# antlr-rust-g4-parser

An ANTLR v4 grammar parser generated by
[`antlr-rust-codegen`](https://crates.io/crates/antlr-rust-codegen) itself and
wrapped in a thin source-syntax facade. This is part of the generator's
dogfooding path: the checked-in lexer and parser recognize the same `.g4`
language that drives code generation, while the facade provides source IDs,
byte spans, tokens, trivia, CST traversal, and diagnostics.

## Usage

Add the parser with `cargo add antlr-rust-g4-parser`, then parse a grammar with
`parse_source`:

```rust
use antlr_rust_g4_parser::{SourceId, parse_source};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let source = r#"
grammar Expr;
root: INT EOF;
INT: [0-9]+;
WS: [ \t\r\n]+ -> skip;
"#;

    let grammar = parse_source(SourceId::new(0), "Expr.g4", source)?;
    let node_count = grammar
        .cst()
        .descendants(grammar.cst().root_id())
        .count();

    println!(
        "parsed {} tokens into {node_count} CST nodes",
        grammar.tokens().len()
    );
    Ok(())
}
```

`parse_source` rejects syntax errors. Use `parse_source_recovering` when a
consumer also needs the recovered CST and parser diagnostics.
