Skip to content

Commit

Permalink
refactor(parser): Make parse_variable name available
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 6, 2024
1 parent 0a91e97 commit 5e5925e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/core/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn parse_literal(literal: Pair) -> Value {

/// Parses a `Variable` from a `Pair` with a variable.
/// This `Pair` must be `Rule::Variable`.
fn parse_variable(variable: Pair) -> Variable {
fn parse_variable_pair(variable: Pair) -> Variable {
if variable.as_rule() != Rule::Variable {
panic!("Expected variable.");
}
Expand Down Expand Up @@ -163,7 +163,7 @@ fn parse_value(value: Pair) -> Expression {

match value.as_rule() {
Rule::Literal => Expression::Literal(parse_literal(value)),
Rule::Variable => Expression::Variable(parse_variable(value)),
Rule::Variable => Expression::Variable(parse_variable_pair(value)),
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -971,7 +971,7 @@ impl<'a> TagToken<'a> {
/// Tries to obtain a `Variable` from this token.
pub fn expect_variable(mut self) -> TryMatchToken<'a, Variable> {
match self.unwrap_variable() {
Ok(t) => TryMatchToken::Matches(parse_variable(t)),
Ok(t) => TryMatchToken::Matches(parse_variable_pair(t)),
Err(_) => {
self.expected.push(Rule::Variable);
TryMatchToken::Fails(self)
Expand Down Expand Up @@ -1121,7 +1121,7 @@ mod test {
}

#[test]
fn test_parse_variable() {
fn test_parse_variable_pair() {
let variable = LiquidParser::parse(Rule::Variable, "foo[0].bar.baz[foo.bar]")
.unwrap()
.next()
Expand All @@ -1137,7 +1137,7 @@ mod test {
let mut expected = Variable::with_literal("foo");
expected.extend(indexes);

assert_eq!(parse_variable(variable), expected);
assert_eq!(parse_variable_pair(variable), expected);
}

#[test]
Expand Down

0 comments on commit 5e5925e

Please sign in to comment.