Unclosed string

This commit is contained in:
greg 2017-09-07 00:18:36 -07:00
parent ac5bdd7bcb
commit 7fe0a6589e

View File

@ -88,7 +88,6 @@ pub fn tokenize(input: &str) -> Vec<Token> {
c @ '_' | c if c.is_alphabetic() => handle_alphabetic(c, &mut input),
c => handle_operator(c, &mut input),
};
tokens.push(Token { token_type: cur_tok_type, offset: idx });
}
tokens
@ -112,10 +111,10 @@ fn handle_digit(c: char, input: &mut CharIter) -> TokenType {
fn handle_quote(input: &mut CharIter) -> TokenType {
let mut buf = String::new();
while let Some(c) = input.next().map(|(_, c)| { c }) {
if c == '"' {
break;
} else if c == '\\' {
loop {
match input.next().map(|(_, c)| { c }) {
Some('"') => break,
Some('\\') => {
let next = input.peek().map(|&(_, c)| { c });
if next == Some('n') {
input.next();
@ -123,10 +122,13 @@ fn handle_quote(input: &mut CharIter) -> TokenType {
} else if next == Some('"') {
input.next();
buf.push('"');
} else if next == Some('t') {
input.next();
buf.push('\t');
}
//TODO handle more escapes
} else {
buf.push(c);
},
Some(c) => buf.push(c),
None => return TokenType::Error(format!("Unclosed string")),
}
}
TokenType::StrLiteral(Rc::new(buf))