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
Replace ANTLR 2.x with updated ANTLR 4 #3055
Comments
Link to Florian's earlier work: https://github.com/fjenett/processing-preprocessor-antlr4 Note that because this is so fundamental to what the PDE does, it needs a lot of testing and a committed maintainer (or at least longer than "hey this is working / incorporate it / bye"). We can't incorporate a "mostly working" set of code. |
I just happen to have a working ANTLR4 prototype branch based on Florian's work with complementary Android branch I worked on in August... it was more of a proof of concept work, but tests are green and I can run Java and Android sketches from PDE. Needs update to current HEAD, new error reporting, better tests. API for other modes will need some thought. https://github.com/JakubValtar/processing/tree/feature-antlr4 It's a great responsibility and I have to consider if I will be able to do good enough job and maintain it. However, I can at least make it work in current version in the meantime. |
Cool, thanks for looking into it. Keep us posted on how it evolves, and/or someone may also be able to help build on your work as you've done w/ Florian's. Here's an excerpt from an email from Florian:
And some back-and-forth with Florian responding to Manindra about incorporating ANTLR 4 with the PDE X code (which is now being merged into the main mode):
|
Yeah, that's also a possibility to update the code and hand it to someone else. I think I already fixed some of the issues... I have to revisit my branch and make a list, it's been four months since I touched it. Also, it would be great to talk about the whole system later, what is PDE X doing and what should this preprocessor exactly do and what not. |
It's code time! https://github.com/JakubValtar/processing/tree/feature-antlr-4.5 Merged with current master. Ant build works, tests are green, size() is parsed into sketchXxxx() methods, you can run sketches from PDE. No error reporting yet. Edit: just found Florian's other repository. Will update my branch with improvements he made. |
Cool, thanks for the update. |
@JakubValtar what's your status on this? |
@benfry Sorry about lack of updates, I was really busy recently. I'm finishing multiple projects this week, will have time to work on this next week. |
Thanks; let me know how it goes. |
@benfry Hi, several things got delayed and sadly I'm not able to work on this one before my graduation mid-June. It would be probably best to tackle this during the summer. |
@JakubValtar Did you happen to find time yet? |
Hey there! Just to keep threads updated... I started continuing @JakubValtar's work over at sampottinger#15 but, in addition to fast forwarding to current master, it uses #5753 as its base. I have a build working over there again though there are some specific errors that still need to be handled. I'll redirect sampottinger#15 from my fork to this repo after #5753. |
Hey @sampottinger, I think the latest plan was to get rid of ANTLR altogether and use Eclipse JDT instead, because JDT keeps up with Java updates and it is easier to build custom features on top of it, whereas messing with ANTLR grammar definitions is something of a lost art. JDT is already powering the live error checking and advanced features like Rename, Go to definition and Find all references and under all of that is JDT based PreprocessingService.java. Most of the building blocks needed are already there. The problem now is JDT and ANTLR work in a different way and also report errors in a different way. You will have to figure out a way to fit the JDT based preprocessor into an ANTLR shaped hole. |
So the first step would be to get rid of all ANTLR stuff?
Also what influence has this on the primitive color type?
Op wo 27 mrt. 2019 om 12:29 schreef Jakub Valtar <notifications@github.com>:
… Hey @sampottinger <https://github.com/sampottinger>, I think the latest
plan was to get rid of ANTLR altogether and use Eclipse JDT instead,
because JDT keeps up with Java updates and it is easier to build custom
features on top of it, whereas messing with ANTLR grammar definitions is
something of a lost art.
JDT is already powering the live error checking and advanced features like
Rename, Go to definition and Find all references and under all of that is
JDT based PreprocessingService.java
<https://github.com/processing/processing/blob/master/java/src/processing/mode/java/pdex/PreprocessingService.java#L257>.
Most of the building blocks needed are already there.
The problem now is JDT and ANTLR work in a different way and also report
errors in a different way. You will have to figure out a way to fit the JDT
based preprocessor into an ANTLR shaped hole.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3055 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAtFWhN3o0moB4cFeVf8Yd1q6zAO4fnzks5va1YqgaJpZM4DV2QH>
.
|
Hello @JakubValtar and @clankill3r! Thanks for your notes back. 😄 Inline Responses
I love it ha ha! This would simplify things quite a bit. Is there a place where that was discussed or was this started at some point?
Hum I could maybe use your help in understanding this... I see we do edits via
Yeah I agree there might be some re-plumbing to do. I am curious though, while not necessarily justifying the retention of ANTLR, wouldn't the ANTLR message be preferred in some situations? I've noticed the JDT errors are sometimes poorly attributed in the case of grammatically incorrect input like below.
I see multiple lines (some correct) flagged in JDT but ANTLR identifies the localized issue. (On my branch the user gets Questions for the community
Either way, thank you both very much! We've been missing some pretty (ahem) nice features for a few years now and I'm excited to hopefully get one option (ANTLR + JDT) or the other (JDT no ANTLR) in. |
Not sure I understand. We can't just remove it, because without a preprocessor you wouldn't be able to run your sketch. It needs to be replaced by a preprocessor with equal functionality.
JDT is aware of @sampottinger You should talk with @benfry before you start working on this. Here is what I remember: Reasons for removing ANTLR:
Reasons for keeping ANTLR:
That is correct, JDT can only parse Java. The idea is to first perform only the necessary edits to make the code parsable by JDT (move imports to the top, replace type constructors and hex literals, detect mode and wrap the sketch into a class). After that JDT can parse the code into AST and by walking the tree we can do more advanced changes (replace The build has some extra steps which need to happen, first three can be implemented by traversing AST, other two are trivial:
I'm not sure right now whether context-sensitive or context-free, but I don't think you can do all preprocessing with regex.
It's possible that ANTLR can sometimes give a better error, but I think JDT is in a good spot – it received most of the work in the recent years. It can be further improved by better error message rewriting (the example you posted is not rewritten properly).
It would enable most of the syntax changes up to Java 8, except lambdas. That's almost all the changes, but I'm still not sure if that's worth it. Build process is a central component which everyone has to use, and if something breaks there, you have a big problem. I wouldn't recommend doing any unnecessary changes there. We should probably run beta releases until the new build system stabilizes.
No, the mapping is almost 1:1 and there are no errors introduced or lost. One thing which is still missing is mapping the error message contents back to Processing code (when
Android mode shares some of the infrastructure with Java mode, but other modes use their own build process and error checking. Uf, that's a lot of text, but it's also a complicated issue. I hope it's useful! If you need some more info, feel free to ask me, I will try to get back to you as my time allows. |
Hey @JakubValtar! Thanks for writing back. Just to clarify for those following along, sampottinger#15 is a working (but still WIP) branch that supports Java 8 language features within the Processing IDE (including lambdas) that integrates with the JDT to produce error message properly in the editor. It is on my branch though because it is branched from changes waiting I have waiting for review in my other PR at #5753 (support for Java 11 / OpenJDK / OpenJFX). Anyway... @JakubValtar, thanks so much for hanging with me here. Again, apologies if I'm missing some obvious stuff. Just come clarifying questions though...
Thank you. I really really appreciate it.
Why not lambdas? sampottinger#15 does change the grammar to support it in ANTLR. Is there an issue elsewhere?
I agree but the build system right now uses ANTLR and the JDT is just for the editor right? Wouldn't the removal of ANTLR to use
I agree that the JDT is pretty active. However, isn't ANTLR also under active development? Were you talking about the grammar here specifically or ANTLR in general?
On official master processing, do you not get incorrect lines highlighted for the example I posted?
I guess my thought here is that some of the features probably require a formalized grammar so are we stuck with ANTLR or ANTLR adjacent anyway?
Just curious, what makes these systems incompatible? In sampottinger#15, I actually removed use of
I can take another crack at it but wouldn't this be easier with preprocessing generating the full AST?
|
Hello there! I know there's still some conversation ongoing and I respect if we decide to go another direction but, given that sometimes things schedule-wise get in the way of contributing code back, I went ahead and finished off sampottinger#15 just to provide a complete PR if we decide to take that path forward. Hopefully always good to have a PR ready to go? See sampottinger#15 for more details but it unifies the preprocessing mechanisms used in If you are interested in trying it out, it is dependent on #5753 but you can preview what everything looks like (after sampottinger#15 and a few other PRs I have in flight) by going to my fork's master branch. Let me know what you think: https://github.com/sampottinger/processing! Thanks so much for the conversation and help so far. I'll try to keep an eye on this thread for further comments. Pending discussion here, I'll can also try looking into the other direction (removing ANTLR and expanding use of [Edit updated picture] 😛 |
Introduces ANTLR4 and Java 8 language feature support within IDE while also adding additional hooks for localization of syntax error messages, addressing processing/processing#3054 and processing/processing#3055. The PR is broadly a continuation of processing/processing#3055, bringing it up to speed with the latest Processing master plus the changes introduced at processing/processing#5753. **Requires processing/processing#5753 as pre-requisite.** This introduces a number of edits beyond processing/processing#3055 beyond compatibility with current Processing master and processing/processing#5753 including: - Update to the grammar itself - Change ANTLR listeners to emit `TextTransform.Edit` to unify JDT-based `PreprocessingService` and `JavaBuild`, removing code with duplicate purpose. - Introduction of syntax error rewriting with support for localization. - Addition of complete localized strings set for English and Spanish. - Addition of partial localized strings set for other languages. - Refactor of ANTLR-related code for testability and readability - Expansion of tests including full parse tests for new Java features (type inference, lambdas).
* Move to ANTLR 4 with Java 11 lang features and localization. Introduces ANTLR4 and Java 8 language feature support within IDE while also adding additional hooks for localization of syntax error messages, addressing processing/processing#3054 and processing/processing#3055. The PR is broadly a continuation of processing/processing#3055, bringing it up to speed with the latest Processing master plus the changes introduced at processing/processing#5753. **Requires processing/processing#5753 as pre-requisite.** This introduces a number of edits beyond processing/processing#3055 beyond compatibility with current Processing master and processing/processing#5753 including: - Update to the grammar itself - Change ANTLR listeners to emit `TextTransform.Edit` to unify JDT-based `PreprocessingService` and `JavaBuild`, removing code with duplicate purpose. - Introduction of syntax error rewriting with support for localization. - Addition of complete localized strings set for English and Spanish. - Addition of partial localized strings set for other languages. - Refactor of ANTLR-related code for testability and readability - Expansion of tests including full parse tests for new Java features (type inference, lambdas). * Ask travis for ant upgrade prior to run. * Ask Travis for java11 update. * Add openjdk ppa * Travis no confirmation on add ppa. * Force newer ant on travis. * Swtich ant download to www-us mirror. * Switch ant to 1.10.7 * Start x for unit tests in travis. * More complete start x in travis. * Revert x in travis. * Try x in services.
Fixed with benfry/processing4#1, further development is at https://github.com/processing/processing4 |
We're using a very old version of ANTLR. @fjenett did some work to move us to ANTLR 4, but there hasn't been enough testing (or someone committed to finishing that work) to include it in 3.x yet.
See also #3054, which is about updating the grammar (the
java.g
file) to support newer Java language features.The text was updated successfully, but these errors were encountered: