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

How can we write multiple parsers to use the same lexer? #4580

Open
rojares opened this issue Apr 8, 2024 · 1 comment
Open

How can we write multiple parsers to use the same lexer? #4580

rojares opened this issue Apr 8, 2024 · 1 comment

Comments

@rojares
Copy link

rojares commented Apr 8, 2024

Looking at class org.antlr.v4.gui.TestRig method process() starting at line 123 I noticed that Lexer classname has to be the same as parser classname.
line 125: String lexerName = grammarName+"Lexer";
How is it possible to use multiple different parsers to use the same lexer?

@rojares
Copy link
Author

rojares commented Apr 8, 2024

I just realized that

  • When I generate a lexer from a lexer grammar then org.antlr.v4.Tool generates a lexer with classname grammarName.
  • When I generate a parser from a parser grammar then org.antlr.v4.Tool generates a parser with classname grammarName.
  • When I generate a parser from a generic grammar (both lexer and parser) then org.antlr.v4.Tool generates a lexer with classname grammarName+"Lexer" and parser with grammarName+"Lexer".
    So there is a tight coupling with the lexer classname and parser classname.
    This is problematic when trying to generate one lexer for multiple grammars.
    I also feel that this coupling is weakly documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant