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

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

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

kaby76
Copy link
Contributor

@kaby76 kaby76 commented Feb 21, 2022

What does this PR fix?

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 kaby76 changed the title Fix for #3510 [CSharp] Fix for #3510 Feb 22, 2022
@kaby76 kaby76 changed the title [CSharp] Fix for #3510 [CSharp] Fix for #3510 -- accept grammars with either "->Channel(HIDDEN)" or "->channel(HIDDEN)" for CSharp Feb 22, 2022
INT : [0-9]+;
AAA : [a-z]+ -> channel(HIDDEN); // Note--lowercase "channel"
BBB : [A-Z]+ -> Channel(HIDDEN); // Note--uppercase "Channel"
WS : [ \t\r\n] -> skip;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be written using a descriptor (https://github.com/antlr/antlr4/tree/dev/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/LexerExec) to cover all runtimes but not C# only.

Also, please add tests on other commands if you can (see lexer-commands description):

  • skip
  • more
  • popMode
  • pushMode
  • type
  • channel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, was wondering what those were for.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, we have similar tests but in tool-testsuite: https://github.com/antlr/antlr4/blob/dev/tool-testsuite/test/org/antlr/v4/test/tool/TestLexerActions.java But actually they should be moved to runtime-testsuite.

@@ -0,0 +1,18 @@
using Antlr4.Runtime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks redundant (all files from runtime/CSharp/tests/issue-3510) since everything can be checked using a descriptor-based test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Will move this over to a descriptor.

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

Successfully merging this pull request may close these issues.

2 participants