Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 219 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,46 @@ antlr4-rust-gen \
Use multiple roots when a build should emit several independent recognizers in
one deterministic source-set compilation.

### Run a grammar with TestRig

TestRig can run directly from a grammar-only project. The project does not need
a `Cargo.toml`, generated Rust sources, or a runtime dependency; it only needs a
Rust toolchain because TestRig invokes Cargo internally. Install the companion
command from the codegen package:

```bash
cargo install antlr-rust-codegen --bin antlr4-rust-testrig
```

From the grammar project, pass a combined grammar, its parser start rule, and
zero or more UTF-8 inputs. With no input files the command reads stdin:

```bash
antlr4-rust-testrig JSON.g4 json --tokens --tree examples/*.json
echo '{"ok":true}' | antlr4-rust-testrig JSON json --tree
```

For a lexer grammar, use the special start rule `tokens`. Pair split grammars
with `--lexer-grammar` and the same import directories used for generation:

```bash
antlr4-rust-testrig MyGrammarParser.g4 start \
--lexer-grammar MyGrammarLexer.g4 \
--lib grammar \
tests/valid/*.txt
```

`--trace`, `--diagnostics`, and `--sll` expose the corresponding parser modes.
Each invocation generates the recognizer and a grammar-specific runner in a
temporary Cargo package, selects the matching `antlr-rust-runtime` release, and
removes the generated package afterward. Cargo build artifacts are reused, so
the first invocation can take longer while dependencies and the runner compile.

TestRig processes every named input and returns a non-zero status when
generation, temporary runner compilation, input reading, lexing, or parsing
fails. Recovered lexer and parser syntax errors therefore fail CI even when a
parse tree was produced.

### Generated-source/runtime compatibility

Every newly generated lexer and parser contains a compile-time generated-code
Expand Down
Loading
Loading