Skip to content
An ANTLR4 grammar for Rust.
ANTLR Java Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE-APACHE
LICENSE-MIT
ParserDriver.java
README.md
Rust.g4
build.sh
setup.sh
xidcontinue.g4
xidstart.g4

README.md

An incomplete ANTLR4 grammar for Rust

The file Rust.g4 in this repository is an ANTLR4 grammar for the Rust programming language.

Note that the Rust repository contains an independent mostly-complete Yacc grammar: src/grammar/parser-lalr.y.

I wrote this grammar while I was working on Programming Rust, to help make sure I understood the syntax. Accordingly it has these limitations:

  • It's incomplete; many post-1.0 Rust features are missing.

  • It may be too permissive (“successfully” parsing text that isn’t valid Rust code), since I never did any negative testing.

  • The grammar may be ambiguous, because ANTLR4 makes no effort to reject ambiguous or buggy grammars.

  • It accepts some weird features that were experimental at the time, and were never officially part of the language. (My goal, never quite reached, was for it to parse every Rust file in the @rust-lang/rust repository, including tests for experimental features.)

License

Like Rust itself, this grammar is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

You can’t perform that action at this time.