Skip to content

Commit 4c3855e

Browse files
committed
Remove parsing order notes (The PEG/LALR/LL(k)/etc algorithm should be chosen at the discretion of the implementation)
1 parent b4ddfa2 commit 4c3855e

4 files changed

Lines changed: 35 additions & 27 deletions

File tree

Specification/Appendix A -- Notation Conventions.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,22 @@ NameToken :: NameStart NameContinue\* [lookahead != NameContinue]
106106
makes explicit that a {NameToken} is always the longest possible sequence,
107107
and cannot be followed by another {NameContinue} character.
108108

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.
109+
**Overlapping Alternatives.** The order in which a production's alternatives
110+
are written carries no meaning by itself. Some alternatives, however, cannot
111+
be told apart by their first symbol alone — for example, {ClassConstant},
112+
{ConstantMask}, {CallableType} and {NamedType} (see
113+
[Primary Types](#sec-Primary-Types)) all begin with a {Name}. In every such
114+
case, this specification identifies, either through an explicit lookahead
115+
restriction or through an accompanying Note, the further input that
116+
determines which alternative applies at that position — typically the single
117+
token that follows a fully recognized {Name} or {Identifier}. The grammar
118+
described by this specification is unambiguous in the sense that, once that
119+
further input is consulted, at most one alternative can match at any
120+
position. This specification prescribes neither a parsing algorithm nor an
121+
implementation strategy; it is satisfied by any implementation — whether
122+
based on recursive descent, an LL(_k_) or LALR parser generator, a parsing
123+
expression grammar, or any other technique — that accepts exactly the
124+
documents, and performs exactly the disambiguation, described herein.
121125

122126
## Grammar Semantics
123127

Specification/Section 3 -- Types.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,7 @@ PrimaryType :
249249

250250
A _primary type_ is the tightest-binding form. It is one of: a parenthesized
251251
{Type}, the `$this` type, a literal type, a callable type (see
252-
[Callable Types](#sec-Callable-Types)), or a named type. Per the ordered-choice
253-
discipline that governs every alternation in this grammar (see
254-
[Grammar Notation](#sec-Grammar-Notation)), these five alternatives are
255-
attempted in the order listed, and the first that matches at the current
256-
position is selected.
252+
[Callable Types](#sec-Callable-Types)), or a named type.
257253

258254
A parenthesized type is used to override precedence; it denotes exactly the
259255
type it encloses:
@@ -270,14 +266,14 @@ $this
270266
```
271267

272268
Note: Each of {CallableType}, {NamedType}, and the {ClassConstant} and
273-
{ConstantMask} forms of {LiteralType} begins with a {Name}. Because a
274-
{LiteralType} is attempted before a {CallableType} or a {NamedType} (see
275-
above), these are distinguished, in effect, by the token that follows the
276-
name: `*` selects a [constant mask](#sec-Constant-Masks); `::` selects a
269+
{ConstantMask} forms of {LiteralType} begins with a {Name}. Once a complete
270+
{Name} has been recognized, these four are distinguished by the single token
271+
that immediately follows it: `*` selects a
272+
[constant mask](#sec-Constant-Masks); `::` selects a
277273
[class constant](#sec-Class-Constants); `(` selects a
278274
[callable type](#sec-Callable-Types); `<` or `{` selects a
279275
[generic or shape](#sec-Generic-Types) named type; any other following token
280-
leaves a plain named type.
276+
(or the end of the document) leaves a plain named type.
281277

282278
## Names and Namespaces
283279

Specification/Section 4 -- Structural Types.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ key may be a bare identifier, an integer literal, a string literal, or a
6767
[constant](#sec-Constant-Types) reference — that is, a {ClassConstant} or a
6868
{ConstantMask}.
6969

70+
Note: An {Identifier}, a {ClassConstant} and a {ConstantMask} may each begin
71+
with the same {Name}. As in [Primary Types](#sec-Primary-Types), these are
72+
distinguished by what follows: a bare {Identifier} key is one not followed by
73+
`::` or a trailing `*`.
74+
7075
```typescript
7176
array{ name: First, count: Second }
7277
```

Writerside/cfg/static/spec.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -804,16 +804,16 @@ <h2><span class="spec-secid" title="link to this section"><a href="#sec-Primary-
804804
<div class="spec-rhs"><span class="spec-nt"><a href="#CallableType" data-name="CallableType">CallableType</a></span></div>
805805
<div class="spec-rhs"><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div>
806806
</div>
807-
<p>A <em>primary type</em> is the tightest-binding form. It is one of: a parenthesized <span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span>, the <code>$this</code> type, a literal type, a callable type (see <a href="#sec-Callable-Types">Callable Types</a>), or a named type. Per the ordered-choice discipline that governs every alternation in this grammar (see <a href="#sec-Grammar-Notation">Grammar Notation</a>), these five alternatives are attempted in the order listed, and the first that matches at the current position is selected.</p>
807+
<p>A <em>primary type</em> is the tightest-binding form. It is one of: a parenthesized <span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span>, the <code>$this</code> type, a literal type, a callable type (see <a href="#sec-Callable-Types">Callable Types</a>), or a named type.</p>
808808
<p>A parenthesized type is used to override precedence; it denotes exactly the type it encloses:</p>
809809
<pre data-language="typescript"><code><span class="token punctuation">(</span><span class="token constant">A</span> <span class="token operator">|</span> <span class="token constant">B</span><span class="token punctuation">)</span> <span class="token operator">&amp;</span> <span class="token constant">C</span>
810810
</code></pre>
811811
<p>The <code>$this</code> variable, when used as a primary type, denotes the current object type:</p>
812812
<pre data-language="typescript"><code>$<span class="token keyword">this</span>
813813
</code></pre>
814-
<div id="note-eaf47" class="spec-note">
815-
<a href="#note-eaf47">Note</a>
816-
Each of <span class="spec-nt"><a href="#CallableType" data-name="CallableType">CallableType</a></span>, <span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span>, and the <span class="spec-nt"><a href="#ClassConstant" data-name="ClassConstant">ClassConstant</a></span> and <span class="spec-nt"><a href="#ConstantMask" data-name="ConstantMask">ConstantMask</a></span> forms of <span class="spec-nt"><a href="#LiteralType" data-name="LiteralType">LiteralType</a></span> begins with a <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span>. Because a <span class="spec-nt"><a href="#LiteralType" data-name="LiteralType">LiteralType</a></span> is attempted before a <span class="spec-nt"><a href="#CallableType" data-name="CallableType">CallableType</a></span> or a <span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span> (see above), these are distinguished, in effect, by the token that follows the name: <code>*</code> selects a <a href="#sec-Constant-Masks">constant mask</a>; <code>::</code> selects a <a href="#sec-Class-Constants">class constant</a>; <code>(</code> selects a <a href="#sec-Callable-Types">callable type</a>; <code>&lt;</code> or <code>{</code> selects a <a href="#sec-Generic-Types">generic or shape</a> named type; any other following token leaves a plain named type.</div>
814+
<div id="note-678fe" class="spec-note">
815+
<a href="#note-678fe">Note</a>
816+
Each of <span class="spec-nt"><a href="#CallableType" data-name="CallableType">CallableType</a></span>, <span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span>, and the <span class="spec-nt"><a href="#ClassConstant" data-name="ClassConstant">ClassConstant</a></span> and <span class="spec-nt"><a href="#ConstantMask" data-name="ConstantMask">ConstantMask</a></span> forms of <span class="spec-nt"><a href="#LiteralType" data-name="LiteralType">LiteralType</a></span> begins with a <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span>. Once a complete <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span> has been recognized, these four are distinguished by the single token that immediately follows it: <code>*</code> selects a <a href="#sec-Constant-Masks">constant mask</a>; <code>::</code> selects a <a href="#sec-Class-Constants">class constant</a>; <code>(</code> selects a <a href="#sec-Callable-Types">callable type</a>; <code>&lt;</code> or <code>{</code> selects a <a href="#sec-Generic-Types">generic or shape</a> named type; any other following token (or the end of the document) leaves a plain named type.</div>
817817
</section>
818818
<section id="sec-Names-and-Namespaces" secid="5.6">
819819
<h2><span class="spec-secid" title="link to this section"><a href="#sec-Names-and-Namespaces">5.6</a></span>Names and Namespaces</h2>
@@ -1039,6 +1039,9 @@ <h3><span class="spec-secid" title="link to this section"><a href="#sec-Shape-Fi
10391039
<span class="spec-nt"><a href="#ShapeValue" data-name="ShapeValue">ShapeValue</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span></div>
10401040
</div>
10411041
<p>A shape field is either <em>explicit</em> (a key, a colon, and a value type) or <em>implicit</em> (a value type alone, whose key is assigned positionally). A shape key may be a bare identifier, an integer literal, a string literal, or a <a href="#sec-Constant-Types">constant</a> reference &mdash; that is, a <span class="spec-nt"><a href="#ClassConstant" data-name="ClassConstant">ClassConstant</a></span> or a <span class="spec-nt"><a href="#ConstantMask" data-name="ConstantMask">ConstantMask</a></span>.</p>
1042+
<div id="note-23a95" class="spec-note">
1043+
<a href="#note-23a95">Note</a>
1044+
An <span class="spec-nt"><a href="#Identifier" data-name="Identifier">Identifier</a></span>, a <span class="spec-nt"><a href="#ClassConstant" data-name="ClassConstant">ClassConstant</a></span> and a <span class="spec-nt"><a href="#ConstantMask" data-name="ConstantMask">ConstantMask</a></span> may each begin with the same <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span>. As in <a href="#sec-Primary-Types">Primary Types</a>, these are distinguished by what follows: a bare <span class="spec-nt"><a href="#Identifier" data-name="Identifier">Identifier</a></span> key is one not followed by <code>::</code> or a trailing <code>*</code>.</div>
10421045
<pre data-language="typescript"><code>array<span class="token punctuation">{</span> name<span class="token operator">:</span> First<span class="token punctuation">,</span> count<span class="token operator">:</span> Second <span class="token punctuation">}</span>
10431046
</code></pre>
10441047
<pre data-language="typescript"><code>array<span class="token punctuation">{</span> <span class="token number">1</span><span class="token operator">:</span> First<span class="token punctuation">,</span> <span class="token number">42</span><span class="token operator">:</span> Second <span class="token punctuation">}</span>
@@ -1292,7 +1295,7 @@ <h2><span class="spec-secid" title="link to this section"><a href="#sec-Grammar-
12921295
<span class="spec-nt"><a href="#NameToken" data-name="NameToken">NameToken</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead ntset not"><span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span></span></div>
12931296
</div>
12941297
<p>makes explicit that a <span class="spec-nt"><a href="#NameToken" data-name="NameToken">NameToken</a></span> is always the longest possible sequence, and cannot be followed by another <span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span> character.</p>
1295-
<p><strong>Ordered Choice.</strong> Unless a production states otherwise, its alternatives are attempted in the order in which they are written, and the first alternative that matches at the current position is selected; a later alternative is attempted only once every earlier alternative has failed to match. This discipline applies uniformly to every alternation in both the lexical and the syntactic grammar and, in particular, is what allows this specification to describe an unambiguous grammar despite alternatives whose languages overlap &mdash; for example, the five alternatives of <a href="#sec-Primary-Types">PrimaryType</a>, or the five alternatives of <a href="#sec-Shape-Fields">ShapeKey</a>. This is analogous to the ordered choice of a parsing expression grammar, and is a stronger guarantee than the mere absence of ambiguity provided by a classical context-free grammar.</p>
1298+
<p><strong>Overlapping Alternatives.</strong> The order in which a production&rsquo;s alternatives are written carries no meaning by itself. Some alternatives, however, cannot be told apart by their first symbol alone &mdash; for example, <span class="spec-nt"><a href="#ClassConstant" data-name="ClassConstant">ClassConstant</a></span>, <span class="spec-nt"><a href="#ConstantMask" data-name="ConstantMask">ConstantMask</a></span>, <span class="spec-nt"><a href="#CallableType" data-name="CallableType">CallableType</a></span> and <span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span> (see <a href="#sec-Primary-Types">Primary Types</a>) all begin with a <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span>. In every such case, this specification identifies, either through an explicit lookahead restriction or through an accompanying Note, the further input that determines which alternative applies at that position &mdash; typically the single token that follows a fully recognized <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span> or <span class="spec-nt"><a href="#Identifier" data-name="Identifier">Identifier</a></span>. The grammar described by this specification is unambiguous in the sense that, once that further input is consulted, at most one alternative can match at any position. This specification prescribes neither a parsing algorithm nor an implementation strategy; it is satisfied by any implementation &mdash; whether based on recursive descent, an LL(<em>k</em>) or LALR parser generator, a parsing expression grammar, or any other technique &mdash; that accepts exactly the documents, and performs exactly the disambiguation, described herein.</p>
12961299
</section>
12971300
<section id="sec-Grammar-Semantics" secid="A.4">
12981301
<h2><span class="spec-secid" title="link to this section"><a href="#sec-Grammar-Semantics">A.4</a></span>Grammar Semantics</h2>

0 commit comments

Comments
 (0)