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

Allowing empty string in lexer islands? #83

Open
znakeeye opened this issue Apr 30, 2024 · 5 comments
Open

Allowing empty string in lexer islands? #83

znakeeye opened this issue Apr 30, 2024 · 5 comments

Comments

@znakeeye
Copy link

znakeeye commented Apr 30, 2024

Using Antlr4.Runtime.Standard 4.13.1 and Antlr4BuildTasks 12.8.

Please consider the grammar below. For input [] I expect tokens START VALUE("") END.

lexer grammar TagLexer;

START   : '[' -> pushMode(VALUE_MODE);

mode VALUE_MODE;

VALUE   : ~']'*;           // May be empty, obviously.
END     : ']' -> popMode;

It will produce an ANT01 warning which is then treated as an error:

Warning ANT01 warning(146): non-fragment lexer rule VALUE can match the empty string
Error ANT02 error(10): warning treated as error

My understanding is that this warning should be ignored in this case. Under no circumstances will it cause an infinite loop in the lexer. Please see antlr/antlr4#180.

How can I get my parser to compile?

@kaby76
Copy link
Owner

kaby76 commented Apr 30, 2024

You are right.. The warning should not be treated as an error. I will check what is wrong.

@kaby76
Copy link
Owner

kaby76 commented May 1, 2024

Does your .csproj have a <Error>true</Error> within the <Antlr4> element?

@znakeeye
Copy link
Author

znakeeye commented May 1, 2024

Yes, indeed.

@kaby76
Copy link
Owner

kaby76 commented May 1, 2024

Antlr4BuildTasks is a thin layer on top of the Java Antlr4 Tool. The package creates a process for java -jar antlr-version-complete.jar .... When <Error>true</Error> is set, the Antlr tool is called with the -Werr option, java -jar antlr-version-complete.jar -Werr .... If the call to the Antlr tool is treating the warning as error, the tool will not create any files. The package will then need to catch the error, and reissue the command without -Werr but only if that is the only warning. Seems to be a lot of work to override what the Antlr tool does. I suggest deleting <Error>true</Error> for the lexer grammar.

@znakeeye
Copy link
Author

znakeeye commented May 1, 2024

Thanks for clarification. I'll keep an ey on that <Error> setting 👍

As for empty tokens, I realized that the lexer should never handle those. It's the task for the parser!

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

2 participants