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

[Merged by Bors] - feat(parser): AST tracking and export #608

Closed
wants to merge 6 commits into from

Conversation

digama0
Copy link
Member

@digama0 digama0 commented Aug 23, 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:

{
  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.

@bryangingechen
Copy link
Collaborator

bors try

bors bot added a commit that referenced this pull request Aug 25, 2021
@bors
Copy link

bors bot commented Aug 25, 2021

@gebner
Copy link
Member

gebner commented Aug 25, 2021

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.
@bors
Copy link

bors bot commented Aug 25, 2021

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(parser): AST tracking and export [Merged by Bors] - feat(parser): AST tracking and export Aug 25, 2021
@bors bors bot closed this 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants