antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

[CSharp] Fix for #3510 -- accept grammars with either "->Channel(HIDDEN)" or "->channel(HIDDEN)" for CSharp

Open kaby76 opened this issue 3 years ago • 0 comments

What does this PR fix?

  • #3510 (CSharp target)

Discussion

The problem here revolves around an undocumented syntax in Antlr lexers. Use of "Channel(HIDDEN)" is accepted (in addition to the documented use of "channel(HIDDEN)") in a lexer grammar, but is outputted to the generated lexer as "_channel = HIDDEN". Unfortunately, this cannot work because the Antlr CSharp runtime sets the accessibility of the various fields ("_channel", "_type", "_mode") to private, and provides instead get and set properties. The generated code already uses the public method PushMode(), and I don't want to change the visibility of the runtime for _channel, this change uses property set instead.

The change is essentially to three lines in the .stg file for CSharp. I've added a test to the CSharp runtime that has a lexer use both "channel(HIDDEN)" and "Channel(HIDDEN)".

Why is this PR important?

In my opinion, this PR is not that important when compared to PRs to fix #3441, #3443, but I would include it in a long list of minor problems. There is no documentation describing "Channel()"; only "channel()" is documented. It occurs in grammars-v4/rego/RegoLexer.g4, which hasn't been targeted for CSharp only until recently.

kaby76 avatar Feb 21 '22 18:02 kaby76