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

Separate lexer/parser grammars #5

Closed
amal-khailtash opened this issue Dec 17, 2020 · 5 comments
Closed

Separate lexer/parser grammars #5

amal-khailtash opened this issue Dec 17, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@amal-khailtash
Copy link

This is great tool! Quite helpful creating a faster parser with Python binding.

It seems though as this does not support separate lexer/parser grammars. When separate lexer/parser grammar files are used I see the following problem.

I have a grammar for a parser named A with the following file/grammar names:

ALexer.g4
AParser.g4

ANTLR4 Python3 target generates these python files:

ALexer.interp
ALexer.py
ALexer.tokens
AParser.interp
AParser.py
AParser.tokens

ANTLR4 Cpp target generates these cpp files:

ALexer.cpp
ALexer.h
ALexer.interp
ALexer.tokens
AParserBaseVisitor.cpp
AParserBaseVisitor.h
AParser.cpp
AParser.h
AParser.interp
AParser.tokens
AParserVisitor.cpp
AParserVisitor.h

Running speedy_antlr_tool.generate and passing AParser.py as argument generates:

sa_a.py

sa_A_cpp_parser.cpp
sa_A_translator.cpp
sa_A_translator.h

speedy_antlr.cpp
speedy_antlr.h
speedy_antlr.o

It seems the templates require a visitor header file with the name ABaseVisitor.h, but the CPP source includes a header named: AParserBaseVisitor.cpp:.

In file included from sa_a_cpp_parser.cpp:16:
sa_a_translator.h:8:10: fatal error: ABaseVisitor.h: No such file or directory
 #include "ABaseVisitor.h"
          ^~~~~~~~~~~~~~~~
@amal-khailtash
Copy link
Author

It seems this had been mentioned before in Issue #2, but I don't see a resolution, but somehow the error went away. Maybe some manual renaming of generated filenames were done?

@amykyta3
Copy link
Owner

Good point.
This project was motivated by the systemrdl-compiler project, where I combined the lexer & parser in a single grammar file. It shouldn't be too difficult to extend support for this to support grammars that are split across files.

@amal-khailtash
Copy link
Author

On this same note. It would be great if you could support lexer only grammars as well. I have one that I just use ANTLR4 lexer only grammar.

@amykyta3
Copy link
Owner

Just published v1.1.0.
This adds support for grammars that are split into separate lexer/parser files. See example: https://github.com/amykyta3/speedy-antlr-example/blob/master/src/spam/parser/generate_parsers_split.sh

Regarding the lexer-only request, I have opened a separate issue here: #6

@amykyta3 amykyta3 added the enhancement New feature or request label Dec 18, 2020
@amal-khailtash
Copy link
Author

This is great. I confirm this fixes the separate grammars. Thanks.

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

No branches or pull requests

2 participants