- TypeScript 32.5%
- Zig 19.8%
- json 19.3%
- C 13%
- Nim 12.3%
- Other 3%
astTF | Transmission Format for Abstract Syntax Trees
astTF is a format to serialize AST data into JSON-glTF-like objects.
It is an efficient and extensible format for transmission and loading of AST data, for use in compilers and programming language tools.
Specification
The astTF specification can be found inside the ./spec folder:
spec/
├── astTF.zig : Type Declarations for Zig
├── astTF.h : Type Declarations for C
├── astTF.nim : Type Declarations for Nim
├── astTF.py : Type Declarations for Python
└── *.schema.json : JSON Schema representation of the Specification, for use by other tools
Samples
The ./samples folder contains working examples for every AST feature.
Each sample has an ast.atf file and a paired source file written in the original language.
See the samples' readme.md file for a complete list.
How to use
astTF allows serializing and transferring AST data in a compiler-agnostic way.
A parser writes an .atf file, and any number of backends can read it (code generators,linters, formatters, documentation tools)
without having to reimplement the parser themselves.
Given the code int x = 5;, a C parser would produce:
{
"root": 0,
"data": {
"modules": [{ "path": "main.c", "source": "int x = 5;\n", "body": 0 }],
"types": [{ "primitive": { "name": { "location": { "start": 0, "end": 2 } } } }],
"expressions": [{ "literal": { "kind": 0, "value": { "start": 8, "end": 8 } } }],
"bindings": [{ "name": { "location": { "start": 4, "end": 4 } }, "dataType": 0, "value": 0 }],
"statements": [{ "variable": { "id": 0 } }]
}
}
A backend (eg: a formatter, a linter, a code generator or any other tool), then reads this data with any regular JSON parser,
traverses (and/or modifies) the data in whatever way they need,
and is then free to re-transfer or process the result (eg: outputting documentation, machine code, linting, etc),
without ever having to parse C themselves at all.
Getting Started
The best way to start using this format is to go through the implementation roadmap,
and, one by one, add support for each feature to the application.
The phases are written and organized as an "implementation guide" for development,
and they gradually build upon the features of previous phases.
Buildsystem
note: These tools are useful mostly for development of the specification itself.
Requires bun.
bun install
bun spec # re-generate all spec files
bun test # run validation tests
bun test:zig # run zig parsing tests
License
MPL-2.0