Skip to content

Commit 2568a4d

Browse files
committed
Auto merge of #24924 - carols10cents:grammar-improvements, r=pnkfelix
I'm interested in helping out with #16676 but more in the grammar than the reference-- here's my first chunk, more to come!! 🎉 I did pull a bit *out* of the reference, though, that was more relevant to the grammar but wasn't moved over as part of #24729. I'm looking at, e.g. https://github.com/rust-lang/rust/blob/master/src/libsyntax/ast.rs, as the source of truth, please let me know if I should be checking against something else instead/in addition. r? @steveklabnik
2 parents 2f613bf + 0ddee94 commit 2568a4d

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/doc/grammar.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,15 @@ excluded from the `ident` rule.
176176

177177
```antlr
178178
lit_suffix : ident;
179-
literal : [ string_lit | char_lit | byte_string_lit | byte_lit | num_lit ] lit_suffix ?;
179+
literal : [ string_lit | char_lit | byte_string_lit | byte_lit | num_lit | bool_lit ] lit_suffix ?;
180180
```
181181

182+
The optional `lit_suffix` production is only used for certain numeric literals,
183+
but is reserved for future extension. That is, the above gives the lexical
184+
grammar, but a Rust parser will reject everything but the 12 special cases
185+
mentioned in [Number literals](reference.html#number-literals) in the
186+
reference.
187+
182188
#### Character and string literals
183189

184190
```antlr
@@ -238,7 +244,9 @@ dec_lit : [ dec_digit | '_' ] + ;
238244

239245
#### Boolean literals
240246

241-
**FIXME:** write grammar
247+
```antlr
248+
bool_lit : [ "true" | "false" ] ;
249+
```
242250

243251
The two values of the boolean type are written `true` and `false`.
244252

@@ -297,7 +305,7 @@ transcriber : '(' transcriber * ')' | '[' transcriber * ']'
297305

298306
```antlr
299307
item : mod_item | fn_item | type_item | struct_item | enum_item
300-
| static_item | trait_item | impl_item | extern_block ;
308+
| const_item | static_item | trait_item | impl_item | extern_block ;
301309
```
302310

303311
### Type Parameters
@@ -369,6 +377,10 @@ path_item : ident | "mod" ;
369377

370378
**FIXME:** grammar?
371379

380+
### Enumerations
381+
382+
**FIXME:** grammar?
383+
372384
### Constant items
373385

374386
```antlr

src/doc/reference.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ of tokens, that immediately and directly denotes the value it evaluates to,
130130
rather than referring to it by name or some other evaluation rule. A literal is
131131
a form of constant expression, so is evaluated (primarily) at compile time.
132132

133-
The optional suffix is only used for certain numeric literals, but is
134-
reserved for future extension, that is, the above gives the lexical
135-
grammar, but a Rust parser will reject everything but the 12 special
136-
cases mentioned in [Number literals](#number-literals) below.
137-
138133
#### Examples
139134

140135
##### Characters and strings

0 commit comments

Comments
 (0)