1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00
semantic/semantic-ast/README.md

33 lines
1.3 KiB
Markdown
Raw Normal View History

2019-09-10 22:13:39 +03:00
# semantic-ast
This package has two goals:
1. Develop a library that will produce ASTs;
2. Provide a command line tool that will output ASTs in supported formats.
2019-10-16 18:53:38 +03:00
#### CLI
2019-09-10 22:13:39 +03:00
2019-10-16 18:53:38 +03:00
To output ASTs, run the `semantic-ast` command, specifying two mandatory options: 1) the format you'd like to return (ex., `Show`, `JSON`, etc.) and 2) the option specifying whether the source code will be passed in directly via command line (using `--sourceString`) or via providing the file path `--sourceFile`.
2019-09-10 22:13:39 +03:00
2019-10-16 18:53:38 +03:00
Filepath:
```
semantic-ast --format [FORMAT] --sourceFile [FILEPATH]
```
2019-09-10 22:13:39 +03:00
2019-10-16 18:53:38 +03:00
Source string:
2019-09-10 22:13:39 +03:00
```
2019-10-16 18:53:38 +03:00
semantic-ast --format [FORMAT] --sourceString [SOURCE]
2019-09-10 22:13:39 +03:00
```
An example command is:
```
2019-10-16 18:53:38 +03:00
semantic-ast -- --format Show --sourceString "a"
2019-09-10 22:13:39 +03:00
```
This will generate an AST
```
2019-10-16 18:53:38 +03:00
Right (Module {ann = (Range {start = 0, end = 1},Span {start = Pos {line = 0, column = 0}, end = Pos {line = 0, column = 1}}), extraChildren = [R1 (ExpressionStatementSimpleStatement (ExpressionStatement {ann = (Range {start = 0, end = 1},Span {start = Pos {line = 0, column = 0}, end = Pos {line = 0, column = 1}}), extraChildren = L1 (PrimaryExpressionExpression (IdentifierPrimaryExpression (Identifier {ann = (Range {start = 0, end = 1},Span {start = Pos {line = 0, column = 0}, end = Pos {line = 0, column = 1}}), bytes = "a"}))) :| []}))]})
2019-09-10 22:13:39 +03:00
```