|
| 1 | +- Feature Name: grammar |
| 2 | +- Start Date: 2015-10-21 |
| 3 | +- RFC PR: (leave this empty) |
| 4 | +- Rust Issue: (leave this empty) |
| 5 | + |
| 6 | +# Summary |
| 7 | +[summary]: #summary |
| 8 | +[src/grammar]: https://github.com/rust-lang/rust/tree/master/src/grammar |
| 9 | + |
| 10 | +Grammar of the Rust language should not be rustc implementation-defined. We have a formal grammar |
| 11 | +at [src/grammar] which is to be used as the canonical and formal representation of the Rust |
| 12 | +language. |
| 13 | + |
| 14 | +# Motivation |
| 15 | +[motivation]: #motivation |
| 16 | +[#1228]: https://github.com/rust-lang/rfcs/blob/master/text/1228-placement-left-arrow.md |
| 17 | +[#1219]: https://github.com/rust-lang/rfcs/blob/master/text/1219-use-group-as.md |
| 18 | +[#1192]: https://github.com/rust-lang/rfcs/blob/master/text/1192-inclusive-ranges.md |
| 19 | + |
| 20 | +In many RFCs proposing syntactic changes ([#1228], [#1219] and [#1192] being some of more recently |
| 21 | +merged RFCs) the changes are described rather informally, discussions contain a lot of guess-work |
| 22 | +and are hard to work with in general, both when implementing and discussing them. |
| 23 | + |
| 24 | +Making [src/grammar] to be the canonical grammar and demanding for description of syntactic changes |
| 25 | +to be presented in terms of changes to the formal grammar should greatly simplify both the |
| 26 | +discussion and implementation of the RFCs. Using a formal grammar also allows us to discover and |
| 27 | +rule out existence of various issues with the grammar changes (e.g. grammar ambiguities) during |
| 28 | +design phase rather than implementation phase or, even worse, after the stabilisation. |
| 29 | + |
| 30 | +# Detailed design |
| 31 | +[design]: #detailed-design |
| 32 | +[A-grammar]: https://github.com/rust-lang/rust/issues?utf8=✓&q=is:issue+is:open+label:A-grammar |
| 33 | + |
| 34 | +Sadly, the [grammar][src/grammar] in question is [not quite equivalent][A-grammar] to the |
| 35 | +implementation in rustc yet. We cannot possibly hope to catch all the quirks in the rustc parser |
| 36 | +implementation, therefore something else needs to be done. |
| 37 | + |
| 38 | +This RFC proposes following approach to making [src/grammar] the canonical Rust language grammar: |
| 39 | + |
| 40 | +1. Fix the already known discrepancies between implementation and [src/grammar]; |
| 41 | +2. Make [src/grammar] a [semi-canonical grammar]; |
| 42 | +3. After a period of time transition [src/grammar] to a [fully-canonical grammar]. |
| 43 | + |
| 44 | +## Semi-canonical grammar |
| 45 | +[semi-canonical grammar]: #semi-canonical-grammar |
| 46 | + |
| 47 | +Once all known discrepancies between the [src/grammar] and rustc parser implementation are |
| 48 | +resolved, [src/grammar] enters the state of being semi-canonical grammar of the Rust language. |
| 49 | + |
| 50 | +Semi-canonical means that all new development involving syntax changes are made and discussed in |
| 51 | +terms of changes to the [src/grammar] and [src/grammar] is in general regarded to as the canonical |
| 52 | +grammar except when new discrepancies are discovered. These discrepancies must be swiftly resolved, |
| 53 | +but resolution will depend on what kind of discrepancy it is: |
| 54 | + |
| 55 | +1. For syntax changes/additions introduced after [src/grammar] gained the semi-canonical state, the |
| 56 | + [src/grammar] is canonical; |
| 57 | +2. For syntax that was present before [src/grammar] gained the semi-canonical state, in most cases |
| 58 | + the implementation is canonical. |
| 59 | + |
| 60 | +This process is sure to become ambiguous over time as syntax is increasingly adjusted (it is harder |
| 61 | +to “blame” syntax changes compared to syntax additions), therefore the resolution process of |
| 62 | +discrepancies will also depend more on a decision from the Rust team. |
| 63 | + |
| 64 | +## Fully-canonical grammar |
| 65 | +[fully-canonical grammar]: #fully-canonical-grammar |
| 66 | + |
| 67 | +After some time passes, [src/grammar] will transition to the state of fully canonical grammar. |
| 68 | +After [src/grammar] transitions into this state, for any discovered discrepancies the |
| 69 | +rustc parser implementation must be adjusted to match the [src/grammar], unless decided otherwise |
| 70 | +by the RFC process. |
| 71 | + |
| 72 | +## RFC process changes for syntactic changes and additions |
| 73 | + |
| 74 | +Once the [src/grammar] enters semi-canonical state, all RFCs must describe syntax additions and |
| 75 | +changes in terms of the formal [src/grammar]. Discussion about these changes are also expected (but |
| 76 | +not necessarily will) to become more formal and easier to follow. |
| 77 | + |
| 78 | +# Drawbacks |
| 79 | +[drawbacks]: #drawbacks |
| 80 | + |
| 81 | +This RFC introduces a period of ambiguity during which neither implementation nor [src/grammar] are |
| 82 | +truly canonical representation of the Rust language. This will be less of an issue over time as |
| 83 | +discrepancies are resolved, but its an issue nevertheless. |
| 84 | + |
| 85 | +# Alternatives |
| 86 | +[alternatives]: #alternatives |
| 87 | + |
| 88 | +One alternative would be to immediately make [src/grammar] a fully-canonical grammar of the Rust |
| 89 | +language at some arbitrary point in the future. |
| 90 | + |
| 91 | +Another alternative is to simply forget idea of having a formal grammar be the canonical grammar of |
| 92 | +the Rust language. |
| 93 | + |
| 94 | +# Unresolved questions |
| 95 | +[unresolved]: #unresolved-questions |
| 96 | + |
| 97 | +How much time should pass between [src/grammar] becoming semi-canonical and fully-canonical? |
0 commit comments