Rants #14
Replies: 2 comments 3 replies
-
|
First of all, thank you for accepting me in this amazing group! I would like to share the use-cases that we have for ANTLR 4 at Strumenta, as the starting point discussing potential improvements in ANTLR 5. We use ANTLR on a daily basis, across different projects to build two main kinds of projects:
Do you also use ANTLR for similar purposes? Or do you build different things with it? Error tolerance and APII think there is a main difference in how we use the parser in the two contexts I described above:
For example, let's suppose that we are examining a sum operation, When working with parsers with correct code, we may want the node class to look like this: So that we can access the left and right operand and be sure to get valid values back. This means skipping a lot of ifs. When using the parser within the editor, we instead need to have this API: This is the case because the expression could be malformed (as the user is typing the code when we process it). Because of that the tree may be incomplete. We still need to process it for things like autocompletion. Multiple platformsOften we need to build a parser for the same language and be able to use it from multiple platforms. These is the case for two different reasons:
While we can write a grammar without semantic actions or predicates and generate parsers using multiple targets, we typically also need to share some code around the parsers, to process some nodes. For example, we could want to share some semantic error-checking logic or symbol resolution logic across the different platforms. Right we use some form of inter-process communication, with one component doing the work, for example on the JVM, and another component in Typescript or Python contacting the JVM component through web sockets and getting some result serialized in JSON, protobuf or something else. We have our own tools to generate stubs and handle serialization and de-serialization on the two sides, but still deployment is a little bit cumbersone. We also explored the idea of solving this problem by using Kotlin multi-platform, and this is why we started working on the ANTLR Kotlin target. The idea was to generate Kotlin multiplatform parser code, depending on the Kotlin multiplatform runtime, and build libraries on top of that in Kotlin multiplatform, to be later integrated in JVM applications, browser applications, but also Python by generating native libraries and Python wrappers. I understand that the goal is to go for WASM and perhaps that will solve this problem for us. Tree reorganization + APIsCurrently the way in which we use ANTLR is by processing its results and wrapping them with one of our libraries (Kolasu, Tylasu, Pylasu, or SharpLasu, they are basically porting of the same library to Kotlin, TypeScript, Python, and C#, where Kolasu is by far the most mature one). We do that for two reasons:
Tree re-organizationFor tree reorganization, we do that in two ways:
Special comments in the grammar can look like this: While the mapping in code could look like: APIsWe have a lot of APIs to do things such as:
I could go more in detail about this in separate issues, as we have a lot of different APIs to process the trees in different ways, but here there are a few considerations. The homogeneous/reflective APIs is the most important one. It consists in the possibility of asking each node for its type, and then ask the type for its structure. This is useful to implement generic algorithms like XML serialization. For example, something like: Regarding APIs to traverse the tree, we like to use tree iterators and ways to find in a subtree nodes of a given type. We never use listeners or visitors. I hope this is not too long, and if there is any question I am happy to go more in detail |
Beta Was this translation helpful? Give feedback.
-
|
User rant: antlr/antlr4#455 |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
This place is for respectfully criticizing antrl4, throwing out immature suggestions, any stuff that doesn't yet deserve a dedicated discussion.
Beta Was this translation helpful? Give feedback.
All reactions