tunnelvisionlabs / antlr4ts

Optimized TypeScript target for ANTLR 4
Other
624 stars 106 forks source link

Please add support for Typescript 4.4.x #528

Open martinmolema opened 2 years ago

martinmolema commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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.

nidomiro commented 1 year ago

Here is an example on how to automate this: https://github.com/nidomiro/relation-tuple-parser/commit/8209a1bc120e0aa94334d2edb2c2ce85d7bee528

chengchengpei commented 1 year ago

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

nidomiro commented 1 year ago

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

martinmolema commented 1 year ago

@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 commented 1 year ago

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 commented 11 months ago

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 commented 9 months ago

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 commented 5 months ago

Still seeing the same thing on TypeScript 4.9.5 :(