From 447dd3edc1355f3875af488ba9ded2cce9bc67b4 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 18 Feb 2024 12:41:33 -0600 Subject: [PATCH] double-quoted string literals --- src/lex.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/lex.rs b/src/lex.rs index 45ef286..654fe97 100644 --- a/src/lex.rs +++ b/src/lex.rs @@ -129,7 +129,7 @@ impl<'text> Tokenizer<'text> { _ if next.is_glob() => Some(self.lex_glob(vec![next])), '@' => Some(self.lex_var(vec![next])), '\'' => Some(self.lex_raw_string(vec![next])), - '"' => Some(self.lex_interp_string(vec![next])), + '"' => Some(self.lex_string_literal(vec![])), ';' => Some(Ok(Token::Semi(next))), _ => Some(Err(LexError::UnexpectedCharacter(next))), } @@ -188,11 +188,24 @@ impl<'text> Tokenizer<'text> { )) } - fn lex_interp_string(&mut self, _progress: Vec) -> Result { - Err(LexError::not_yet( - self.source.next_position, - "interpreted strings not done yet", - )) + fn lex_string_literal(&mut self, mut progress: Vec) -> Result { + while let Some(next) = self.source.peek() { + match next.glyph { + _ if next.glyph.is_whitespace() => progress.push(self.source.pop()?), + _ if next.is_word() => progress.push(self.source.pop()?), + _ if next.is_glob() => progress.push(self.source.pop()?), + '"' => { + self.source.pop()?; + break; + } + _ => todo!(), + } + } + if progress.is_empty() { + Err(LexError::UnexpectedEOF(self.source.next_position)) + } else { + Ok(Token::Word(progress.into())) + } } fn lex_var(&mut self, _progress: Vec) -> Result { @@ -331,8 +344,6 @@ mod tests { // Single-quoted strings arne't done yet strings: r"echo 'one' two"; - // Single-quoted strings arne't done yet - double_quoted_strings: r#"echo "one" two"#; } accept! { @@ -342,6 +353,11 @@ mod tests { identifier_2 " a" [ word("a") ] identifier_3 "a " [ word("a") ] identifier_4 " a " [ word("a") ] + double_quoted_strings r#"echo "one" two"# [ + word("echo") + word("one") + word("two") + ] file_name "poop.exe" [ word("poop.exe") ] multi_idents "one two three four " [ word("one")