Skip to content

Commit

Permalink
Begin AST structure
Browse files Browse the repository at this point in the history
Summary:
Add boilerplate for an AST structure intended to look close to
idiomatic Rust.

The top-level struct is `Node`, which contains common information to
all nodes such as the `SourceRange` which they occupy.

Most strings in the AST are represented by Rust strings,
except for string and template literals,
which may contains invalid UTF-8 and are therefore represented
as UTF-16 by `Vec<u16>`.
The AST being a tree, each node owns its children via either
`Box<Node>` or `Vec<Node>`, which have been type aliased accordingly.

Differentiate between AST nodes via `NodeKind`,
an `enum` which houses each of the variants.
`NodeKind` is generated via macro in order to make it easier to
add more functions which `match` on every kind of node,
such as visitors.
Change the names of the fields from ESTree.def to Rust naming
conventions, so `camelCase` has been changed to `snake_case`.
The fields with reserved words as names have added `is_` at the front.
In the future, if we need serialization or compatibility,
mappings for those can be added within copying/conversion logic.

Reviewed By: tmikov

Differential Revision: D29623395

fbshipit-source-id: 27ae213feb53ca84c0882191ec30b7b8503dce5f
  • Loading branch information
avp authored and facebook-github-bot committed Jul 22, 2021
1 parent 9d15fef commit c06587d
Show file tree
Hide file tree
Showing 3 changed files with 969 additions and 0 deletions.
Loading

0 comments on commit c06587d

Please sign in to comment.