A Java 14 grammar for
Iguana, written in
Iggy and based on the
syntax described in the
Java Language Specification.
The grammar is defined in java.iggy and can be
browsed or run in the playground.
The grammar has three notable design choices:
- Expressions use a natural, ambiguous form. Precedence and associativity select the intended tree without splitting expressions into a hierarchy of nonterminals. The disambiguation documentation explains the notation.
- Layout is the whitespace and comments that may occur between grammar
symbols. The rule
Layout = (WhiteSpace | Comment)* !>> WhiteSpace !>> Commentuses follow restrictions to prevent the repetition from stopping while more whitespace or another comment remains. This makes the choice between continuing and stopping decidable with one token of lookahead, soLayoutis LL(1). Layout appears between nearly every pair of symbols, making this optimization particularly important for performance. The documentation covers layout and the measured effect of the LL(1) optimization. - Contextual keywords such as
var,yield, and the module-system words are reserved only where the grammar expects them. The single-phase parsing documentation explains how token matching follows the grammar context.
The Rust sources under src/ are generated from java.iggy and
should not be edited directly. After changing the grammar, regenerate the
parser and rebuild it:
iguana generate --grammar java.iggy --output .
cargo build --releaseThe repository has golden-file tests for individual language features and corpus tests against OpenJDK, Spring, and Elasticsearch:
cargo run --release -- --dir tests --ext java --start CompilationUnit --check-sexpr
cargo run --release -- --corpus-testSee Developing grammars for the complete workflow.
Licensed under either of MIT or Apache-2.0 at your option.
Copyright (c) 2026 Ali Afroozeh.
Java is a registered trademark of Oracle and/or its affiliates. This project is not affiliated with or endorsed by Oracle.