antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.11k stars 3.28k forks source link

imported lexer grammar may not start with mode #2830

Open kortemik opened 4 years ago

kortemik commented 4 years ago
lexer grammar SomeSubLexer;
mode SUB_MODE;

is not permitted, while

lexer grammar SomeSubLexer;
SOME_VERY_USELESS_TOKEN: 'you_might_miss_this_token';
mode SUB_MODE;

is.

KvanTTT commented 3 years ago

Where is importing? Could you please provide a full example?

kortemik commented 3 years ago

working https://github.com/kortemik/antlr4-stuff/commit/92658f55bf525d2287ec0a83f9c1179a334958de breaks https://github.com/kortemik/antlr4-stuff/commit/a52563514f610269ce9b685cf4023db390546334

KvanTTT commented 3 years ago

Got it. I think it's expected behavior because every mode should have at least one rule even if the grammar is being imported.

kortemik commented 3 years ago

Thank you. I think it is quite hard to work with as the rules of the mode come afterwards not before the mode statement. even if we have something in the default mode it still refuses to import. it works the same even though there are already tokens in the default mode of the previous imports.