New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to preserve spans from the lexer into the parser? #125
Comments
Personally, I use a custom Span with two fields. struct Span {
source_span: (usize, usize),
stream_span: (usize, usize),
}
impl chumsky::Span for Span {
// Return stream span here
} Then later, you use |
@CraftSpider I like that the custom |
Yes. I lex with logos, so it just uses its range internally, then when I hit chumsky, I convert to this new differentiated span, and that span gets preserved into future steps. |
If you want more example code, I can grab some snippets from the implementation |
Chumsky supports spans 'natively', so you don't need to mention them in the type of the input token. Although |
I ended up dropping the separate lexer that was generating a |
I'm struggling to access char spans in my parser when using a two-step lexer+parser approach:
My lexer looks like:
and I started working on a parser that looks like:
In nano_rust.rs, the parser only accepts
Token
instead of(Token, Span)
.I'm going to try doing the same and then using the token spans provided by
.map_with_span()
in the parser to look up the span in the original char stream from theVet<(Token, Span)>
produced by the lexer.I was wondering if this is the recommended way of accessing char spans from the parser when using a two-step parsing approach?
The text was updated successfully, but these errors were encountered: