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
[Merged by Bors] - feat(parser): AST tracking and export #608
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bors try |
bors r+ |
bors bot
pushed a commit
that referenced
this pull request
Aug 25, 2021
This PR implements AST tracking across the whole parser. That means that every parser command creates an AST node, and the result can currently be exported via the `--ast` command line argument, which produces a `foo.ast.json` file for every `foo.lean` file that is processed (note that files that already have oleans will not be processed and so will not have ast files generated). The basic schema of the exported JSON file (see `ast_exporter.cpp`) looks like this: ```ts { ast: [null | { kind: string, value?: name, start: [int, int], end?: [int, int], children?: [int], pexpr?: int, expr?: int, }], file: int, level: [ "0" | {suc: int} | {max: [int, int]} | {imax: [int, int]} | {param: int} | {mvar: int} ], expr: [ {var: int} | {sort: int} | {mvar: {name: name, pp: name, type: int}} | {local: {name: name, pp: name, bi: int, type: int}} | {const: [name, [int]]} | {Pi: {name: name, bi: int, dom: int, body: int}} | {lam: {name: name, bi: int, dom: int, body: int}} | {app: [int, int]} | {let: {name: name, type: int, value: int, body: int}} | ... // one variant per macro ] } ``` The https://github.com/dselsam/mathport repo contains an .ast.json parser developed in tandem with this PR, which can be used as a more precise specification for the files, at least until a proper specification is written. The behavior of lean with the `--ast` option disabled should be otherwise unchanged, although memory usage might possibly be a bit higher. It is possible to compile the AST stuff out if necessary, or disable the collection at runtime, but this version does not support that. Future extensions may add direct access to the AST data from within lean.
Pull request successfully merged into master. Build succeeded: |
bors
bot
changed the title
feat(parser): AST tracking and export
[Merged by Bors] - feat(parser): AST tracking and export
Aug 25, 2021
dselsam
pushed a commit
to dselsam/lean3
that referenced
this pull request
Sep 8, 2021
This PR implements AST tracking across the whole parser. That means that every parser command creates an AST node, and the result can currently be exported via the `--ast` command line argument, which produces a `foo.ast.json` file for every `foo.lean` file that is processed (note that files that already have oleans will not be processed and so will not have ast files generated). The basic schema of the exported JSON file (see `ast_exporter.cpp`) looks like this: ```ts { ast: [null | { kind: string, value?: name, start: [int, int], end?: [int, int], children?: [int], pexpr?: int, expr?: int, }], file: int, level: [ "0" | {suc: int} | {max: [int, int]} | {imax: [int, int]} | {param: int} | {mvar: int} ], expr: [ {var: int} | {sort: int} | {mvar: {name: name, pp: name, type: int}} | {local: {name: name, pp: name, bi: int, type: int}} | {const: [name, [int]]} | {Pi: {name: name, bi: int, dom: int, body: int}} | {lam: {name: name, bi: int, dom: int, body: int}} | {app: [int, int]} | {let: {name: name, type: int, value: int, body: int}} | ... // one variant per macro ] } ``` The https://github.com/dselsam/mathport repo contains an .ast.json parser developed in tandem with this PR, which can be used as a more precise specification for the files, at least until a proper specification is written. The behavior of lean with the `--ast` option disabled should be otherwise unchanged, although memory usage might possibly be a bit higher. It is possible to compile the AST stuff out if necessary, or disable the collection at runtime, but this version does not support that. Future extensions may add direct access to the AST data from within lean.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR implements AST tracking across the whole parser. That means that every parser command creates an AST node, and the result can currently be exported via the
--ast
command line argument, which produces afoo.ast.json
file for everyfoo.lean
file that is processed (note that files that already have oleans will not be processed and so will not have ast files generated).The basic schema of the exported JSON file (see
ast_exporter.cpp
) looks like this:The https://github.com/dselsam/mathport repo contains an .ast.json parser developed in tandem with this PR, which can be used as a more precise specification for the files, at least until a proper specification is written.
The behavior of lean with the
--ast
option disabled should be otherwise unchanged, although memory usage might possibly be a bit higher. It is possible to compile the AST stuff out if necessary, or disable the collection at runtime, but this version does not support that. Future extensions may add direct access to the AST data from within lean.