Skip to content

Commit a5375bd

Browse files
jmdyckljharb
authored andcommitted
Editorial: Clarify note re parsing the same string multiple times (#1521)
... which was the subject of issue #1484. This is basically @allenwb's suggested wording from #1484 (comment)
1 parent 9a81833 commit a5375bd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

spec.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,13 @@ <h1>The Syntactic Grammar</h1>
460460
<p>When a parse is successful, it constructs a <em>parse tree</em>, a rooted tree structure in which each node is a <dfn>Parse Node</dfn>. Each Parse Node is an <em>instance</em> of a symbol in the grammar; it represents a span of the source text that can be derived from that symbol. The root node of the parse tree, representing the whole of the source text, is an instance of the parse's goal symbol. When a Parse Node is an instance of a nonterminal, it is also an instance of some production that has that nonterminal as its left-hand side. Moreover, it has zero or more <em>children</em>, one for each symbol on the production's right-hand side: each child is a Parse Node that is an instance of the corresponding symbol.</p>
461461
<p>New Parse Nodes are instantiated for each invocation of the parser and never reused between parses even of identical source text. Parse Nodes are considered <dfn>the same Parse Node</dfn> if and only if they represent the same span of source text, are instances of the same grammar symbol, and resulted from the same parser invocation.</p>
462462
<emu-note>
463-
<p>Parsing the same String multiple times will lead to different Parse Nodes, e.g., as occurs in:</p>
464-
<pre><code class="javascript">eval(str); eval(str);</code></pre>
463+
<p>Parsing the same String multiple times will lead to different Parse Nodes. For example, consider:</p>
464+
<pre><code class="javascript">
465+
let str = "1 + 1;";
466+
eval(str);
467+
eval(str);
468+
</code></pre>
469+
<p>Each call to `eval` converts the value of `str` into an ECMAScript source text and performs an independent parse that creates its own separate tree of Parse Nodes. The trees are distinct even though each parse operates upon a source text that was derived from the same String value.</p>
465470
</emu-note>
466471
<emu-note>Parse Nodes are specification artefacts, and implementations are not required to use an analogous data structure.</emu-note>
467472
<p>Productions of the syntactic grammar are distinguished by having just one colon &ldquo;<b>:</b>&rdquo; as punctuation.</p>

0 commit comments

Comments
 (0)