Skip to content

Commit

Permalink
Editorial: Extract operation ParseText
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdyck committed May 26, 2020
1 parent 6ef161e commit 1e2b425
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -10454,6 +10454,23 @@ <h1>Static Semantics: UTF16DecodeString ( _string_ )</h1>
1. Return _codePoints_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-parsetext" aoid="ParseText">
<h1>Static Semantics: ParseText ( _sourceText_, _goalSymbol_ )</h1>
<p>The abstract operation ParseText takes arguments _sourceText_ (a sequence of Unicode code points) and _goalSymbol_ (a nonterminal in one of the ECMAScript grammars). It performs the following steps when called:</p>
<emu-alg>
1. Attempt to parse _sourceText_ using _goalSymbol_ as the goal symbol, and analyse the parse result for any Early Error conditions.
1. NOTE: In the preceding step, parsing and Early Error detection may be interleaved in an implementation-dependent manner.
1. If the parse succeeded (i.e., _sourceText_ conformed to the grammar, all elements of _sourceText_ were matched by _goalSymbol_, ...), and no early errors were found (early error conditions exist), return the Parse Node (an instance of _goalSymbol_) at the root of the parse tree resulting from the parse.
1. Otherwise, return a List of one or more *SyntaxError* objects representing the parsing errors and/or early errors. If more than one parsing error or early error is present, the number and ordering of error objects in the list is implementation-dependent, but at least one must be present.
</emu-alg>
<emu-note>
<p>Consider a text that has an Early Error at a particular point, and also a syntax error at a later point. An implementation that does a parse pass followed by an Early Errors pass might report the syntax error and not proceed to the Early Errors pass. An implementation that interleaves the two activities might report the Early Error and not proceed to find the syntax error. A third implementation might report both errors. All of these behaviours are conformant.</p>
</emu-note>
<emu-note>
<p>See also clause <emu-xref href="#sec-error-handling-and-language-extensions"></emu-xref>.</p>
</emu-note>
</emu-clause>
</emu-clause>

<emu-clause id="sec-types-of-source-code">
Expand Down Expand Up @@ -21263,13 +21280,11 @@ <h1>Runtime Semantics: ClassDefinitionEvaluation</h1>
1. Else, let _constructor_ be ConstructorMethod of |ClassBody|.
1. If _constructor_ is ~empty~, then
1. If |ClassHeritage_opt| is present, then
1. Set _constructor_ to the result of parsing the source text
<pre><code class="javascript">constructor(...args) { super(...args); }</code></pre>
using the syntactic grammar with the goal symbol |MethodDefinition[~Yield, ~Await]|.
1. Let _constructorText_ be the source text <pre><code class="javascript">constructor(...args) { super(...args); }</code></pre>
1. Else,
1. Set _constructor_ to the result of parsing the source text
<pre><code class="javascript">constructor() {}</code></pre>
using the syntactic grammar with the goal symbol |MethodDefinition[~Yield, ~Await]|.
1. Let _constructorText_ be the source text <pre><code class="javascript">constructor() {}</code></pre>
1. Set _constructor_ to ParseText(_constructorText_, |MethodDefinition[~Yield, ~Await]|).
1. Assert: _constructor_ is a Parse Node.
1. Set the running execution context's LexicalEnvironment to _classScope_.
1. Let _constructorInfo_ be ! DefineMethod of _constructor_ with arguments _proto_ and _constructorParent_.
1. Let _F_ be _constructorInfo_.[[Closure]].
Expand Down Expand Up @@ -22456,7 +22471,7 @@ <h1>ParseScript ( _sourceText_, _realm_, _hostDefined_ )</h1>

