Fixed string parsing
This commit is contained in:
parent
e9429ed62a
commit
766209e5b2
@ -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) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user