antlr / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
10.25k stars 3.72k forks source link

[C] Some grammars have parser rules without lexer rules declared #3350

Open kaby76 opened 1 year ago

kaby76 commented 1 year ago

See https://github.com/antlr/antlr4/discussions/4212#discussioncomment-5739418

Some grammars like C.g4 have parser rules that have string literals that don't have a corresponding lexer rule for the string literal. For example, in the C.g4 grammar, we don't have a lexer rule for '__asm'. String literals in a parser rule get unfolded by the Antlr4 tool. If it cannot find a lexer rule for the string literal, Antlr will generate a rule internally.

Parser rule string literals are okay as long as one doesn't need to split the grammar, because once split, the Antlr4 tool will then complain that you don't have a lexer rule for the string literal. It might be best to find all string literals in all grammars-v4, and make sure we declare string literals with explicitly.

KvanTTT commented 1 year ago

I guess it's related to https://github.com/antlr/grammars-v4/issues/2998 Once we fix that, all warnings will be treated as errors including warnings about missing token definitions.