# Verification

## Local commands

```sh
moon fmt --check
moon check --deny-warn
moon build --deny-warn
moon test --deny-warn
moon test --target wasm-gc --deny-warn
moon test --target js --deny-warn
moon test --target native --deny-warn
moon run examples/typed
moon run cmd/main
```

The baseline uses moonc 0.10.20. All declared runtime logic is MoonBit and has
no external package dependency beyond the standard library.

## Independent Java reference

`tools/Oracle.java` loads parsers and lexers generated by the unmodified ANTLR
4.13.2 Java target. `tools/oracle.py` generates deterministic cases:

| Grammar | Cases | Accepted by the reference |
| --- | ---: | ---: |
| JSON | 98 | 81 |
| Arithmetic | 65 | 55 |
| Split lexer/parser with modes | 15 | 12 |
| CSV | 34 | 30 |
| Precedence / associativity | 75 | 64 |
| Prefix, postfix, ternary and nested EBNF | 80 | 29 |
| Typed labelled grammar | 44 | 38 |
| Context-sensitive / ambiguous decisions | 26 | 22 |
| Predicate gating | 4 | 4 |
| Non-greedy lexer decisions | 6 | 4 |

Accepted cases compare the complete rule-labelled tree and every emitted token's
type, text, scalar offsets, line, column and channel. Rejected cases must also
be rejected by MoonANTLR. Rejection tests do not claim matching error text or
ANTLR error-recovery behavior. Seeds and counts are recorded in
`tests/oracle-manifest.json`; the expected outputs are committed so running
the tests does not require Java.

There are 447 independent oracle cases. Accepted cases verify exact trees,
not merely acceptance. Decision cases include caller-sensitive short/long
alternatives, ambiguity order and common prefixes longer than the predictor's
64-token window. Left-recursion cases exercise nested EBNF stars to prevent
accidental creation of recursive contexts at unrelated loop entries.

Generated API tests check optional/list labels, left/right operand identity,
alternative narrowing, spans, Visitor results and Listener event order.
Prediction tests require full-context fallbacks and DFA cache hits.
`python tools/check_target.py --jar /path/to/antlr-4.13.2-complete.jar` separately
builds the plugin and checks the real ANTLR CLI on combined/split grammars,
listener/visitor flags, and exact emitted ATN equality with `.interp` artifacts.
CI regenerates and compiles the native-target fixtures as well.

The handwritten runtime tests additionally cover all truncated prefixes of a
real parser ATN, corrupted headers and section data, trailing serialized data,
unknown rules, explicit work limits, Unicode positions and invalid JSON.
They also cover every truncated prefix of the lexer artifact and two sentinel
mutations at every field of the JSON lexer/parser and mode lexer artifacts.
Structural validation checks block/loop references, decision tables, rule stop
states, symbol bounds and mode/action indices before execution.

`python tools/check_cli.py` exercises the command as an external JSON consumer.
The arithmetic evaluator and CSV reader have application-level tests alongside
the Java conformance corpus.

Regenerate with Java 17, Python 3.10+ and the official complete JAR:

```sh
python tools/oracle.py --jar /path/to/antlr-4.13.2-complete.jar
moon fmt
moon test --deny-warn
```

Use `--java` and `--javac` for explicit executable paths. The JAR SHA-256 is
verified before use. Temporary files live under the ignored `.local/` directory;
generated source comments contain grammar basenames and hashes, not local paths.

CI checks, builds, tests and runs the example on wasm, wasm-gc, JS and Linux
native. A separate job regenerates the grammar artifacts and Java-reference
tests, then rejects any difference from the committed outputs.
