Fixed string parsing

This commit is contained in:
greg 2017-12-03 17:47:17 -08:00
parent 9c3e223e51
commit 728393671f

View File

@ -107,20 +107,18 @@ fn tokenize(input: &mut Peekable<Chars>) -> Vec<Token> {
Some('\'') => tokens.push(Quote), Some('\'') => tokens.push(Quote),
Some(c) if c.is_whitespace() => continue, Some(c) if c.is_whitespace() => continue,
Some('"') => { Some('"') => {
let string: String = input.scan(false, |seen_escape, cur_char| { let string: String = input.scan(false, |escape, cur_char| {
let ret = if cur_char == '"' && !*seen_escape { let seen_escape = *escape;
None *escape = cur_char == '\\' && !seen_escape;
} else {
Some(cur_char)
};
if cur_char == '\\' { if cur_char == '"' && !seen_escape {
*seen_escape = true; None
} else if cur_char == '\\' && !seen_escape {
Some(None)
} else { } else {
*seen_escape = false; Some(Some(cur_char))
} }
ret }).filter_map(|x| x).collect();
}).collect();
tokens.push(StringLiteral(string)); tokens.push(StringLiteral(string));
} }
Some(c) => { Some(c) => {