Refactor interpolation eating
@@ -604,28 +604,32 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
}
}
}
- TokenKind::Interpolation => {
+ TokenKind::Interpolation => values.extend(eat_interpolation(toks)),
+ _ => match toks.next() {
+ Some(tok) => values.push(tok),
+ _ => unsafe { std::hint::unreachable_unchecked() },
+ },
+ };
+ }
+ 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,
- _ => {},
+ _ => {}
}
- values.push(tok);
+ vals.push(tok);
if n == 0 {
break;
}
}
- }
- _ => match toks.next() {
- Some(tok) => values.push(tok),
- _ => unsafe { std::hint::unreachable_unchecked() },
- },
- };
- }
- Ok(None)
+ vals
}
/// Functions that print to stdout or stderr