<emu-alg>
1. Assert: _sourceText_ is an ECMAScript source text (see clause <emu-xref href="#sec-ecmascript-language-source-code"></emu-xref>).
1. Parse _sourceText_ using |Script| as the goal symbol and analyse the parse result for any Early Error conditions. If the parse was successful and no early errors were found, let _body_ be the resulting parse tree. Otherwise, let _body_ be a List of one or more *SyntaxError* objects representing the parsing errors and/or early errors. Parsing and early error detection may be interweaved in an implementation-dependent manner. If more than one parsing error or early error is present, the number and ordering of error objects in the list is implementation-dependent, but at least one must be present.
1. Let _body_ be ParseText(_sourceText_, |Script|).
1. If _body_ is a List of errors, return _body_.
1. Return Script Record { [[Realm]]: _realm_, [[Environment]]: *undefined*, [[ECMAScriptCode]]: _body_, [[HostDefined]]: _hostDefined_ }.
</emu-alg>
Expand Down Expand Up @@ -23819,7 +23834,7 @@ <h1>ParseModule ( _sourceText_, _realm_, _hostDefined_ )</h1>
<p>The abstract operation ParseModule takes arguments _sourceText_ (ECMAScript source text), _realm_, and _hostDefined_. It creates a Source Text Module Record based upon the result of parsing _sourceText_ as a |Module|. It performs the following steps when called:</p>
<emu-alg>
1. Assert: _sourceText_ is an ECMAScript source text (see clause <emu-xref href="#sec-ecmascript-language-source-code"></emu-xref>).
1. Parse _sourceText_ using |Module| as the goal symbol and analyse the parse result for any Early Error conditions. If the parse was successful and no early errors were found, let _body_ be the resulting parse tree. Otherwise, let _body_ be a List of one or more *SyntaxError* objects representing the parsing errors and/or early errors. Parsing and early error detection may be interweaved in an implementation-dependent manner. If more than one parsing error or early error is present, the number and ordering of error objects in the list is implementation-dependent, but at least one must be present.
1. Let _body_ be ParseText(_sourceText_, |Module|).
1. If _body_ is a List of errors, return _body_.
1. Let _requestedModules_ be the ModuleRequests of _body_.
1. Let _importEntries_ be ImportEntries of _body_.
Expand Down Expand Up @@ -24912,7 +24927,8 @@ <h1>Runtime Semantics: PerformEval ( _x_, _callerRealm_, _strictCaller_, _direct
1. Set _inMethod_ to _thisEnvRec_.HasSuperBinding().
1. If _F_.[[ConstructorKind]] is ~derived~, set _inDerivedConstructor_ to *true*.
1. Perform the following substeps in an implementation-dependent order, possibly interleaving parsing and error detection:
1. Let _script_ be the ECMAScript code that is the result of parsing ! UTF16DecodeString(_x_), for the goal symbol |Script|. If the parse fails, throw a *SyntaxError* exception. If any early errors are detected, throw a *SyntaxError* exception (but see also clause <emu-xref href="#sec-error-handling-and-language-extensions"></emu-xref>).
1. Let _script_ be ParseText(! UTF16DecodeString(_x_), |Script|).
1. If _script_ is a List of errors, throw a *SyntaxError* exception.
1. If _script_ Contains |ScriptBody| is *false*, return *undefined*.
1. Let _body_ be the |ScriptBody| of _script_.
1. If _inFunction_ is *false*, and _body_ Contains |NewTarget|, throw a *SyntaxError* exception.
Expand Down Expand Up @@ -26222,10 +26238,12 @@ <h1>Runtime Semantics: CreateDynamicFunction ( _constructor_, _newTarget_, _kind
1. Let _sourceString_ be the string-concatenation of _prefix_, *" anonymous("*, _P_, 0x000A (LINE FEED), *") {"*, _bodyString_, and *"}"*.
1. Let _sourceText_ be ! UTF16DecodeString(_sourceString_).
1. Perform the following substeps in an implementation-dependent order, possibly interleaving parsing and error detection:
1. Let _parameters_ be the result of parsing ! UTF16DecodeString(_P_), using _parameterGoal_ as the goal symbol. Throw a *SyntaxError* exception if the parse fails.
1. Let _body_ be the result of parsing ! UTF16DecodeString(_bodyString_), using _goal_ as the goal symbol. Throw a *SyntaxError* exception if the parse fails.
1. Let _parameters_ be ParseText(! UTF16DecodeString(_P_), _parameterGoal_).
1. If _parameters_ is a List of errors, throw a *SyntaxError* exception.
1. Let _body_ be ParseText(! UTF16DecodeString(_bodyString_), _goal_).
1. If _body_ is a List of errors, throw a *SyntaxError* exception.
1. Let _strict_ be ContainsUseStrict of _body_.
1. If any static semantics errors are detected for _parameters_ or _body_, throw a *SyntaxError* exception. If _strict_ is *true*, the Early Error rules for <emu-grammar>UniqueFormalParameters : FormalParameters</emu-grammar> are applied.
1. If _strict_ is *true*, apply the Early Error rules for <emu-grammar>UniqueFormalParameters : FormalParameters</emu-grammar>.
1. If _strict_ is *true* and IsSimpleParameterList of _parameters_ is *false*, throw a *SyntaxError* exception.
1. If any element of the BoundNames of _parameters_ also occurs in the LexicallyDeclaredNames of _body_, throw a *SyntaxError* exception.
1. If _body_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception.
Expand Down Expand Up @@ -32512,11 +32530,12 @@ <h1>Static Semantics: ParsePattern ( _patternText_, _u_ )</h1>
<p>The abstract operation ParsePattern takes arguments _patternText_ (a sequence of Unicode code points) and _u_ (a Boolean). It performs the following steps when called:</p>
<emu-alg>
1. If _u_ is *true*, then
1. Parse _patternText_ using the grammars in <emu-xref href="#sec-patterns"></emu-xref>. The goal symbol for the parse is |Pattern[+U, +N]|.
1. Let _parseResult_ be ParseText(_patternText_, |Pattern[+U, +N]|).
1. Else,
1. Parse _patternText_ using the grammars in <emu-xref href="#sec-patterns"></emu-xref>. The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of parsing contains a |GroupName|, reparse with the goal symbol |Pattern[~U, +N]| and use this result instead.
1. If _patternText_ did not conform to the grammar, or any elements of _patternText_ were not matched by the parse, or any Early Error conditions exist, return a List of one or more *SyntaxError* objects representing the parsing errors and/or early errors.
1. Otherwise, return the Parse Node resulting from the parse.
1. Let _parseResult_ be ParseText(_patternText_, |Pattern[~U, ~N]|).
1. If _parseResult_ is a Parse Node and _parseResult_ contains a |GroupName|, then
1. Set _parseResult_ to ParseText(_patternText_, |Pattern[~U, +N]|).
1. Return _parseResult_.
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -38154,7 +38173,9 @@ <h1>JSON.parse ( _text_ [ , _reviver_ ] )</h1>
1. Let _jsonString_ be ? ToString(_text_).
1. Parse ! UTF16DecodeString(_jsonString_) as a JSON text as specified in ECMA-404. Throw a *SyntaxError* exception if it is not a valid JSON text as defined in that specification.
1. Let _scriptString_ be the string-concatenation of *"("*, _jsonString_, and *");"*.
1. Let _completion_ be the result of parsing and evaluating ! UTF16DecodeString(_scriptString_) as if it was the source text of an ECMAScript |Script|. The extended PropertyDefinitionEvaluation semantics defined in <emu-xref href="#sec-__proto__-property-names-in-object-initializers"></emu-xref> must not be used during the evaluation.
1. Let _script_ be ParseText(! UTF16DecodeString(_scriptString_), |Script|).
1. Assert: _script_ is a Parse Node.
1. Let _completion_ be the result of evaluating _script_. The extended PropertyDefinitionEvaluation semantics defined in <emu-xref href="#sec-__proto__-property-names-in-object-initializers"></emu-xref> must not be used during the evaluation.
1. Let _unfiltered_ be _completion_.[[Value]].
1. Assert: _unfiltered_ is either a String, Number, Boolean, Null, or an Object that is defined by either an |ArrayLiteral| or an |ObjectLiteral|.
1. If IsCallable(_reviver_) is *true*, then
Expand All @@ -38168,7 +38189,7 @@ <h1>JSON.parse ( _text_ [ , _reviver_ ] )</h1>
<p>This function is the <dfn>%JSONParse%</dfn> intrinsic object.</p>
<p>The *"length"* property of the `parse` function is 2.</p>
<emu-note>
<p>Valid JSON text is a subset of the ECMAScript |PrimaryExpression| syntax. Step 2 verifies that _jsonString_ conforms to that subset, and step 6 verifies that that parsing and evaluation returns a value of an appropriate type.</p>
<p>Valid JSON text is a subset of the ECMAScript |PrimaryExpression| syntax. Step 2 verifies that _jsonString_ conforms to that subset, and step 8 verifies that that parsing and evaluation returns a value of an appropriate type.</p>
</emu-note>

<emu-clause id="sec-internalizejsonproperty" aoid="InternalizeJSONProperty">
Expand Down

0 comments on commit 1e2b425

Please sign in to comment.