Skip to content

Commit 5679586

Browse files
committed
Fix bareword handling in expression parsing and allow it in subfield position
1 parent 81b3bae commit 5679586

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

esi/src/expression.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ fn parse_expr(cur: &mut Peekable<Iter<Token>>) -> Result<Expr> {
343343
match token {
344344
Token::Integer(i) => Expr::Integer(*i),
345345
Token::String(s) => Expr::String(s.clone()),
346-
Token::Bareword(s) => Expr::String(s.clone()),
347346
Token::Dollar => parse_dollar(cur)?,
348347
unexpected => {
349348
return Err(ExecutionError::ExpressionError(format!(
@@ -408,11 +407,15 @@ fn parse_variable(cur: &mut Peekable<Iter<Token>>) -> Result<Expr> {
408407

409408
match cur.next() {
410409
Some(Token::OpenBracket) => {
411-
// TODO: I think there might be cases of $var{key} where key is a
412-
// bareword. If that's the case, then handle here by checking
413-
// if the next token is a bareword instead of trying to parse
414-
// an expression.
415-
let subfield = parse_expr(cur)?;
410+
// Allow bareword as string in subfield position
411+
let subfield = if let Some(Token::Bareword(s)) = cur.peek() {
412+
cur.next();
413+
Expr::String(s.clone())
414+
} else {
415+
// Parse the subfield expression
416+
parse_expr(cur)?
417+
};
418+
416419
let Some(Token::CloseBracket) = cur.next() else {
417420
return Err(ExecutionError::ExpressionError(format!(
418421
"unexpected token: {:?}",

0 commit comments

Comments
 (0)