-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Error with customized channel names in ANTLR 4.6 #1555
Comments
Can you upload the full version of your grammars or point a link? |
Token, Channel and Mode types checking is more strict since 4.6 version, see this issue for detail: #1411. Your code-defined channels will not be recognized. You should use ChanLexer.g4: lexer grammar ChanLexer;
channels { CHAN }
WS : ' ' -> channel(CHAN);
Char : .; ChanParser.g4: parser grammar ChanParser;
options { tokenVocab = ChanLexer; }
file : Char* EOF; |
OK, thank you very much! |
📝 If you really must use
|
I've done the @lexer::members approach with the raw numbers as part of fixing older code when upgrading to 4.6. But what I haven't figured out is why custom channels aren't allowed in a combined grammar. Is the issue only in determining which state we're in (and thus that the channel is legal at that point)? |
@blindpirate That could be the case, and if so I'm not sure that aspect was intentional. That said, my overwhelming recommendation in all cases is to not use combined grammars since they prevent using some of the most powerful features (e.g. lexer modes) and make it much easier to make mistakes that will not be reported by the code generator (e.g. referencing an undefined literal in a parser rule). |
@blindpirate it's not possible to use customized channel names in combined grammars in earlier versions of ANTLR too (< 4.6). Check added by yourself issue #965 |
As reported in #965 , the customized channel name aren't recognized with ANTLR4.6.
I'm testing examples in The Definitive ANTLR4 Reference 12.1, Page 205.
In ANTLR 4.5.3 and earlier version, customized channel name can be declared with
And it may result in some warnings.
With 4.6, the code above will cause an error:
However, when I turned to use
channels
block as said in doc, I got errors like:So I broke them into a lexer grammar and imported it in the combined grammar, but the error still occured:
Somebody also met this in #965 . But in 4.6, it means that I cannot use custom channel name at all - both the old
@lexer::members
and the newchannels
will cause errors.What is the right way to define a custom channel in ANTLR 4.6+ ?
The text was updated successfully, but these errors were encountered: