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

[Go target] cannot create a custom token in a base class lexer #4342

Open
kaby76 opened this issue Jul 2, 2023 · 1 comment
Open

[Go target] cannot create a custom token in a base class lexer #4342

kaby76 opened this issue Jul 2, 2023 · 1 comment

Comments

@kaby76
Copy link
Contributor

kaby76 commented Jul 2, 2023

I am trying to port python/python3 to the Go target. Specifically, it involves creating some custom tokens for indentation. Unfortunately, given the current API, it's impossible to do so. Therefore, this is a blocking bug.

There is no way to create and have called a Python3LexerBase.EmitToken() method for custom token creation. This method should be defined for the Go target (it's defined in the other targets, sometimes as Emit(token)). The call to EmitToken(token) is wrong too. It should be b.Virt.EmitToken(t). The Lexer interface requires a definition for EmitToken(token).

Rant: I'll say it again, nesting structs like this does not make an OO data structure. It's like this person didn't ever write a compiler that implements an OO language. We had to do this kind of stuff for years with C, because C doesn't support OO directly.

(In Python3Lexer3.g4)
options {superClass=Python3LexerBase;}


(In the generated Python3Lexer.go)
type Python3Lexer struct {
	Python3LexerBase
	channelNames []string
	modeNames    []string
	// TODO: EOF string
}

It should be:

type Python3Lexer struct {
	mybase *Python3LexerBase
	channelNames []string
	modeNames    []string
	// TODO: EOF string
}
@kaby76 kaby76 changed the title [Go target] API is missing EmitToken() [Go target] API is missing EmitToken(token) Jul 2, 2023
@kaby76 kaby76 changed the title [Go target] API is missing EmitToken(token) [Go target] virtual function EmitToken(token) is not called correctly Jul 2, 2023
@kaby76 kaby76 changed the title [Go target] virtual function EmitToken(token) is not called correctly [Go target] virtual function EmitToken(token) is not called Jul 2, 2023
@kaby76
Copy link
Contributor Author

kaby76 commented Jul 2, 2023

The fix is slightly more than the one line changed (PR to follow). But, this code must be updated because the port to Go for python/python3 requires full control of Emit()/EmitToken().

kaby76 added a commit to kaby76/antlr4 that referenced this issue Jul 2, 2023
…. Required for porting https://github.com/antlr/grammars-v4/tree/master/python/python3 to the Go target. This change just mirrors the APIs for the other targets, like Java, CSharp, and JavaScript/TypeScript.

Signed-off-by: Ken Domino <kenneth.domino@domemtech.com>
@kaby76 kaby76 changed the title [Go target] virtual function EmitToken(token) is not called [Go target] cannot create a custom token in a base class lexer Jul 3, 2023
teverett pushed a commit to antlr/grammars-v4 that referenced this issue Jul 8, 2023
* Fixes for #3539

Typescript cannot work because the declaration of the constructor for CommonToken() is wrong.

* Fix python/python3/TypeScript

* Remove grammars that only add to confusion.

* Update Dart port, but this cannot work because Antlr 4.13.0 Dart runtime missing types.

* Add Dart port for python3 grammar.

This base class for Dart works, but requires changes to Antlr. antlr/antlr4#4321

* Updates, but incomplete, for Cpp.

* Additional changes.

* Updates to get Cpp target to link.

* Changes for working Cpp target.

* Add in Cpp to workflow.

* Updates.

* Adjust to for rebuild.

* Remove bothersome tabs from source code.

* Rename tests into "small" and "large" tests to reflect that "slow parsers work on the small test suite".

* Fix names of test directories in desc.xml.

* Update for Go target. Remove python3-cpp.

* Getting Go target compiling--does not work yet.

* Fixes for Go target of python3 grammar.

This port works but only if the Go runtime is fixed, and "Virt" is assigned in the driver. See antlr/antlr4#4343 antlr/antlr4#4342

* Fix desc.xml
rvrooman-codelogic pushed a commit to CodeLogicIncEngineering/grammars-v4-public-fork that referenced this issue Jul 27, 2023
* Fixes for antlr#3539

Typescript cannot work because the declaration of the constructor for CommonToken() is wrong.

* Fix python/python3/TypeScript

* Remove grammars that only add to confusion.

* Update Dart port, but this cannot work because Antlr 4.13.0 Dart runtime missing types.

* Add Dart port for python3 grammar.

This base class for Dart works, but requires changes to Antlr. antlr/antlr4#4321

* Updates, but incomplete, for Cpp.

* Additional changes.

* Updates to get Cpp target to link.

* Changes for working Cpp target.

* Add in Cpp to workflow.

* Updates.

* Adjust to for rebuild.

* Remove bothersome tabs from source code.

* Rename tests into "small" and "large" tests to reflect that "slow parsers work on the small test suite".

* Fix names of test directories in desc.xml.

* Update for Go target. Remove python3-cpp.

* Getting Go target compiling--does not work yet.

* Fixes for Go target of python3 grammar.

This port works but only if the Go runtime is fixed, and "Virt" is assigned in the driver. See antlr/antlr4#4343 antlr/antlr4#4342

* Fix desc.xml
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

No branches or pull requests

1 participant