# Grammar specification for Rust

**URL:** <https://internals.rust-lang.org/t/grammar-specification-for-rust/13364>\
**Category:** language design\
**Created:** [November 10, 2020, 3:50pm UTC](https://internals.rust-lang.org/t/grammar-specification-for-rust/13364 "2020-11-10T15:50:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Storyyeller](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/storyyeller/32/3248_2.png) [@Storyyeller](https://internals.rust-lang.org/u/Storyyeller)\
**Post date:** [November 10, 2020, 3:50pm UTC](https://internals.rust-lang.org/t/grammar-specification-for-rust/13364/1 "2020-11-10T15:50:18Z")

</div>

Would it be possible for Rust to adopt an official grammar specification? It seems like right now, the implementation is the specification, which means you have to dive through dozens of files and thousands of lines of code to figure out what the syntax actually is.

It appears that around a year and a half ago, [there was an effort to specify the Rust grammar](https://github.com/rust-lang/wg-grammar), but it sadly seems to be abandoned and incomplete.

---

<div class="post-metadata">

**Author:** ![skysch](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@skysch](https://internals.rust-lang.org/u/skysch)\
**Post date:** [November 10, 2020, 9:05pm UTC](https://internals.rust-lang.org/t/grammar-specification-for-rust/13364/2 "2020-11-10T21:05:05Z")

</div>

[This document](https://doc.rust-lang.org/reference/introduction.html) is pretty accurate in my experience. I've found it to be a usable base for implementing accurate syntax highlighting, anyway.

---

<div class="post-metadata">

**Author:** ![mjbshaw](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mjbshaw/32/5103_2.png) [@mjbshaw](https://internals.rust-lang.org/u/mjbshaw)\
**Post date:** [November 10, 2020, 9:21pm UTC](https://internals.rust-lang.org/t/grammar-specification-for-rust/13364/3 "2020-11-10T21:21:21Z")

</div>

The [ungrammar](https://rust-analyzer.github.io/blog/2020/10/24/introducing-ungrammar.html) that rust-analyzer uses can also be useful. It doesn't tell you how to parse the tokens, and it doesn't disambiguate anything, but it does a pretty good job at showing humans what the syntax of Rust looks like.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [February 8, 2021, 9:21pm UTC](https://internals.rust-lang.org/t/grammar-specification-for-rust/13364/4 "2021-02-08T21:21:27Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
