logos icon indicating copy to clipboard operation
logos copied to clipboard

Switching lexers

Open ronniec95 opened this issue 6 years ago • 1 comments

Is there a way to switch lexers? Standard case of lexing a buffer using a primary lexer and then a separate function to parse quoted strings, then switch back?

Is there an easy way to get the current position of the lexer and move it along while I take over?

ronniec95 avatar Nov 28 '18 12:11 ronniec95

Maybe. There is no way to do context switching on the Lexer atm, but you can do a lot with function callbacks. Have a look at this piece of code from Lunarity, it handleds the block comments (/* ... */) by exposing the internals of the Lexer and basically doing the work manually.

On a sidenote, quoted strings you can already do with regex. If you want the lexer to produce an unescaped String out of the literal, you can add a #[callback] there that reads through it and stores the result on some fields on Extras.

maciejhirsz avatar Nov 28 '18 15:11 maciejhirsz

Closing this a too old, feel free to re-open if needed.

jeertmans avatar Feb 07 '24 11:02 jeertmans