Refactor interpolation eating
This commit is contained in:
parent
efe056d3c7
commit
21515214cb
34
src/lib.rs
34
src/lib.rs
@ -604,21 +604,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
||||
}
|
||||
}
|
||||
}
|
||||
TokenKind::Interpolation => {
|
||||
let mut n = 0;
|
||||
while let Some(tok) = toks.next() {
|
||||
match tok.kind {
|
||||
TokenKind::Symbol(Symbol::OpenCurlyBrace) => n += 1,
|
||||
TokenKind::Symbol(Symbol::CloseCurlyBrace) => n -= 1,
|
||||
TokenKind::Interpolation => n += 1,
|
||||
_ => {},
|
||||
}
|
||||
values.push(tok);
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
TokenKind::Interpolation => values.extend(eat_interpolation(toks)),
|
||||
_ => match toks.next() {
|
||||
Some(tok) => values.push(tok),
|
||||
_ => unsafe { std::hint::unreachable_unchecked() },
|
||||
@ -628,6 +614,24 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn eat_interpolation<I: Iterator<Item = Token>>(toks: &mut Peekable<I>) -> Vec<Token> {
|
||||
let mut vals = Vec::new();
|
||||
let mut n = 0;
|
||||
while let Some(tok) = toks.next() {
|
||||
match tok.kind {
|
||||
TokenKind::Symbol(Symbol::OpenCurlyBrace) => n += 1,
|
||||
TokenKind::Symbol(Symbol::CloseCurlyBrace) => n -= 1,
|
||||
TokenKind::Interpolation => n += 1,
|
||||
_ => {}
|
||||
}
|
||||
vals.push(tok);
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
vals
|
||||
}
|
||||
|
||||
/// Functions that print to stdout or stderr
|
||||
impl<'a> StyleSheetParser<'a> {
|
||||
fn debug(&self, pos: Pos, message: &str) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user