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 => {
|
TokenKind::Interpolation => values.extend(eat_interpolation(toks)),
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => match toks.next() {
|
_ => match toks.next() {
|
||||||
Some(tok) => values.push(tok),
|
Some(tok) => values.push(tok),
|
||||||
_ => unsafe { std::hint::unreachable_unchecked() },
|
_ => unsafe { std::hint::unreachable_unchecked() },
|
||||||
@ -628,6 +614,24 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
|||||||
Ok(None)
|
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
|
/// Functions that print to stdout or stderr
|
||||||
impl<'a> StyleSheetParser<'a> {
|
impl<'a> StyleSheetParser<'a> {
|
||||||
fn debug(&self, pos: Pos, message: &str) {
|
fn debug(&self, pos: Pos, message: &str) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user