-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do we have a central document with the Rust grammar? #19278
Comments
There isn't. One would be lovely. This is a superset of #9022, really. |
There's a lexical grammar in https://github.com/rust-lang/rust/tree/master/src/grammar . It's not currently guaranteed to be up-to-date. |
@steveklabnik should we start an effort to get a document going with all the grammar? |
Please. |
@steveklabnik, @huonw Ok, how do we go about this? For example: 4.1 Macros (more details)expr_macro_rules : "macro_rules" '!' ident '(' macro_rule * ')' ;
macro_rule : '(' matcher * ')' "=>" '(' transcriber * ')' ';' ;
matcher : '(' matcher * ')' | '[' matcher * ']'
| '{' matcher * '}' | '$' ident ':' ident
| '$' '(' matcher * ')' sep_token? [ '*' | '+' ]
| non_special_token ;
transcriber : '(' transcriber * ')' | '[' transcriber * ']'
| '{' transcriber * '}' | '$' ident
| '$' '(' transcriber * ')' sep_token? [ '*' | '+' ]
| non_special_token ; What do you think? |
Ideally, go through the code and figure it out. 😅 It's possible reference.md has diverged. The full grammar should be part of the reference. |
Yea, We can figure out later how to have the Sounds good? |
@huonw @steveklabnik I have this grammar.md going on my fork. I left the intro as it was given that is talks about the grammar... perhaps it's not necessary to keep in that document. If someone is looking at a grammar for a language you could assume they understand how to read the productions. The relevant pieces start here. I cleaned up to "CHECKPOINT". There are a lot of features with no grammar definition (to mention a few: type, trait, struct, enum, fn... are all missing). If you guys think this is worth having, I'll continue cleaning it up, leaving only the existing grammar bits from the reference.md. But that is just the beginning, then comes the task to fill in all the blanks. |
Nice! This is looking awesome. I just skimmed it, but it's certainly in the right direction. |
Pinging @marijnh from CodeMirror to keep him up to date on this effort. |
Ok, here is the new grammar.md file with everything that was available at the reference.md. Who from rust side can help fill in the blanks? I can certainly do a first pass based on examples, but I'm not familiar with everything that might be possible. |
If you're uncertain. You can still start a WIP PR for review and iteration. |
Original [issue](#19278) that inspired this patch. The [reference.md] has evolved past simple grammatical constructs, and it serves a different purpose. The intent for the proposed _grammar.md_ is to hold **only** the official reference for the language grammar. This document would keep track of grammatical changes to the language over time, facilitate discussions over proposed changes to the existing grammar, and serve as basis for building parsers by third-parties (IDE's, GitHub linguist, CodeMirror, etc.). The current state of the PR contains all the grammars that were available in [reference.md] and nothing else. There are still a lot of missing pieces that weren't available. The following are just a few of the definitions missing: - [Functions](https://github.com/icorderi/rust/blob/docs/grammar/src/doc/grammar.md#functions) - [Structures](https://github.com/icorderi/rust/blob/docs/grammar/src/doc/grammar.md#structures) - [Traits](https://github.com/icorderi/rust/blob/docs/grammar/src/doc/grammar.md#traits) - [Implementations](https://github.com/icorderi/rust/blob/docs/grammar/src/doc/grammar.md#implementations) - [Operators](https://github.com/icorderi/rust/blob/docs/grammar/src/doc/grammar.md#unary-operator-expressions) - [Statements](https://github.com/icorderi/rust/blob/docs/grammar/src/doc/grammar.md#statements) - [Expressions](https://github.com/icorderi/rust/blob/docs/grammar/src/doc/grammar.md#expressions) [reference.md]: https://github.com/rust-lang/rust/blob/master/src/doc/reference.md We need help from people familiar with those grammatical constructs to fill in the missing pieces.
The makefiles may still need to be updated to render the docs, and a link placed somewhere. |
Assuming that http://doc.rust-lang.org/grammar.html reflects the current state of the grammar, there's still a lot of FIXMEs and missing rules. Is there an issue tracking the completion of an actual full grammar? |
@marijnh I agree that having an issue for the full grammar is important, so I filed #22445. (I chose spawning a new issue over reopening this ticket, because I think the most interesting part of this ticket was choosing an tool for documenting the grammar and incorporating an invocation of that tool into our build process, yay!) |
Hey guys, we are trying to revamp the CodeMirror definition for Rust given that it is a bit out of date and doesn't parse Rust code correctly anymore. Here is the issue on CodeMirror.
Do we have a document outlining the Rust language grammar? I've seen bits and pieces all over the reference document.
Who in the Rust community can help with this?
The text was updated successfully, but these errors were encountered: