-
I'm trying to update my parser to 1.0.0-alpha.7 from 1.0.0-alpha.6. Something changed with the pratt parsers and I can't figure out what the library wants me to change. Here is my (rather large) pratt parser. let atom = choice((
range.clone(),
parsed_function.clone(),
list.clone(),
basic_value.clone(),
map.clone(),
structure_instance.clone(),
identifier_expression.clone(),
expression.clone().delimited_by(
just(Token::Control(Control::ParenOpen)),
just(Token::Control(Control::ParenClose)),
),
));
let logic_math_indexes_as_and_function_calls = atom.pratt((
prefix(
2,
just(Token::Operator(Operator::Not)),
|_, expression, span| {
ValueExpression::Logic(Box::new(Logic::Not(expression)).with_position(span))
},
),
postfix(
3,
expression.clone().delimited_by(
just(Token::Control(Control::SquareOpen)),
just(Token::Control(Control::SquareClose)),
),
|left, right, span| {
ValueExpression::ListIndex(
Box::new(ListIndex::new(left, right)).with_position(span),
)
},
),
infix(
left(4),
just(Token::Control(Control::Dot)),
|left: ValueExpression, _: Token, right: ValueExpression, span| {
ValueExpression::MapIndex(
Box::new(MapIndex::new(left, right)).with_position(span),
)
},
),
postfix(
3,
turbofish.clone().or_not().then(
expression
.clone()
.separated_by(just(Token::Control(Control::Comma)))
.collect()
.delimited_by(
just(Token::Control(Control::ParenOpen)),
just(Token::Control(Control::ParenClose)),
),
),
|function_expression,
(type_arguments, arguments): (
Option<Vec<WithPosition<Type>>>,
Vec<ValueExpression>,
),
span| {
ValueExpression::FunctionCall(
FunctionCall::new(
function_expression,
type_arguments.unwrap_or_else(|| Vec::with_capacity(0)),
arguments,
)
.with_position(span),
)
},
),
infix(
left(1),
just(Token::Operator(Operator::Equal)),
|left, _, right, span| {
ValueExpression::Logic(
Box::new(Logic::Equal(left, right)).with_position(span),
)
},
),
infix(
left(1),
just(Token::Operator(Operator::NotEqual)),
|left, _, right, span| {
ValueExpression::Logic(
Box::new(Logic::NotEqual(left, right)).with_position(span),
)
},
),
infix(
left(1),
just(Token::Operator(Operator::Greater)),
|left, _, right, span| {
ValueExpression::Logic(
Box::new(Logic::Greater(left, right)).with_position(span),
)
},
),
infix(
left(1),
just(Token::Operator(Operator::Less)),
|left, _, right, span| {
ValueExpression::Logic(
Box::new(Logic::Less(left, right)).with_position(span),
)
},
),
infix(
left(1),
just(Token::Operator(Operator::GreaterOrEqual)),
|left, _, right, span| {
ValueExpression::Logic(
Box::new(Logic::GreaterOrEqual(left, right)).with_position(span),
)
},
),
infix(
left(1),
just(Token::Operator(Operator::LessOrEqual)),
|left, _, right, span| {
ValueExpression::Logic(
Box::new(Logic::LessOrEqual(left, right)).with_position(span),
)
},
),
infix(
left(1),
just(Token::Operator(Operator::And)),
|left, _, right, span| {
ValueExpression::Logic(
Box::new(Logic::And(left, right)).with_position(span),
)
},
),
infix(
left(1),
just(Token::Operator(Operator::Or)),
|left, _, right, span| {
ValueExpression::Logic(Box::new(Logic::Or(left, right)).with_position(span))
},
),
infix(
left(1),
just(Token::Operator(Operator::Add)),
|left, _, right, span| {
ValueExpression::Math(Box::new(Math::Add(left, right)).with_position(span))
},
),
infix(
left(1),
just(Token::Operator(Operator::Subtract)),
|left, _, right, span| {
ValueExpression::Math(
Box::new(Math::Subtract(left, right)).with_position(span),
)
},
),
infix(
left(2),
just(Token::Operator(Operator::Multiply)),
|left, _, right, span| {
ValueExpression::Math(
Box::new(Math::Multiply(left, right)).with_position(span),
)
},
),
infix(
left(2),
just(Token::Operator(Operator::Divide)),
|left, _, right, span| {
ValueExpression::Math(
Box::new(Math::Divide(left, right)).with_position(span),
)
},
),
infix(
left(1),
just(Token::Operator(Operator::Modulo)),
|left, _, right, span| {
ValueExpression::Math(
Box::new(Math::Modulo(left, right)).with_position(span),
)
},
),
postfix(
2,
just(Token::Keyword(Keyword::As)).ignore_then(r#type.clone()),
|expression, r#type, span| {
ValueExpression::As(
Box::new(As::new(expression, r#type)).with_position(span),
)
},
),
)); |
Beta Was this translation helpful? Give feedback.
Answered by
zesterer
Jun 27, 2024
Replies: 1 comment
-
The pratt parsers were changes such that the extra parameter in the functions is a |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
solaeus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The pratt parsers were changes such that the extra parameter in the functions is a
MapExtra
rather than a span.MapExtra
is the more general big brother and gives you access to the span, the state, context, and input subslices.