Skip to content

Corrected EBNF grammar in the manual #14277

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

Merged
merged 1 commit into from
May 20, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,11 @@ extern crate foo = "some/where/rust-foo#foo:1.0"; // a full crate ID for externa
##### Use declarations

~~~~ {.notrust .ebnf .gram}
use_decl : "pub" ? "use" ident [ '=' path
| "::" path_glob ] ;
use_decl : "pub" ? "use" [ ident '=' path
| path_glob ] ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um… what? These changes would make use; valid, which it is certainly not. A use statement must be followed by an identifier.

The grammar already existing appears to me to be correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take back what I said about the grammar existing being correct—I’ve been reading other grammar rules too much recently (the IETF RFC ones in particular) and was thinking […] meant optional. There is a problem with the current grammar, but the new one is wrong also. I think that just tacking a question mark after the ] on the existing grammar would be correct? OK, OK, that responsibility got shifted to the path_glob rule… not doing well today, am I?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My line of thought is that a single identifier is also a path. path_glob can match multiple paths.

// Valid declarations
use ident = simple::path;
use simple::path;
use {many, idents}; // doesn't start with an ident!
// Invalid
use simple::path = another::path;
use *;
use;


path_glob : ident [ "::" path_glob ] ?
| '*'
path_glob : ident [ "::" [ path_glob
| '*' ] ] ?
| '{' ident [ ',' ident ] * '}' ;
~~~~

Expand Down Expand Up @@ -1743,7 +1743,7 @@ import public items from their destination, not private items.
attribute : '#' '!' ? '[' meta_item ']' ;
meta_item : ident [ '=' literal
| '(' meta_seq ')' ] ? ;
meta_seq : meta_item [ ',' meta_seq ]* ;
meta_seq : meta_item [ ',' meta_seq ] ? ;
~~~~

Static entities in Rust — crates, modules and items — may have _attributes_
Expand Down Expand Up @@ -3027,11 +3027,11 @@ then any `else` block is executed.
### Match expressions

~~~~ {.notrust .ebnf .gram}
match_expr : "match" expr '{' match_arm [ '|' match_arm ] * '}' ;
match_expr : "match" expr '{' match_arm * '}' ;

match_arm : match_pat "=>" [ expr "," | '{' block '}' ] ;
match_arm : attribute * match_pat "=>" [ expr "," | '{' block '}' ] ;

match_pat : pat [ ".." pat ] ? [ "if" expr ] ;
match_pat : pat [ '|' pat ] * [ "if" expr ] ? ;
~~~~

A `match` expression branches on a *pattern*. The exact form of matching that
Expand Down Expand Up @@ -3137,7 +3137,7 @@ using the `ref` keyword,
or to a mutable reference using `ref mut`.

Subpatterns can also be bound to variables by the use of the syntax
`variable @ pattern`.
`variable @ subpattern`.
For example:

~~~~
Expand Down