Skip to content
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

53 add option to parsejava to print ast in json #68

Merged
merged 39 commits into from
Nov 29, 2023

Conversation

StoneyJackson
Copy link
Member

@StoneyJackson StoneyJackson commented Nov 8, 2023

feat: print AST in JSON format

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]>

@StoneyJackson StoneyJackson linked an issue Nov 8, 2023 that may be closed by this pull request
@StoneyJackson StoneyJackson marked this pull request as draft November 8, 2023 18:50
@StoneyJackson
Copy link
Member Author

StoneyJackson commented Nov 8, 2023

Review

Excellent! Now we need to get the design, the UI, and the documentation right. On the design side, it would be good if the new JSON generator is copied over to Java/ when it is needed. So this needs to be an extra option to plcc.py. This is important so existing systems, when updated do not need to update their classpaths. Also we need to update the installation documentation to explain how to add the 3rd party libraries, and when that is necessary. We also need docs on how to use this stuff. All docs are in the project's wiki. We should also update the docker images so they install the jackson libraries.

Here's a todo-list.

  • Remove example grammar, program, and json ASTs from the repo.
  • Tests need to pass.
  • Need a test for the new system. Maybe build it out of the example grammar, program, and json AST that are currently in the root.
  • Update wiki docs
    • Install
    • Use
  • Write a commit message

src/plcc.py Outdated
STDT = ['ILazy','IMatch','IScan','ITrace', 'Trace', 'PLCCException', 'Scan']
STDP = ['ProcessFiles','Parse','Rep']
print(argv)
if len(argv) > 1:
if argv[0] == "--python":
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plcc.py has a mechanism for handling command-line arguments. Unless there is a good reason, we should probably work within that framework.

Specifically, there is a loop in main() that walks through all the command line arguments and calls processFlag() to populate a global dict with flags. The rest of the system interrogates flags to decide what to do.

@StoneyJackson
Copy link
Member Author

Let's use --json-ast for all of our options (e.g., plccmk --json-ast and plcc.py --json-ast). This better expresses what the new feature does. And allows for future features like --json-token.

The next phase of this project can add --python and make use of these --json-ast options.

_Start parseTree = _Start.parse(scn, trace);
parseTree.$ok();
try {
objectMapper.writeValue(new File("ASTroot.json"), parseTree);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should print the AST to stdout. Can we do that?

@StoneyJackson
Copy link
Member Author

I've added a test that should pass when:

  • --json-ast is used for plccmk and plcc.py
  • parse prints the AST to stdout and not a file.

@StoneyJackson
Copy link
Member Author

Great work on you recent commits!

I just overhauled the docs in main. Please synch this branch before updating docs.

@StoneyJackson
Copy link
Member Author

StoneyJackson commented Nov 17, 2023

  • Do Windows Batch files need to be updated?

NOPE

@StoneyJackson
Copy link
Member Author

I just overhauled the docs again! Now everything we either update the README.md in the root, or write a separate document about the new options. At the moment, the first sounds better.

@StoneyJackson StoneyJackson marked this pull request as ready for review November 29, 2023 20:19
@StoneyJackson StoneyJackson merged commit 559ff22 into main Nov 29, 2023
4 checks passed
@StoneyJackson StoneyJackson deleted the 53-add-option-to-parsejava-to-print-ast-in-json branch November 29, 2023 20:24
Copy link

🎉 This PR is included in version 6.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to Parse.java to print AST in JSON
3 participants