11# A. Appendix: Notation Conventions
22
3- This specification uses a number of notation conventions to describe the language
4- grammar. This appendix explains those notations to avoid ambiguity.
3+ This specification uses a number of notation conventions to describe the
4+ language grammar. This appendix explains those notations so as to avoid
5+ ambiguity, and is itself non-normative: it describes how to read the
6+ productions found elsewhere in this document, but introduces no new
7+ requirement of its own.
58
69## Context-Free Grammar
710
8- A context-free grammar consists of a number of _ productions_ . Each production has
9- an abstract symbol called a _ non-terminal_ as its left-hand side, and one or more
10- sequences of non-terminal symbols and terminal characters as its right-hand side.
11+ A context-free grammar consists of a number of _ productions_ . Each production
12+ has an abstract symbol, called a _ non-terminal_ , as its left-hand side, and
13+ one or more sequences of non-terminal symbols and terminal characters as its
14+ right-hand side.
1115
12- Starting from a single goal non-terminal ({Type} for TypeLang), the grammar
16+ Starting from a single goal non-terminal ({Type}, for TypeLang), the grammar
1317describes a language: the set of character sequences obtained by repeatedly
14- replacing a non-terminal with one of its right-hand sides until only terminals
15- remain.
18+ replacing a non-terminal with one of its right-hand sides until only
19+ terminals remain.
1620
1721Terminals are written in a monospace font, either as a specific character or
18- sequence (for example {` | ` } or {` is ` }), or as prose describing a code point (for
19- example {"New Line (U+000A)"}).
22+ sequence (for example {` | ` } or {` is ` }), or as prose describing a code point
23+ (for example {"New Line (U+000A)"}).
2024
2125A production with a single definition is written on one line:
2226
@@ -38,17 +42,19 @@ ListOfLetterA :
3842
3943## Lexical and Syntactic Grammar
4044
41- TypeLang is defined by two grammars. The _ lexical grammar_ matches patterns of
42- source characters into _ tokens_ ; the _ syntactic grammar_ matches patterns of
43- tokens into the abstract syntax tree.
45+ TypeLang is defined by two grammars. The _ lexical grammar_ matches patterns
46+ of source characters into _ tokens_ ; the _ syntactic grammar_ matches patterns
47+ of tokens into the abstract syntax tree.
4448
45- A lexical grammar production is distinguished by a double colon ` :: ` . No {Ignored}
46- characters may appear between the terminals of a lexical production.
49+ A lexical grammar production is distinguished by a double colon ` :: ` . No
50+ {Ignored} characters may appear between the terminals of a lexical
51+ production.
4752
4853Word :: Letter+
4954
50- A syntactic grammar production is distinguished by a single colon ` : ` . {Ignored}
51- tokens may appear before or after any terminal token of a syntactic production.
55+ A syntactic grammar production is distinguished by a single colon ` : ` .
56+ {Ignored} tokens may appear before or after any terminal token of a syntactic
57+ production.
5258
5359Phrase : Word+
5460
@@ -67,8 +73,8 @@ Operator :
6773- ` & `
6874- ` ? `
6975
70- ** Optionality.** A subscript-style suffix ` ? ` denotes an optional symbol — one
71- sequence including it and one excluding it.
76+ ** Optionality.** A subscript-style suffix ` ? ` denotes an optional symbol: one
77+ sequence including it, and one excluding it.
7278
7379Nullable : ` ? ` ? Type
7480
@@ -79,39 +85,56 @@ Nullable :
7985- ` ? ` Type
8086- Type
8187
82- ** Lists.** A suffix ` * ` denotes zero or more repetitions of a symbol; a suffix ` + `
83- denotes one or more. For example {Identifier+} matches a non-empty run of
84- {Identifier}.
88+ ** Lists.** A suffix ` * ` denotes zero or more repetitions of a symbol; a
89+ suffix ` + ` denotes one or more. For example, {Identifier+} matches a
90+ non-empty run of {Identifier}.
8591
86- ** Constraints (but not).** The phrase "but not" excludes certain expansions that
87- would otherwise be permitted.
92+ ** Constraints (but not).** The phrase "but not" excludes certain expansions
93+ that would otherwise be permitted.
8894
8995NonReserved : Name but not ` true ` or ` false ` or ` null `
9096
91- means a {NonReserved} may be any {Name} except those three sequences.
97+ means that a {NonReserved} may be any {Name} except those three sequences.
9298
93- ** Lookahead Restrictions.** A restriction of the form ` [lookahead != X] ` states
94- that the production must not be followed by ` X ` . Lookahead restrictions remove
95- ambiguity and, together with longest-match scanning, ensure a single valid lexical
96- analysis. For example:
99+ ** Lookahead Restrictions.** A restriction of the form ` [lookahead != X] `
100+ states that the production must not be followed by ` X ` . Lookahead
101+ restrictions remove ambiguity and, together with longest-match scanning,
102+ ensure a single valid lexical analysis. For example:
97103
98- Name :: NameStart NameContinue\* [ lookahead != NameContinue]
104+ NameToken :: NameStart NameContinue\* [ lookahead != NameContinue]
99105
100- makes explicit that a {Name} is always the longest possible sequence and cannot be
101- followed by another {NameContinue} character.
106+ makes explicit that a {NameToken} is always the longest possible sequence,
107+ and cannot be followed by another {NameContinue} character.
108+
109+ ** Ordered Choice.** Unless a production states otherwise, its alternatives
110+ are attempted in the order in which they are written, and the first
111+ alternative that matches at the current position is selected; a later
112+ alternative is attempted only once every earlier alternative has failed to
113+ match. This discipline applies uniformly to every alternation in both the
114+ lexical and the syntactic grammar and, in particular, is what allows this
115+ specification to describe an unambiguous grammar despite alternatives whose
116+ languages overlap — for example, the five alternatives of
117+ [ PrimaryType] ( #sec-Primary-Types ) , or the five alternatives of
118+ [ ShapeKey] ( #sec-Shape-Fields ) . This is analogous to the ordered choice of a
119+ parsing expression grammar, and is a stronger guarantee than the mere absence
120+ of ambiguity provided by a classical context-free grammar.
102121
103122## Grammar Semantics
104123
105124Some productions are accompanied by a ** Static Semantics** description, which
106- explains how a conforming parser should interpret the matched source beyond merely
107- accepting it — for example, how the radix of an integer literal is determined, or
108- how out-of-range values are clamped. Static semantics never alter which documents
109- are accepted; they only describe the value or node that a valid document denotes.
125+ explains how a conforming implementation is to interpret the matched source
126+ beyond merely accepting it — for example, how the radix of an integer
127+ literal is determined, or how an out-of-range value is clamped. Static
128+ semantics never alter which documents are accepted; they only describe the
129+ value or node that a valid document denotes.
110130
111131## Examples and Counter-Examples
112132
113- Code blocks in this document illustrate the grammar. A block presented without
114- qualification denotes a ** valid** document. A block explicitly introduced as a
115- _ counter-example_ denotes an ** invalid** document, and is followed by the kind of
116- error a conforming parser is expected to raise. Error messages are illustrative;
117- the exact wording is not normative.
133+ Code blocks in this document illustrate the grammar. A block presented
134+ without qualification denotes a ** valid** document. A block explicitly
135+ introduced as a _ counter-example_ denotes an ** invalid** document, and is
136+ typically followed by the kind of error a conforming implementation is
137+ expected to raise. Such error messages are illustrative and non-normative;
138+ their exact wording is not prescribed by this specification, and an
139+ implementation MAY report a different message, provided that it rejects the
140+ document (see [ Conformance] ( #sec-Conformance ) ).
0 commit comments