Generate AST types from ASDL (Abstract Syntax Description Language) descriptions.
Dependencies
moon run cmd/asdl-gen path/to/schema.asdl --target moonbit -o schema.mbt///|
test "asdl_to_moonbit" {
let asdl =
#|module Expr {
#| expr = Num(int n) | Add(expr left, expr right)
#|}
let code = @asdl.asdl_to_moonbit(asdl)
let expected =
#|///|
#|pub type Identifier = StringView
#|
#|///|
#|pub(all) enum Expr {
#| Num(n~ : Int)
#| Add(left~ : Expr, right~ : Expr)
#|} derive(Debug)
#|
#|///|
#|pub extend Expr with Debug::{ to_repr }
#|
assert_eq(code, expected)
}| Stage | Package | Role |
|---|---|---|
| Lexer | lexer/ | Tokenize ASDL source |
| Parser | parser/ | Build an ASDL module AST |
| Checker | checker/ | Validate type names and definitions |
| Backend | backend/ | Emit target-language source (MoonBit today) |
module ASDL {
module = (identifier name, definition* definitions)
definition = Product(identifier name, field* fields)
| Sum(identifier name, constructor* constructors, field* attributes)
constructor = (identifier name, field* fields)
field = (identifier type, quantifier? quant, identifier? name)
quantifier = Optional | Sequence
}Install
Download zipGenerate AST types from ASDL (Abstract Syntax Description Language) descriptions.
Dependencies