From 7fe0a6589e0604994e8979a133ba4e2c4b816526 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 7 Sep 2017 00:18:36 -0700 Subject: [PATCH] Unclosed string --- src/schala_lang/parsing.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 118cfff..6241841 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -88,7 +88,6 @@ pub fn tokenize(input: &str) -> Vec { 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,21 +111,24 @@ 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 == '\\' { - let next = input.peek().map(|&(_, c)| { c }); - if next == Some('n') { - input.next(); - buf.push('\n') - } else if next == Some('"') { - input.next(); - buf.push('"'); - } - //TODO handle more escapes - } else { - buf.push(c); + loop { + match input.next().map(|(_, c)| { c }) { + Some('"') => break, + Some('\\') => { + let next = input.peek().map(|&(_, c)| { c }); + if next == Some('n') { + input.next(); + buf.push('\n') + } else if next == Some('"') { + input.next(); + buf.push('"'); + } else if next == Some('t') { + input.next(); + buf.push('\t'); + } + }, + Some(c) => buf.push(c), + None => return TokenType::Error(format!("Unclosed string")), } } TokenType::StrLiteral(Rc::new(buf))