Skip to content

Commit

Permalink
Fix "for member" grammar problems
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhkay committed Oct 16, 2023
1 parent 0e26cd8 commit 480c62f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
28 changes: 24 additions & 4 deletions specifications/grammar-40/xpath-grammar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,6 @@ VersionDecl ::= "xquery" (("encoding" StringLiteral) | ("version" StringLiteral
<g:production name="InitialClause" if="xquery40">
<g:choice>
<g:ref name="ForClause" lookahead="2"/>
<g:ref name="ForMemberClause" lookahead="2"/>
<g:ref name="LetClause"/>
<g:ref name="WindowClause" lookahead="2"/>
</g:choice>
Expand All @@ -967,8 +966,15 @@ VersionDecl ::= "xquery" (("encoding" StringLiteral) | ("version" StringLiteral
<g:ref name="ForBinding"/>
</g:zeroOrMore>
</g:production>

<g:production name="ForBinding" if="xquery40">
<g:choice>
<g:ref name="ForItemBinding"/>
<g:ref name="ForMemberBinding"/>
</g:choice>
</g:production>

<g:production name="ForItemBinding" if="xquery40">
<g:string>$</g:string>
<g:ref name="VarName"/>
<g:optional>
Expand All @@ -987,14 +993,28 @@ VersionDecl ::= "xquery" (("encoding" StringLiteral) | ("version" StringLiteral
<g:ref name="ExprSingle"/>
</g:production>

<g:production name="ForMemberBinding" if="xquery40">
<g:string>member</g:string>
<g:string>$</g:string>
<g:ref name="VarName"/>
<g:optional>
<g:ref name="TypeDeclaration"/>
</g:optional>
<g:optional>
<g:ref name="PositionalVar"/>
</g:optional>
<g:string>in</g:string>
<g:ref name="ExprSingle"/>
</g:production>



<g:production name="AllowingEmpty" if="xquery40">
<g:string>allowing</g:string>
<g:string>empty</g:string>
</g:production>

<g:production name="ForMemberClause" if="xquery40">
<!--<g:production name="ForMemberClause" if="xquery40">
<g:string>for</g:string>
<g:string>member</g:string>
<g:ref name="ForMemberBinding"/>
Expand All @@ -1015,7 +1035,7 @@ VersionDecl ::= "xquery" (("encoding" StringLiteral) | ("version" StringLiteral
</g:optional>
<g:string>in</g:string>
<g:ref name="ExprSingle"/>
</g:production>
</g:production>-->

<g:production name="PositionalVar" if=" xquery40">
<g:string>at</g:string>
Expand Down
24 changes: 17 additions & 7 deletions specifications/xquery-40/src/expressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16164,6 +16164,8 @@ return .($k)
<prodrecap id="IntermediateClause" ref="IntermediateClause"/>
<prodrecap ref="ForClause"/>
<prodrecap ref="ForBinding"/>
<prodrecap ref="ForItemBinding"/>
<prodrecap ref="ForMemberBinding"/>
<prodrecap ref="LetClause"/>
<prodrecap ref="LetBinding"/>
<prodrecap id="TypeDeclaration" ref="TypeDeclaration"/>
Expand Down Expand Up @@ -16287,8 +16289,8 @@ let $z := g($x, $y)]]></eg>
<scrap>
<head/>
<prodrecap id="ForClause" ref="ForClause"/>
<prodrecap id="ForMemberClause" ref="ForMemberClause"/>
<prodrecap id="ForBinding" ref="ForBinding"/>
<prodrecap id="ForItemBinding" ref="ForItemBinding"/>
<prodrecap id="ForMemberBinding" ref="ForMemberBinding"/>
<prodrecap ref="TypeDeclaration"/>
<prodrecap ref="AllowingEmpty"/>
Expand Down Expand Up @@ -16342,7 +16344,8 @@ for member $y in $expr2]]></eg>
def="dt-implementation-dependent">implementation-dependent</termref>.</p>
<p>If the <termref def="dt-binding-sequence"
>binding collection</termref> is empty, the output tuple stream depends on whether <code>allowing empty</code> is specified.
If <code>allowing empty</code> is specified, the output tuple stream consists of one tuple in which the variable is bound to an empty sequence.
If <code>allowing empty</code> is specified, the output tuple stream consists of one tuple in which the variable is bound to an empty sequence.
This option is not available with "for member".
If <code>allowing empty</code> is not specified, the output tuple stream consists of zero tuples.</p>
<p>The following examples illustrates tuple streams that are generated by initial <code>for</code> clauses:</p>
<ulist>
Expand Down Expand Up @@ -16453,11 +16456,18 @@ for member $y in $expr2]]></eg>
</note>
<p>For a given input tuple, if the <termref def="dt-binding-collection" diff="chg" at="A"
>binding collection</termref> for the new variable in the <code>for</code> clause <phrase diff="add" at="A">is empty
(that is, it is an empty sequence or an empty array depending on whether <code>member</code> is specified)</phrase>,
the result depends on whether <code>allowing empty</code> is specified. If <code>allowing empty</code>
is specified, the input tuple generates one output tuple, with the original variable bindings plus a
binding of the new variable to an empty sequence. If <code>allowing empty</code> is not specified,
the input tuple generates zero output tuples (it is not represented in the output tuple stream.)</p>
(that is, it is an empty sequence or an empty array depending on whether <code>member</code> is specified)</phrase>,
and if <code>allowing empty</code> is not specified, the input tuple generates zero output tuples
(it is not represented in the output tuple stream.)</p>

<p diff="chg" at="2023-10-16">The <code>allowing empty</code> option is available only when processing sequences, not when processing arrays.
The effect is that if the binding collection is an empty sequence, the input tuple generates one output tuple,
with the original variable bindings plus a binding of the new variable to an empty sequence.</p>

<note diff="add" at="2023-10-16"><p>If a type declaration is present and <code>allowing empty</code> is specified, the type declaration
should include an occurrence indicator of <code>"?"</code> to indicate that the variable may be bound to an
empty sequence.</p></note>

<p>If the new variable introduced by a <code>for</code> clause has an associated <termref
def="dt-positional-variable"
>positional variable</termref>, the output tuples generated by the <code>for</code> clause also contain bindings for the <termref
Expand Down

0 comments on commit 480c62f

Please sign in to comment.