Skip to content

jorendorff/rust-grammar

Repository files navigation

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.

About

An ANTLR4 grammar for Rust.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published