You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>A <em>primary type</em> is the tightest-binding form. It is one of: a parenthesized <spanclass="spec-nt"><ahref="#Type" data-name="Type">Type</a></span>, the <code>$this</code> type, a literal type, a callable type (see <ahref="#sec-Callable-Types">Callable Types</a>), or a named type. Per the ordered-choice discipline that governs every alternation in this grammar (see <ahref="#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 <spanclass="spec-nt"><ahref="#Type" data-name="Type">Type</a></span>, the <code>$this</code> type, a literal type, a callable type (see <ahref="#sec-Callable-Types">Callable Types</a>), or a named type.</p>
808
808
<p>A parenthesized type is used to override precedence; it denotes exactly the type it encloses:</p>
Each of <spanclass="spec-nt"><ahref="#CallableType" data-name="CallableType">CallableType</a></span>, <spanclass="spec-nt"><ahref="#NamedType" data-name="NamedType">NamedType</a></span>, and the <spanclass="spec-nt"><ahref="#ClassConstant" data-name="ClassConstant">ClassConstant</a></span> and <spanclass="spec-nt"><ahref="#ConstantMask" data-name="ConstantMask">ConstantMask</a></span> forms of <spanclass="spec-nt"><ahref="#LiteralType" data-name="LiteralType">LiteralType</a></span> begins with a <spanclass="spec-nt"><ahref="#Name" data-name="Name">Name</a></span>. Because a <spanclass="spec-nt"><ahref="#LiteralType" data-name="LiteralType">LiteralType</a></span> is attempted before a <spanclass="spec-nt"><ahref="#CallableType" data-name="CallableType">CallableType</a></span> or a <spanclass="spec-nt"><ahref="#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 <ahref="#sec-Constant-Masks">constant mask</a>; <code>::</code> selects a <ahref="#sec-Class-Constants">class constant</a>; <code>(</code> selects a <ahref="#sec-Callable-Types">callable type</a>; <code><</code> or <code>{</code> selects a <ahref="#sec-Generic-Types">generic or shape</a> named type; any other following token leaves a plain named type.</div>
814
+
<divid="note-678fe" class="spec-note">
815
+
<ahref="#note-678fe">Note</a>
816
+
Each of <spanclass="spec-nt"><ahref="#CallableType" data-name="CallableType">CallableType</a></span>, <spanclass="spec-nt"><ahref="#NamedType" data-name="NamedType">NamedType</a></span>, and the <spanclass="spec-nt"><ahref="#ClassConstant" data-name="ClassConstant">ClassConstant</a></span> and <spanclass="spec-nt"><ahref="#ConstantMask" data-name="ConstantMask">ConstantMask</a></span> forms of <spanclass="spec-nt"><ahref="#LiteralType" data-name="LiteralType">LiteralType</a></span> begins with a <spanclass="spec-nt"><ahref="#Name" data-name="Name">Name</a></span>. Once a complete <spanclass="spec-nt"><ahref="#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 <ahref="#sec-Constant-Masks">constant mask</a>; <code>::</code> selects a <ahref="#sec-Class-Constants">class constant</a>; <code>(</code> selects a <ahref="#sec-Callable-Types">callable type</a>; <code><</code> or <code>{</code> selects a <ahref="#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>
<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 <ahref="#sec-Constant-Types">constant</a> reference — that is, a <spanclass="spec-nt"><ahref="#ClassConstant" data-name="ClassConstant">ClassConstant</a></span> or a <spanclass="spec-nt"><ahref="#ConstantMask" data-name="ConstantMask">ConstantMask</a></span>.</p>
1042
+
<divid="note-23a95" class="spec-note">
1043
+
<ahref="#note-23a95">Note</a>
1044
+
An <spanclass="spec-nt"><ahref="#Identifier" data-name="Identifier">Identifier</a></span>, a <spanclass="spec-nt"><ahref="#ClassConstant" data-name="ClassConstant">ClassConstant</a></span> and a <spanclass="spec-nt"><ahref="#ConstantMask" data-name="ConstantMask">ConstantMask</a></span> may each begin with the same <spanclass="spec-nt"><ahref="#Name" data-name="Name">Name</a></span>. As in <ahref="#sec-Primary-Types">Primary Types</a>, these are distinguished by what follows: a bare <spanclass="spec-nt"><ahref="#Identifier" data-name="Identifier">Identifier</a></span> key is one not followed by <code>::</code> or a trailing <code>*</code>.</div>
<p>makes explicit that a <spanclass="spec-nt"><ahref="#NameToken" data-name="NameToken">NameToken</a></span> is always the longest possible sequence, and cannot be followed by another <spanclass="spec-nt"><ahref="#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 — for example, the five alternatives of <ahref="#sec-Primary-Types">PrimaryType</a>, or the five alternatives of <ahref="#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’s alternatives are written carries no meaning by itself. Some alternatives, however, cannot be told apart by their first symbol alone — for example, <spanclass="spec-nt"><ahref="#ClassConstant" data-name="ClassConstant">ClassConstant</a></span>, <spanclass="spec-nt"><ahref="#ConstantMask" data-name="ConstantMask">ConstantMask</a></span>, <spanclass="spec-nt"><ahref="#CallableType" data-name="CallableType">CallableType</a></span> and <spanclass="spec-nt"><ahref="#NamedType" data-name="NamedType">NamedType</a></span> (see <ahref="#sec-Primary-Types">Primary Types</a>) all begin with a <spanclass="spec-nt"><ahref="#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 — typically the single token that follows a fully recognized <spanclass="spec-nt"><ahref="#Name" data-name="Name">Name</a></span> or <spanclass="spec-nt"><ahref="#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 — whether based on recursive descent, an LL(<em>k</em>) or LALR parser generator, a parsing expression grammar, or any other technique — that accepts exactly the documents, and performs exactly the disambiguation, described herein.</p>
1296
1299
</section>
1297
1300
<sectionid="sec-Grammar-Semantics" secid="A.4">
1298
1301
<h2><spanclass="spec-secid" title="link to this section"><ahref="#sec-Grammar-Semantics">A.4</a></span>Grammar Semantics</h2>
0 commit comments