cl-lexer: Make strings curly-brace-aware, for future format string work

This commit is contained in:
John 2025-09-15 00:21:14 -04:00
parent 8dd2920fca
commit 1f9d32f972

View File

@ -375,12 +375,21 @@ impl Lexer<'_> {
/// Produces a [Literal](Kind::Literal) with a pre-escaped [String]
pub fn string(&mut self) -> Result<Token, Error> {
let mut lexeme = String::new();
let mut depth = 0;
self.consume();
loop {
lexeme.push(match self.take() {
None => Err(self.error(Reason::UnmatchedDelimiters('"')))?,
Some('\\') => self.unescape()?,
Some('"') => break,
Some('"') if depth == 0 => break,
Some(c @ '{') => {
depth += 1;
c
}
Some(c @ '}') => {
depth -= 1;
c
}
Some(c) => c,
})
}