-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add option to Parse.java to print AST in JSON #53
Comments
What should [the] JSON format be?We should consider using Jackson (no relation to me). It serializes POJOs (plain old Java objects) into JSON format. On the other end, we should look at Jsonic. It deserializes JSON into instances of given classes. The question is, are the two compatible? Can the JSON generated by Jackson be read by Jsonic? If so, this could be easy. If not, we may need to programmatically massage the output of Jackson's output so that it is suitable for Jsonic. If these work, then we don't have to invent a JSON format. They may also save us from writing a lot of code. |
Implement as an ITrace?I don't think this will work (at least it won't be easy). Instead, I think we'll need to implement a new class that inherits from ProcessFiles, named something like JsonTree, that's like Parse but uses Jackson to produce JSON of the parsed tree. What should option name be?
The first is probably overkill at the moment since we are implementing only a single output format. The third is a little vague. The second is probably the best if possible. If we want this to run as an option to Parse (i.e., Options of Parse are handled by ProcessFiles, which Parse inherits. Assuming JsonTree also inherits from ProcessFiles, the Parse implementation would need to construct a JsonTree and use it instead of itself. But the JsonTree would need to ignore this option, lest it infinitely, recursively constructs JsonTree objects. The problem is that the base class ProcessFiles is where options are handled, but we need the |
@Rarity-Belle @WilliamBowery Please explore/try-out Jackson and Jsonic and see if they will work for us. |
Issue: Jackson is a 3rd party Java package. To use 3rd party Java packages, it's best to use a package manager to resolve dependencies. In Java, that's Maven or Gradle. Gradle is the newer of the two. So @Rarity-Belle and @WilliamBowery are figuring out how to set up Gradle with PLCC. |
Gradle is a bad idea because it would add a dependency for end users (Gradle). Instead, we're going to try to ship the jar files for Jackson with PLCC and then include them in the classpath when compiling and running plcc stuff. This would not require an extra dependency. |
The Parse program builds an AST from classes that PLCC creates. The user can only enhance those classes. If we want to display the AST visually, and the the tree already exists as a collection of instances of PLCC-created classes, why not have PLCC add code to those classes to display the tree? Also, these notes don't say why viewing the AST in JSON is useful. |
How exactly do you want the AST to be printed? Running Parse with the '-t'
option prints the AST in a rather klutzy way...
…On Fri, Oct 6, 2023, 1:54 PM James Heliotis ***@***.***> wrote:
The Parse program builds an AST from classes that PLCC creates. The user
can only enhance those classes. If we want to display the AST visually, and
the the tree already exists as a collection of instances of PLCC-created
classes, why not have PLCC add code to those classes to display the tree?
Also, these notes don't say why viewing the AST in JSON is useful.
—
Reply to this email directly, view it on GitHub
<#53 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABN5MQVSJJCGQDRRN7QJOM3X6BAVFAVCNFSM6AAAAAA5ANRKV2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJRGE4TANJQGE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
The goal: cat program | java -cp Java Parse --json | python -m plcc.rep If we use the output of Once we can dump ASTs in JSON, then we can use plethora of tools and libraries that work with JSON. |
To print an AST for a program in JSON format, do the following. plccmk --json_ast GRAMMAR_FILE parse --json_ast < PROGRAM_FILE Adds a new dependency: the Jackson JSON library for java. We distribute jars (in src/lib) from the following projects under the Apache 2.0 license: * https://github.com/FasterXML/jackson-core * https://github.com/FasterXML/jackson-databind * https://github.com/FasterXML/jackson-annotations If manually compiling and running the generated Java code, you'll need to add these jars to your classpath. If you don't use the new --json_ast option, these jars do not need to be in your classpath. --- Closes #53 - Add option to print parsejava to print ast in json Co-authored-by: Madison Mason <[email protected]> Co-authored-by: Rarity Van Lone <[email protected]> Co-authored-by: Stoney Jackson <[email protected]>
🎉 This issue has been resolved in version 6.1.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Parent issue: #52
Design decisions that need to be made
The text was updated successfully, but these errors were encountered: