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

Add json mapper for pp_ast #526

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pedrobslisboa
Copy link

Description

Add json mapper on pp_ast to improve usage in tools such as AST Explorer.
The idea is to increment the @NathanReb PR #517

@NathanReb, your opinion on how to structure it better is very welcome.
@jchavarri @davesnx thank you for the help.

How

To use it, we just need to pass --json to ppxlib-pp-ast. It works with all other flags, such as --show-attrs and --show-loc.

How to test

  • In this branch build the project
  • Create a test.ml on the root and add some content
  • Run ppxlib-pp-ast test.ml and check the result
  • Run ppxlib-pp-ast --json test.ml and check the result
  • Use others flags to see the result with --json

Signed-off-by: pedrobslisboa <[email protected]>
Copy link
Collaborator

@patricoferris patricoferris left a comment

Choose a reason for hiding this comment

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

Just a quick comment from me, I don't think we would want to add yojson as a dependency of ppxlib for this feature (I might be mistaken).

The implementation uses the lifter to lift values to JSON values (not actually print them, like pp_simple_val does). So I wonder if this couldn't be its own little tool that depends on ppxlib?

One workaround if this were to be merged here would be to add yojson as a dependency for ppxlib-pp-ast and then ppxlib could just return the polymorphic variants that happen to correspond to the Yojson.Safe.t variants?

@NathanReb
Copy link
Collaborator

Yes, as Patrick said, ppxlib should not depend on external libraries as it otherwise prevents them from being able to depend on ppxlib.

The Yojson dependent parts should go into ppxlib-pp-ast or just a seperate tool shipped with ppxlib-tools.

We could add a json lifter to ppxlib but given it's fairly easy to write one this could be done directly in ppxlib-tools.

Did you try to load the resulting JSON into AST explorer? It would be nice to have a working usecase for this before we merge this feature!

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

Successfully merging this pull request may close these issues.

3 participants