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

Please add support for Typescript 4.4.x #528

Open
martinmolema opened this issue Apr 27, 2022 · 11 comments
Open

Please add support for Typescript 4.4.x #528

martinmolema opened this issue Apr 27, 2022 · 11 comments

Comments

@martinmolema
Copy link

martinmolema commented Apr 27, 2022

I really am benefiting from your great work. However, now that I am migrating to Angular 13 the language used is TypeScript version 4.4.4. When running the your antlr4ts tool to generate the files and visitors, the //@OverRide is not enough anymore and generates error TS4114. For instance: This member must have an 'override' modifier because it overrides a member in the base class 'ParserRuleContext'.

In the mean time I am looking at how to turn off this error in my project, but really: these are useful errors ...

Edit: cloned the repo and found the .stg file (tool/resources/org/antlr/v4/tool/templates/codegen/TypeScript/TypeScript.stg). I think all that needs to be done is improve this file.

Edit: managed to edit the file (see attachment) and recompile the whole thing (./tool folder using npm -i). So for now I am out of trouble. Maybe for future searchers this might help.

Thank you
TypeScript.stg.txt
!

@martinmolema
Copy link
Author

Managed to recompile the .jar file for the generation tool (in folder 'tool'). Then put the file antlr4-typescript-4.9.0-SNAPSHOT-complete.jar in the Angular project folder for antlr4ts-cli (node_modules/antlr4ts-cli/target) and ran the regular antlr4ts script to generate new files.

@IT-CASADO
Copy link

I'm having the same trouble and your workaround is unfortunately only a workaround.

This issue/ticket needs to be reopened to solve this problem here in this repository.

@martinmolema
Copy link
Author

Another solution would be to just unzip the .jar-file ntlr4-typescript-4.9.0-SNAPSHOT-complete.jar (after all it is just a zip-file) and replace the given attachment (see my initial contribution) and re-zip the whole thing and rename it to .jar again.
The .jar-file can me found in node_modules/antlr4ts-cli/target.

@martinmolema martinmolema reopened this Nov 5, 2022
@nidomiro
Copy link

nidomiro commented Dec 3, 2022

Here is an example on how to automate this: nidomiro/relation-tuple-parser@8209a1b

@chengchengpei
Copy link

are your problems resolved?
did you compile using ts 4.4.0+?
@martinmolema @nidomiro

@nidomiro
Copy link

@chengchengpei I'm using ts 4.8.2 at the commit posted above. It compiles, but only with the patches.

@martinmolema
Copy link
Author

@chengchengpei thank you for your help. However, I have no idea how to apply such a patch... there's a first time for everything. Could you give me pointers here?

@chengchengpei
Copy link

I got some errors when using antlr4ts in my project. Here is the post: https://stackoverflow.com/questions/74870072/typeerror-class-extends-value-undefined-is-not-a-constructor-or-null-when-using

I need help. Any comments welcomed. thanks :)

@martinmolema
Copy link
Author

I upgraded to Angular 16 and got some more errors. Noticed that a few more override statements had to be inserted.
TypeScript.txt
Please rename this attachment to TypeScript.stg and put it in the right place.

Also wrote a small shell-script to help repackaging without recompiling the whole stuff. Make sure to unpack the original .jar-file somewhere. Then put the script and the attachment (TypeScript.stg) in the same folder. So you get the following folder structure:

ProjectFolder
|
|-----antlr4-typescript-4.9.0-SNAPSHOT-complete/
|-----repackage.sh
|-----TypeScript.stg

# This will create a new JAR-file that can be used to create new G4-dependant files using the antlr4ts-cli
# - Edit the file ./TypeScript.stg (in this folder)
# - save the file
# - run this script
# The script will copy the .stg-file to the right folder in the folder structure that originated from the original
# JAR-file (antlr4-typescript-4.9.0-SNAPSHOT-complete.jar) that was unpacked here.
# then a new JAR-file is created and put in the right folder: the node_modules folder that was created when installing
# the antlr4ts-cli (https://github.com/tunnelvisionlabs/antlr4ts/tree/master) :
#   node_modules/antlr4ts-cli/target/antlr4-typescript-4.9.0-SNAPSHOT-complete.jar

PROJECT_ROOT="/mnt/ssd/Develop/crisisgame/scenariomanager-v16"
ANTLR4TS_FOLDER=${PROJECT_ROOT}/__Resources/Antlr4ts-cli
JAR_FILE_UNPACKED_FOLDER=${ANTLR4TS_FOLDER}/antlr4-typescript-4.9.0-SNAPSHOT-complete
TEMPLATE_FILENAME_DESTINATION_JAR_FILE=${JAR_FILE_UNPACKED_FOLDER}/org/antlr/v4/tool/templates/codegen/TypeScript

cd $ANTLR4TS_FOLDER
cp TypeScript.stg $TEMPLATE_FILENAME_DESTINATION_JAR_FILE

# Repackage the file. this must be done using the current folder otherwise the class-files will have an absolute path in them
cd $JAR_FILE_UNPACKED_FOLDER
jar cvfm $ANTLR4TS_FOLDER/typescript.jar ./META-INF/MANIFEST.MF .

# Copy to source location and rename to right filename
cd $ANTLR4TS_FOLDER
cp typescript.jar ${PROJECT_ROOT}/node_modules/antlr4ts-cli/target/antlr4-typescript-4.9.0-SNAPSHOT-complete.jar

@cubuspl42
Copy link

I also get something like this:

src/generated_parser/MetamarkLexer.ts:83:13 - error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Lexer'.

83  public get serializedATN(): string { return MetamarkLexer._serializedATN; }
               ~~~~~~~~~~~~~

I have strict tsconfig.json settings in my project and it's not really possible to add an exception from a rule for ANTLR-generated classes... So I'm basically forced to use less safe compiler options 😔

@fronbasal
Copy link

Still seeing the same thing on TypeScript 4.9.5 :(

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

6 participants