MoonBit runtime and tooling for ANTLR4 grammars
git clone https://github.com/wdgodghl/MoonANTLR.git
cd MoonANTLR
moon version --all
moon check --deny-warn
moon build --deny-warn
moon test --deny-warn
moon run cmd/mainmoon run examples/evaluate
moon run examples/csv
moon run examples/typed
moon run cmd/inspect -- arithmetic '1+2*3'
moon run cmd/inspect -- json --file './config.json'moon test --target wasm-gc --deny-warn
moon test --target js --deny-warn
moon test --target native --deny-warnlet grammar = @json.grammar()
let tokens = grammar.tokenize("{\"ready\":true}")
let tree = grammar.parse("{\"ready\":true}")
println(tree.to_sexpr())python tools/generate_target.py grammars/Typed.g4 --output generated/typed --jar /path/to/antlr-4.13.2-complete.jar
moon fmt
moon run examples/typedfn Grammar::parse(self : Grammar, source : String, start_rule? : Int, work_limit? : Int) -> ParseTree raise RuntimeErrorfn Grammar::parse_context(self : Grammar, source : String, start_rule? : Int, work_limit? : Int, predicate? : (Int, Int, Token) -> Bool) -> RuleContext raise RuntimeErrorfn Grammar::parse_detailed(self : Grammar, source : String, start_rule? : Int, work_limit? : Int, predicate? : (Int, Int, Token) -> Bool) -> ParseResult raise RuntimeErrorfn Grammar::parse_recovering(self : Grammar, source : String, start_rule? : Int, sync_tokens? : Array[Int], max_repairs? : Int, work_limit? : Int, predicate? : (Int, Int, Token) -> Bool) -> RecoveryResult raise RuntimeErrorpub(all) struct PredictionStatistics {
decisions : Int
full_context_fallbacks : Int
dfa_states : Int
dfa_hits : Int
}pub(all) struct RecoveryResult {
context : RuleContext?
diagnostics : Array[Diagnostic]
complete : Bool
}pub(all) struct RuleContext {
name : String
children : Array[ContextChild]
sources : Array[Int]
path : Array[Int]
}fn RuleContext::rules(self : RuleContext, name : String, states? : Array[Int]) -> Array[RuleContext]