From b1a3492648fc16368cc35edef646ecd33cd24f3e Mon Sep 17 00:00:00 2001 From: Michael Dyck Date: Mon, 25 May 2020 17:11:36 -0400 Subject: [PATCH] Editorial: Extract operation ParseText --- spec.html | 55 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/spec.html b/spec.html index 269cee202d0..60af368f473 100644 --- a/spec.html +++ b/spec.html @@ -10454,6 +10454,23 @@

Static Semantics: UTF16DecodeString ( _string_ )

1. Return _codePoints_. + + +

Static Semantics: ParseText ( _sourceText_, _goalSymbol_ )

+

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:

+ + 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. + + +

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.

+
+ +

See also clause .

+
+
@@ -21263,13 +21280,13 @@

Runtime Semantics: ClassDefinitionEvaluation

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 + 1. Let _constructorText_ be the source text
constructor(...args) { super(...args); }
- using the syntactic grammar with the goal symbol |MethodDefinition[~Yield, ~Await]|. 1. Else, - 1. Set _constructor_ to the result of parsing the source text + 1. Let _constructorText_ be the source text
constructor() {}
- using the syntactic grammar with the goal symbol |MethodDefinition[~Yield, ~Await]|. + 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]]. @@ -22456,7 +22473,7 @@

ParseScript ( _sourceText_, _realm_, _hostDefined_ )

1. Assert: _sourceText_ is an ECMAScript source text (see clause ). - 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_ }. @@ -23819,7 +23836,7 @@

ParseModule ( _sourceText_, _realm_, _hostDefined_ )

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:

1. Assert: _sourceText_ is an ECMAScript source text (see clause ). - 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_. @@ -24912,7 +24929,8 @@

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 ). + 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. @@ -26222,10 +26240,12 @@

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 UniqueFormalParameters : FormalParameters are applied. + 1. If _strict_ is *true*, apply the Early Error rules for UniqueFormalParameters : FormalParameters. 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. @@ -32512,11 +32532,12 @@

Static Semantics: ParsePattern ( _patternText_, _u_ )

The abstract operation ParsePattern takes arguments _patternText_ (a sequence of Unicode code points) and _u_ (a Boolean). It performs the following steps when called:

1. If _u_ is *true*, then - 1. Parse _patternText_ using the grammars in . 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 . 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_.
@@ -38154,7 +38175,9 @@

JSON.parse ( _text_ [ , _reviver_ ] )

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 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 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 @@ -38168,7 +38191,7 @@

JSON.parse ( _text_ [ , _reviver_ ] )

This function is the %JSONParse% intrinsic object.

The *"length"* property of the `parse` function is 2.

-

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.

+

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.