[Go] Fix for #3441 and #3443 -- expose Reset() and String() methods. #3548
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR fix?
Discussion
This is a fix for the missing API method String() in the Token, and Reset() in the Lexer.
Go requires any exported data or functions to be capitalized. These functions are required for this code to print out the token stream:
IToken.ToString() in C# and Token.toString() in Java are available because whatever implementation is used, it is derived from
object. Thus, in C#, you can dot.ToString()or Java,t.toString(). Yet,t.String()in Go causes a compilation error.Reset() in C# and reset() in Java are explicitly listed
publicin the interface. Thus, in C#, you can dolexer.Reset();, and Java,lexer.reset();. Yet,lexer.Reset()orlexer.reset()in Go results in a compilation error.The change is renames two methods. I've included a test in the runtime for the two methods.
Why is this PR important?
grammars-v4 CI tests most of the Antlr targets on a per-commit basis. The CI testing has pointed to many important bugs in Antlr. When a difference in parsing is detected, we need ways to easily compare the computations of the target with other targets. A print out of the tokens during the parse is absolutely essential in discovering why a parser target is not working.