Skip to content

Commit

Permalink
Add more docs on parens. Fixes peggyjs#398.
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Apr 6, 2023
1 parent 986a2e1 commit 4ec608c
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 86 deletions.
23 changes: 22 additions & 1 deletion docs/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,12 @@ <h3 id="grammar-syntax-and-semantics-parsing-expression-types">Parsing Expressio
<dt><code>( <em>expression</em> )</code></dt>

<dd>
<p>Match a subexpression and return its match result.</p>
<p>Match a subexpression and return its match result. Parentheses create
a new local context for the <a href="#action-execution-environment">Action
Execution Environment</a> as well as plucks with the <code>@</code>
operator. Note that the action block in the following example returns
<code>2</code> from the parenthesized expression, NOT from the rule -- the
rule returns an array of <code>2</code>'s due to the <code>+</code> operator.</p>

<div class="example">
<div>
Expand All @@ -767,6 +772,22 @@ <h3 id="grammar-syntax-and-semantics-parsing-expression-types">Parsing Expressio
<div class="result"></div>
</div>
</div>

<p>Similarly, in the next example, the pluck operator applies to the
return value of the parentheses, not the rule:</p>

<div class="example">
<div>
<div><em>Example:</em> <code>paren_pluck = (@[0-9] ",")+</code></div>
<div><em>Matches:</em> <code>"1,"</code>, <code>"2,3,"</code></div>
<div><em>Does not match:</em> <code>"2"</code>, <code>","</code></div>
</div>
<div class="try">
<em>Try it:</em>
<input type="text" value="1,2,3," class="exampleInput" name="paren_pluck">
<div class="result"></div>
</div>
</div>
</dd>

<dt><code><em>expression</em> *</code></dt>
Expand Down
Loading

0 comments on commit 4ec608c

Please sign in to comment.