double-quoted string literals

main
Jordan Orelli 7 months ago
parent 965cb45437
commit 447dd3edc1

@ -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<Glyph>) -> Result<Token, LexError> {
Err(LexError::not_yet(
self.source.next_position,
"interpreted strings not done yet",
))
fn lex_string_literal(&mut self, mut progress: Vec<Glyph>) -> Result<Token, LexError> {
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<Glyph>) -> Result<Token, LexError> {
@ -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")

Loading…
Cancel
Save