From 728393671f4e9c54195947ab8f751e9114f87825 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 3 Dec 2017 17:47:17 -0800 Subject: [PATCH] Fixed string parsing --- src/rukka_lang/mod.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/rukka_lang/mod.rs b/src/rukka_lang/mod.rs index 3d3ce8b..4fcf87b 100644 --- a/src/rukka_lang/mod.rs +++ b/src/rukka_lang/mod.rs @@ -107,20 +107,18 @@ fn tokenize(input: &mut Peekable) -> Vec { Some('\'') => tokens.push(Quote), Some(c) if c.is_whitespace() => continue, Some('"') => { - let string: String = input.scan(false, |seen_escape, cur_char| { - let ret = if cur_char == '"' && !*seen_escape { - None - } else { - Some(cur_char) - }; + let string: String = input.scan(false, |escape, cur_char| { + let seen_escape = *escape; + *escape = cur_char == '\\' && !seen_escape; - if cur_char == '\\' { - *seen_escape = true; + if cur_char == '"' && !seen_escape { + None + } else if cur_char == '\\' && !seen_escape { + Some(None) } else { - *seen_escape = false; + Some(Some(cur_char)) } - ret - }).collect(); + }).filter_map(|x| x).collect(); tokens.push(StringLiteral(string)); } Some(c) => {