Advice on how to do lookahead using the package lexer #780
Unanswered
vinipsmaker
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
At the Racket level, I have sometimes use |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm writing a series of Pratt parsing blog posts, and I'm using Rhombus for all code samples. Later down the series I want to teach how to do some advanced stuff such modal lexing + two-phase parsing so one phase uses a cheap greedy lexer definition (modal lexing) to skip over large chunks of code structure just to collect names on global scope (for lexical scoping) and the second phase actually parses the definitions.
I've implemented all this in C++ and I know how to do this using Pratt. I'm not asking for advice on Pratt.
Also I plan on writing a whole series on Pratt parsing. The point of some articles is not just solving the immediate problem, but teaching a tool that you can use later. I want to use lookahead in this example so the reader learns the lookahead trick (other articles in the series are going to use different tricks).
So what I'd like help with is advice on how to use lookahead in the package for the Rhombus lexer. The lexer relies on
Port.Inputfor buffered read (and optional line/column count) which already works great for modal lexing (I can interleave different lexers as I read tokens), but I don't see how I can create a copy of aPort.Input.Stringin its current state so I can lex the copy to lookahead w/o modifying the original. Is there a method inPort.Input.Stringthat I'm missing? Is there a different approach I should be pursuing for lookahead?Beta Was this translation helpful? Give feedback.
All reactions