Pratt parsing with extra metadata #617
Answered
by
zesterer
catapillie
asked this question in
Q&A
-
Hello!
There doesn't seem to be a way to directly do this using |
Beta Was this translation helpful? Give feedback.
Answered by
zesterer
Apr 1, 2024
Replies: 1 comment 1 reply
-
It's easier than you might think! You can simply add the span to the output type of the operator / atom like so: atom.map_with(|x, e| (x, e.span())).pratt((
infix(left(1), my_op.map_with(|x, e| (x, e.span())), |l, op, r, e| {
// Note that in here, `l.1`, `op.1`, and `r.1` all give the span of their respective elements
(Expr::MyOp(l, op, r), e.span())
}),
)) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
catapillie
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's easier than you might think! You can simply add the span to the output type of the operator / atom like so: