lexer: basic support for double-quoted strings

This commit is contained in:
Ryan Chandler 2022-07-22 15:13:32 +01:00
parent 2e298b2cec
commit ab7b067e43
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
2 changed files with 54 additions and 0 deletions

View File

@ -254,6 +254,47 @@ impl Lexer {
TokenKind::ConstantString(buffer)
},
'"' => {
self.col += 1;
let mut buffer = String::new();
let mut escaping = false;
while let Some(n) = it.peek() {
if ! escaping && *n == '"' {
it.next();
break;
}
if *n == '\\' && !escaping {
escaping = true;
it.next();
continue;
}
if escaping && ['\\', '"'].contains(n) {
escaping = false;
buffer.push(*n);
it.next();
continue;
}
if *n == '\n' {
self.line += 1;
self.col = 0;
} else {
self.col += 1;
}
escaping = false;
buffer.push(*n);
it.next();
}
TokenKind::ConstantString(buffer)
},
'$' => {
let mut buffer = String::new();
@ -491,6 +532,17 @@ impl Lexer {
self.col += 1;
TokenKind::LessThanEquals
} else if let Some('<') = it.peek() {
it.next();
if let Some('<') = it.peek() {
// TODO: Handle both heredocs and nowdocs.
it.next();
todo!("heredocs & nowdocs");
} else {
TokenKind::LeftShift
}
} else {
TokenKind::LessThan
}

View File

@ -11,6 +11,7 @@ pub enum TokenKind {
AndEqual,
Array,
ArrayCast,
LeftShift,
As,
Asterisk,
Attribute,
@ -107,6 +108,7 @@ pub enum TokenKind {
Bang,
And,
BitAnd,
DocOpen(String),
}
#[derive(Debug, Clone)]