@@ -8901,10 +8901,10 @@ <h4>Variable Scope</h4>
89018901 query. The definition below provides a way of determining this from the
89028902 abstract syntax tree of a query.</p>
89038903 <p>Note that a subquery with a projection can hide variables; use of a variable in
8904- <code> FILTER</code> or in <code> MINUS</code> does not cause the variable to be in-scope
8904+ ` FILTER` or in ` MINUS` does not cause the variable to be in-scope
89058905 outside of those forms.</p>
89068906 <p>Let <b>P</b>, <b>P1</b>, and <b>P2</b> be graph patterns, and <b>E</b>,
8907- <b>E1</b>,..., through <b>En</b> be expressions. A variable <code>v</code> is in-scope if:</p>
8907+ <b>E1</b>,..., through <b>En</b> be expressions. A variable `v` is in-scope if:</p>
89088908 <table style="border-collapse: collapse; border-color: #000000; border-spacing:5px; border-width: 1px">
89098909 <tbody>
89108910 <tr>
@@ -8913,70 +8913,81 @@ <h4>Variable Scope</h4>
89138913 </tr>
89148914 <tr>
89158915 <td>Basic Graph Pattern (BGP)</td>
8916- <td><code>v</code> occurs in the BGP</td>
8916+ <td>`v` occurs in the BGP</td>
89178917 </tr>
89188918 <tr>
89198919 <td>Path</td>
8920- <td><code>v</code> occurs in the path</td>
8920+ <td>`v` occurs in the path</td>
89218921 </tr>
89228922 <tr>
8923- <td>Group <code> { P1 P2 ... }</code> </td>
8924- <td><code>v</code> is in-scope if it is in-scope in one or more of P1, P2, ...</td>
8923+ <td>Group ` { P1 P2 ... }` </td>
8924+ <td>`v` is in-scope if it is in-scope in one or more of P1, P2, ...</td>
89258925 </tr>
89268926 <tr>
8927- <td><code> GRAPH term { P }</code> </td>
8928- <td><code>v</code> is <code> term</code> or <code>v</code> is in-scope in P</td>
8927+ <td>` GRAPH term { P }` </td>
8928+ <td>`v` is ` term` or `v` is in-scope in P</td>
89298929 </tr>
89308930 <tr>
8931- <td><code> { P1 } UNION { P2 }</code> </td>
8932- <td><code>v</code> is in-scope in P1 or in-scope in P2</td>
8931+ <td>` { P1 } UNION { P2 }` </td>
8932+ <td>`v` is in-scope in P1 or in-scope in P2</td>
89338933 </tr>
89348934 <tr>
8935- <td><code> OPTIONAL {P}</code> </td>
8936- <td><code>v</code> is in-scope in P</td>
8935+ <td>` OPTIONAL {P}` </td>
8936+ <td>`v` is in-scope in P</td>
89378937 </tr>
89388938 <tr>
8939- <td><code> SERVICE term {P}</code> </td>
8940- <td><code>v</code> is <code> term</code> or <code>v</code> is in-scope in P</td>
8939+ <td>` SERVICE term {P}` </td>
8940+ <td>`v` is ` term` or `v` is in-scope in P</td>
89418941 </tr>
89428942 <tr>
8943- <td><code> BIND (expr AS v)</code> </td>
8944- <td><code>v</code> is in-scope</td>
8943+ <td>` BIND (expr AS v)` </td>
8944+ <td>`v` is in-scope</td>
89458945 </tr>
89468946 <tr>
8947- <td><code> SELECT .. v .. { P }</code> </td>
8948- <td><code>v</code> is in-scope</td>
8947+ <td>` SELECT .. v .. { P }` </td>
8948+ <td>`v` is in-scope</td>
89498949 </tr>
89508950 <tr>
8951- <td><code> SELECT ... (expr AS v)</code> </td>
8952- <td><code>v</code> is in-scope</td>
8951+ <td>` SELECT ... (expr AS v)` </td>
8952+ <td>`v` is in-scope</td>
89538953 </tr>
89548954 <tr>
8955- <td><code> GROUP BY (expr AS v)</code> </td>
8956- <td><code>v</code> is in-scope</td>
8955+ <td>` GROUP BY (expr AS v)` </td>
8956+ <td>`v` is in-scope</td>
89578957 </tr>
89588958 <tr>
8959- <td><code> SELECT * { P }</code> </td>
8960- <td><code>v</code> is in-scope in <code>P</code> </td>
8959+ <td>` SELECT * { P }` </td>
8960+ <td>`v` is in-scope in `P` </td>
89618961 </tr>
89628962 <tr>
8963- <td><code> VALUES v { values }</code> </td>
8964- <td><code>v</code> is in-scope</td>
8963+ <td>` VALUES v { values }` </td>
8964+ <td>`v` is in-scope</td>
89658965 </tr>
89668966 <tr>
8967- <td><code>VALUES varlist { values }</code></td>
8968- <td><code>v</code> is in-scope if <code>v</code> is in <code>varlist</code></td>
8967+ <td>`VALUES varlist { values }`</td>
8968+ <td>`v` is in-scope if `v` is in `varlist`</td>
8969+ </tr>
8970+ <tr>
8971+ <td>`EXISTS` and `NOT EXISTS`</td>
8972+ <td>
8973+ `v` is in-scope if it is in-scope for the
8974+ <a href="#defn_sparqlSolutionMapping">solution mapping</a>
8975+ where the expression containing `EXISTS` or `NOT EXISTS` is applied.
8976+ </td>
89698977 </tr>
89708978 </tbody>
89718979 </table>
8972- <p>The variable <code>v</code> must not be in-scope at the point of the <code>(expr AS
8973- v)</code> form. The scoping for <code>(expr AS v)</code> applies immediately in
8974- <code>SELECT</code> expressions.</p>
8975- <p>In <code>BIND (expr AS v)</code> requires that the variable <code>v</code> is not
8976- in-scope from the preceeding elements in the group graph pattern in which it is used.</p>
8977- <p>In <code>SELECT</code>, the variable <code>v</code> must not be in-scope in the graph
8978- pattern of the <code>SELECT</code> clause, nor used in another select expression earlier in
8979- the clause.</p>
8980+ <p>The variable `v` must not be in-scope at the point of the
8981+ `(expr AS v)` form. The scoping for `(expr AS v)`
8982+ applies immediately in `SELECT` expressions.
8983+ </p>
8984+ <p>In `BIND (expr AS v)` requires that the variable `v` is not
8985+ in-scope from the preceeding elements in the group graph pattern in which it is used.
8986+ </p>
8987+ <p>In `SELECT`, the variable `v` must not be in-scope in the graph
8988+ pattern of the `SELECT` clause, nor used in another select expression earlier in
8989+ the clause.
8990+ </p>
89808991 </section>
89818992 <section id="convertGraphPattern">
89828993 <h4>Converting Graph Patterns</h4>
@@ -11209,61 +11220,111 @@ <h3>Escape sequences in strings</h3>
1120911220 <section id="sparqlGrammar">
1121011221 <h3>Grammar</h3>
1121111222 <p>The EBNF notation used in the grammar is defined in
11212- Extensible Markup Language (XML) 1.1
11213- [[XML11]]
11223+ Extensible Markup Language (XML) 1.1 [[XML11]]
1121411224 section 6 <a data-cite="xml11#sec-notation">Notation</a>.</p>
11225+ <p>
11226+ There are two entry points into the grammar:
11227+ </p>
11228+ <ol>
11229+ <li><a href="#rQueryUnit">`QueryUnit`</a> for the SPARQL query language</li>
11230+ <li><a href="#rUpdateUnit">`UpdateUnit`</a> for the SPARQL update language.</li>
11231+ </ol>
11232+ <p>
11233+ The SPARQL grammar is LL(1) when the rules with uppercased names are used as terminals.
11234+ </p>
1121511235 <p>Notes:</p>
1121611236 <ol>
11217- <li>Keywords are matched in a case-insensitive manner with the exception of
11218- the keyword '<code>a</code>' which, in line with Turtle and N3, is used
11219- in place of the IRI <code>rdf:type</code>
11220- (in full, <code><a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#type">http://www.w3.org/1999/02/22-rdf-syntax-ns#type</a></code>).</li>
11221- <li>Escape sequences are case sensitive.</li>
11222- <li>When tokenizing the input and choosing grammar rules, the longest match is chosen.</li>
11223- <li>The SPARQL grammar is LL(1) when the rules with uppercased names are used as terminals.</li>
11224- <li>There are two entry points into the grammar: <code>QueryUnit</code> for the SPARQL query language
11225- and <code>UpdateUnit</code> for the SPARQL update language.</li>
11226- <li>In signed numbers, no white space is allowed between the sign and the number.
11227- The <code><a href="#rAdditiveExpression">AdditiveExpression</a></code> grammar rule allows for this by
11228- covering the two cases of an expression followed by a signed number. These
11229- produce an addition or subtraction of the unsigned number as appropriate.</li>
11230- <li>The tokens <code><a href="#rInsertData">INSERT DATA</a></code>,
11231- <code><a href="#rDeleteData">DELETE DATA</a></code> and
11232- <code><a href="#rDeleteWhere">DELETE WHERE</a></code> allow any amount of white space between the words.
11233- The single space version is used in the grammar for clarity.</li>
11234- <li>The <code><a href="#rQuadData">QuadData</a></code> and
11235- <code><a href="#rQuadPattern">QuadPattern</a></code>
11236- rules both use rule <code><a href="#rQuads">Quads</a></code>. The rule
11237- <code><a href="#rQuadData">QuadData</a></code>, used in
11238- <a href="#rInsertData"><code>INSERTDATA</code></a> and
11239- <a href="#rDeleteData"><code>DELETE DATA</code></a>,
11240- must not allow variables in the quad patterns.</li>
11241- <li>Blank node syntax is not allowed in <code><a href="#rDeleteWhere">DELETE WHERE</a></code>,
11242- the <code><a href="#rDeleteClause">DeleteClause</a></code> for
11243- <code>DELETE</code>,
11244- nor in <code><a href="#rDeleteData">DELETE DATA</a></code>.</li>
11245- <li>Rules for limiting the use of blank node identifiers are given in <a href="#grammarBNodes">section 19.6</a>.</li>
11246- <li>The number of variables in the variable list of a <code>VALUES</code> block
11247- must be the same as the number of each list of associated values in the <code>DataBlock</code>.</li>
11248- <li>Variables in the variable list of a <code>VALUES</code> block must be unique within that list.</li>
11249- <li>Variables introduced by <code>AS</code> in a <code>SELECT</code> clause
11250- must not already be <a href="#variableScope">in-scope</a>.</li>
11251- <li>The variable assigned in a <code>BIND</code> clause must not be already
11252- in-use within the immediately preceding <code><a href="#rTriplesBlock">TriplesBlock</a></code> within a
11253- <code><a href="#rGroupGraphPattern">GroupGraphPattern</a></code>.</li>
11254- <li>Aggregate functions can be one of the
11237+ <li>
11238+ Keywords are matched in a case-insensitive manner with the exception of
11239+ the keyword '`a`' which, in line with Turtle, is used
11240+ in place of the IRI for `rdf:type`
11241+ (in full, `http://www.w3.org/1999/02/22-rdf-syntax-ns#type`).
11242+ </li>
11243+ <li>
11244+ Escape sequences are case sensitive.
11245+ </li>
11246+ <li>
11247+ When tokenizing the input and choosing grammar rules, the longest match is chosen.
11248+ </li>
11249+ <li>
11250+ In signed numbers, no white space is allowed between the sign and the number.
11251+ The <a href="#rAdditiveExpression">AdditiveExpression</a>
11252+ grammar rule allows for this by covering the two cases of an expression
11253+ followed by a signed number. These produce an addition or subtraction of
11254+ the unsigned number as appropriate.
11255+ </li>
11256+ <li>
11257+ The tokens <a href="#rInsertData">`INSERT DATA`</a>,
11258+ <a href="#rDeleteData">`DELETE DATA`</a> and
11259+ <a href="#rDeleteWhere">`DELETE WHERE`</a>
11260+ allow any amount of white space between the words.
11261+ The single space version is used in the grammar for clarity.
11262+ </li>
11263+ <li>
11264+ The <a href="#rQuadData">`QuadData`</a> and
11265+ <a href="#rQuadPattern">`QuadPattern`</a>
11266+ rules both use rule <a href="#rQuads">`Quads`</a>. The rule
11267+ <a href="#rQuadData">`QuadData`</a>, used in
11268+ <a href="#rInsertData">`INSERT DATA`</a> and
11269+ <a href="#rDeleteDat
11270+ must not allow variables in the quad patterns.
11271+ </li>
11272+ <li>
11273+ Blank node syntax is not allowed in
11274+ <a href="#rDeleteWhere">`DELETE WHERE`</a>,
11275+ the <a href="#rDeleteClause">`DeleteClause`</a> for
11276+ `DELETE`,
11277+ nor in <a href="#rDeleteData">`DELETE DATA`</a>.
11278+ </li>
11279+ <li>
11280+ Rules for limiting the use of blank node identifiers are given in
11281+ <a href="#grammarBNodes"></a>.
11282+ </li>
11283+ <li>
11284+ The number of variables in the variable list of a
11285+ <a href="#rValuesClause">`VALUES`</a> clause
11286+ must correspond to the number of
11287+ <a data-cite="RDF12-CONCEPTS#dfn-rdf-term">RDF terms</a>
11288+ in each of the lists of associated values in the
11289+ <a href="#rDataBlock">`DataBlock`</a>.
11290+ </li>
11291+ <li>
11292+ Variables in the variable list of a
11293+ <a href="#rValuesClause">`VALUES`</a> clause
11294+ must be unique within that list.
11295+ </li>
11296+ <li>
11297+ Variables introduced by `AS` in a
11298+ <a href="#rSelectClause">`SELECT`</a> clause
11299+ must not already be <a href="#variableScope">in-scope</a>.
11300+ </li>
11301+ <li>
11302+ The variable assigned in a <a href="#rBind">`BIND`</a> clause
11303+ must not already be in-use within the immediately preceding
11304+ <a href="#rTriplesBlock">`TriplesBlock`</a> within a
11305+ <a href="#rGroupGraphPattern">`GroupGraphPattern`</a>.
11306+ </li>
11307+ <li>
11308+ Aggregate functions can be one of the
1125511309 <a href="#rAggregate">built-in keywords for aggregates</a>
1125611310 or a custom aggregate, which is syntactically a <a href="#rFunctionCall">function
1125711311 call</a>. Aggregate functions may only be used in
1125811312 <a href="#rSelectClause">SELECT</a>, <a href="#rHavingClause">HAVING</a>
11259- and <a href="#rOrderClause">ORDER BY</a> clauses.</li>
11260- <li>The expression argument of an aggregate function can not contain an aggregate function.</li>
11261- <li>Only custom aggregate functions use the <code>DISTINCT</code> keyword
11262- in a <a href="#rFunctionCall">function call</a>.</li>
11263- <li>A <a href="#rReifier">reifier</a> or
11313+ and <a href="#rOrderClause">ORDER BY</a> clauses.
11314+ </li>
11315+ <li>
11316+ The expression argument of an aggregate function can not
11317+ contain an aggregate function.
11318+ </li>
11319+ <li>
11320+ Only custom aggregate functions use the `DISTINCT` keyword
11321+ in a <a href="#rFunctionCall">function call</a>.
11322+ </li>
11323+ <li>
11324+ A <a href="#rReifier">reifier</a> or
1126411325 <a href="#rAnnotationBlockPath">annotation syntax</a>
1126511326 is only permitted after a triple when the property position is
11266- a simple path (an IRI, the keyword <code>a</code> , or a variable),
11327+ a simple path (an IRI, the keyword `a` , or a variable),
1126711328 and not for other path expressions.
1126811329 </li>
1126911330 </ol>
0 commit comments