Pratt parsing with extra metadata #617
-
Hello!
There doesn't seem to be a way to directly do this using |
Beta Was this translation helpful? Give feedback.
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.
It's easier than you might think! You can simply add the span to the output type of the operator / atom like so: