Skip to content
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

Concept of a lexer mode #419

Open
ccleve opened this issue Sep 12, 2024 · 1 comment
Open

Concept of a lexer mode #419

ccleve opened this issue Sep 12, 2024 · 1 comment
Labels
question Further information is requested

Comments

@ccleve
Copy link

ccleve commented Sep 12, 2024

Is it possible for the lexer to run in different modes, where in one mode something might be recognized, and it in another it would not?

For example, when lexing

red AND blue

A lexer running in "query" mode might recognize AND as a operator, and it "text" mode it would treat it as a regular token.

Other lexers that I've used, including JFlex and Antlr, have this feature and it's extremely useful.

@jeertmans
Copy link
Collaborator

Well, yes and not. You cannot change the Lexer at runtime, as it is constructed during compilation (which makes it fast). However, you can still use callbacks, extras, and other techniques to interpret the tokens differently, depending on the context. At runtime, in a callback, you can also use Lexer.morph to change the lexer to produce other tokens.

@jeertmans jeertmans added the question Further information is requested label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants