cl-lexer: Make strings curly-brace-aware, for future format string work
This commit is contained in:
parent
8dd2920fca
commit
1f9d32f972
@ -375,12 +375,21 @@ impl Lexer<'_> {
|
|||||||
/// Produces a [Literal](Kind::Literal) with a pre-escaped [String]
|
/// Produces a [Literal](Kind::Literal) with a pre-escaped [String]
|
||||||
pub fn string(&mut self) -> Result<Token, Error> {
|
pub fn string(&mut self) -> Result<Token, Error> {
|
||||||
let mut lexeme = String::new();
|
let mut lexeme = String::new();
|
||||||
|
let mut depth = 0;
|
||||||
self.consume();
|
self.consume();
|
||||||
loop {
|
loop {
|
||||||
lexeme.push(match self.take() {
|
lexeme.push(match self.take() {
|
||||||
None => Err(self.error(Reason::UnmatchedDelimiters('"')))?,
|
None => Err(self.error(Reason::UnmatchedDelimiters('"')))?,
|
||||||
Some('\\') => self.unescape()?,
|
Some('\\') => self.unescape()?,
|
||||||
Some('"') => break,
|
Some('"') if depth == 0 => break,
|
||||||
|
Some(c @ '{') => {
|
||||||
|
depth += 1;
|
||||||
|
c
|
||||||
|
}
|
||||||
|
Some(c @ '}') => {
|
||||||
|
depth -= 1;
|
||||||
|
c
|
||||||
|
}
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user