An option to print the source AST using deriving yojson, show #2831
+2,029
−1,387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@raulraja et al. requested an option to print the parser AST in full detail.
This PR provides two options:
--print_ast: Which takes a module/namespace selector for the names of the modules whose AST is to be printed
--print_ast_format [JSON | Show | Internal ]: Which selects one of three formats in which to print the AST, with Internal an ad hoc internal format as the default. The JSON and Show formats are determined by the ppxderiving options for deriving Yojson and Show-based printers
For example, you can write
fstar.exe --print_ast_format JSON --print_ast +Unit1 Unit1.Basic.fst
to print the AST of all files in the Unit1 namespace.By default, the printers produced by deriving Yojson and Show are extremely verbose. They print the entire AST, including all the metadata at each node, like the range information on terms and at every identifier.
So, the main code change in this PR is to refactor the Parser.AST and FStar.Ident.ident and lident types to make it possible to easily omit some of the fields in printing.
The general recipe here is that if you have a type
and you only want to print the
f:tf
,abstract the type a bit to
and define
This, in a generic way, matches the signatures expected by the deriving packages for YoJson and Show and allows one to print just the fields of interest.
I used this recipe on the following types:
The changes to FStar.Ident are localized and make no difference in the interface.
The changes to FStar.Parser.AST do impact several frontend modules, so most of the code change is related to that. Arguably, the change is an improvement, since it factors a lot of the duplication around ranges etc. into a single type, rather than inserting them in several types in the AST (e.g., prange for patters, brange for binders etc.)