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

Concise Ast_traverse.sexp_of #561

Merged
merged 3 commits into from
Feb 12, 2025
Merged

Conversation

ceastlund
Copy link
Collaborator

As tests in the first commit show, Ast_traverse.sexp_of is ridiculously verbose. The output is overwhelmed with empty fields, the fields of location records, and so forth. This feature applies several shorthands to the sexp that make it much more manageable, while still uniquely expressing a value.

  1. Longidents are rendered as a single string, unless parsing fails to round-trip.
  2. Location.none is elided as ().
  3. Other locations are rendered as strings, with suffix <ghost> if loc_ghost=true.
  4. Records drop fields containing only the sexp ().
  5. Records with only one remaining field named txt or *_desc reduce to that fields' value.

After these changes, the test output goes from so long OCaml won't print it to only a few times larger than the Pprintast output.

@ceastlund ceastlund marked this pull request as ready for review February 7, 2025 17:40
Copy link
Collaborator

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@NathanReb NathanReb merged commit b67212a into ocaml-ppx:main Feb 12, 2025
5 of 6 checks passed
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.

2 participants