Replies: 5 comments 8 replies
-
A number of comments here. First, while all languages have different structures and different capabilities we should try to keep the runtimes as similar as possible so that we maintainers can more easily help across targets. Certainly we should not shuffle classes around because people might be relying on the package structure. While perhaps not the best, I see no reason to risk changing these structures and organization. Next, I have a preference for actual TypeScript source code for the library itself (versus types in a separate file) because that will be what typescript developers expect or at least optimally. I suppose it's not the end of the world to not have static types in the library code. On the other hand, it's very attractive having a single js "root" source and then a ts "derivative" that was essentially the same thing without having two nearly identical copies. Having to maintain two separate js and ts targets could be problematic. I'm already burning out managing the languages and operating systems we have already. I made the shocking statement this weekend that coding it's not that fun anymore, and it's directly related to maintaining ANTLR and the myriad of languages, build systems, and requirements. |
Beta Was this translation helpful? Give feedback.
-
This is a pretty interesting situation and you, Ter, have to take the decision after all, I guess. What we have (or are about to get) is:
IMO the "right" approach is to remove the current JS target completely and instead create a full TS target, from which a JS target can be derived easily. This should also replace the With this approach we would also have just one "source of truth", instead of duplicating target code. |
Beta Was this translation helpful? Give feedback.
-
Mike, Ter, thanks for your comments.
There are a few non-official runtimes out there: ts, kotlin, and I’m not sure it’s for Ter or this group to decide anything about them. That rules out option 1.
The reason I`m investing in option 2 is it provides the best ROI: low investment (a few days - 5 so far, 2 or 3 more required), low maintenance (same runtime), high return (single npm package for both js and ts users).
Not sure I agree with your comment that it 'doesn't really use what TS is for’: the generated classes are pure TS, which is what ts users care about primarily. I very much doubt that there are more than a handful of ts developers out there who want to step into the runtime code itself. They just want to use it.
Also it has the massive benefit that it makes it easy for js users migrating to ts: it’s the same api and runtime, so for them it’s a no-brainer: if their app works in js, it ‘should’ work the same in ts.
(FYI, the js classes have the same name and api as the java ones, so cross-target maintenance is not affected by the tighter folder structure. And other runtimes also use their own folder structure: Go and Dart - I don’t think it’s worth a conversation)
I agree that ts users would rather have a full ts runtime rather than a js one, but I believe they are pretty used to a mixed ts/js environment since many npm packages follow that approach for similar historical reasons, including major ones such as react. I am in no way excluding a migration to ts in the future. But that will be much smoother once we have a running ts target, and can be done gradually, on a per class basis (that said, I’d rather invest next in wasm to improve performance than in migrating working code to ts).
Both option 2 and a pure ts target achieve the single source of truth, although imho option 2 does that better since the code that runs is ‘written' rather than ‘generated' from the written code.
Also not sure what you mean by ‘lack of interpreter support’ ? I think the only missing piece is the TokenStreamRewriter, a gap that’s easy to fill (and also exists for Dart). Am I missing something ?
… Le 6 sept. 2022 à 09:37, Mike Lischke ***@***.***> a écrit :
This is a pretty interesting situation and you, Ter, have to take the decision after all, I guess.
What we have (or are about to get) is:
A TS target, which works pretty well once you got used to a few quirks, but which is still in alpha stage (and will probably stay forever there), which means it should not be used in production environments. The target got a number of optimizations, which make it probably the fastest TS/JS runtime. However, these optimizations (and other limits) prevent further development of this target, which will sooner or later make it obsolete.
There's a variant which is not really TS, but just adds typings to the existing JS target. This has the advantage of no code duplication and the smallest possible effort for TS support. However, this approach doesn't really use what TS is for. There are still no type checks within the target code, not to mention that the target is not complete (e.g. no interpreter support). The folder structure is different compared to the Java (and other language target), but this could be changed. Otherwise this variant is close to be generally available.
There's a variant which truly is a TS cousin of the main Java target, with the same structure, same naming and includes all files. This approach follows the Java variant very closely. There are even Java SDK shims <https://github.com/mike-lischke/a4tstool/tree/master/lib/java> to avoid having to rewrite the generated code manually, if a change occurs there (new features, bug fixes etc.). The used approach allows to auto generate individual classes, if the need arises, with minimal manual effort after the machine translation, to get an updated TS class. However, this TS variant will need several months yet, before it can be used.
IMO the "right" approach is to remove the current JS target completely and instead create a full TS target, from which a JS target can be derived easily. This should also replace the antlr4 node module. The generated JS target can be made part of the repo (like the current JS target is), to avoid forcing people not interested in TS to have to install a typescript compiler.
With this approach we would also have just one "source of truth", instead of duplicating target code.
—
Reply to this email directly, view it on GitHub <#3867 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAZNQJALKU73R5XZGM7JR2TV43YC7ANCNFSM6AAAAAAQFFDQCY>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
Folks, I'm still thinking about this. It's a difficult decision. |
Beta Was this translation helpful? Give feedback.
-
ok, finally getting back to this. I have spent the past couple of months thinking about this and I don't think there's a perfect solution and so that means I'm going to disappoint everybody. haha. Story of my life ;). Anyway, I decided to make the minimal change which is to add type files for TS on top of the existing JS target. If I understand correctly, we are going to generate parsers that have type information baked in but when they use the runtime library, it's necessary to have the type files. @ericvergnaud what kind of shape is this PR in? #3870 when you think it's ready, let me know and I will poke around some more. |
Beta Was this translation helpful? Give feedback.
-
@mike-lischke and @ericvergnaud are both working on typescript targets for ANTLR. A discussion started on the mailing list but I am moving it here.
Mike said:
Eric:
Mike:
Eric:
Alessio:
Eric:
Beta Was this translation helpful? Give feedback.
All reactions