<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2002 W3C(r) (http://www.w3.org/) (MIT (http://www.lcs.mit.edu/),
INRIA (http://www.inria.fr/), Keio (http://www.keio.ac.jp/)),
All Rights Reserved.
See http://www.w3.org/Consortium/Legal/ipr-notice-20000612#Copyright.
W3C liability
(http://www.w3.org/Consortium/Legal/ipr-notice-20000612#Legal_Disclaimer),
trademark
(http://www.w3.org/Consortium/Legal/ipr-notice-20000612#W3C_Trademarks),
document use
(http://www.w3.org/Consortium/Legal/copyright-documents-19990405),
and software licensing rules
(http://www.w3.org/Consortium/Legal/copyright-software-19980720)
apply.
-->
<!DOCTYPE g:grammar SYSTEM "grammar.dtd">

<g:grammar xmlns:g="http://www.w3.org/2001/03/XPath/grammar">
  <!-- ====================== Meta Information ==================== -->
  <!-- SJB grammar2spec.xsl seems to pick the first of these to create anchor names -->
  <g:language id="xpath" display-name="XPath 2.0" if="xpath"/>
  <g:language id="pathx1" display-name="XPath 1.0" if="pathx1"/>
  <g:language id="xquery" display-name="XQuery 1.0" if="xquery"/>
  <g:language id="fulltext" display-name="XQuery 1.0 Full-Text" if="fulltext"/>
  <g:language id="core" display-name="XML Processing Formal Semantics Core Language 1.0" if="core"/>
  <!-- g:language id="xslt1-patterns" display-name="XSLT 1.0 Match Patterns" if="pathx1"/ -->
  <g:language id="xslt-patterns" display-name="XSLT 2.0 Match Patterns" if="xslt-patterns"/>
  <g:language id="update" display-name="XQuery Update Facility" if="xquery update"/>
  <!-- ====================== Entry Point Information ==================== -->
  <g:start name="ExprSingle" state="DEFAULT" if="pathx1"/>
  <g:start name="XPath" state="DEFAULT" if="xpath"/>
  <g:start name="Expr" state="DEFAULT" if="core"/>
  <g:start name="QueryList" state="DEFAULT" if="xquery"/>
  <g:start name="Pattern" state="DEFAULT" if="xslt-patterns"/>

  <!-- ====================== Grammar Productions ==================== -->
  <!-- The QueryList production is  not in the official grammar,
       and is not shown in the bnf.  It is here only for the purpose
       of testing a series of queries.
    -->
  <g:production name="QueryList" if="xquery" show="no">
    <g:ref name="Module"/>
    <g:zeroOrMore name="QueryListTail">
      <g:string>%%%</g:string>
      <g:optional name="OptionalModule">
        <g:ref name="Module"/>
      </g:optional>
    </g:zeroOrMore>
  </g:production>
  <g:production name="XPath" if="xpath">
    <!--<g:optional name="XPathOptionalExpr">-->
    <g:ref name="Expr"/>
    <!--</g:optional>-->
  </g:production>
  <!-- DEFAULT PROLOG -->
  <!-- ### Use the name="" names instead of Expr_1() for generated .jj code -->
  <g:production name="Module" if="xquery" editor-is-outline-presentation="yes">
    <g:optional name="OptionalVersionDecl" lookahead="2">
      <g:ref name="VersionDecl"/>
    </g:optional>
    <g:choice name="MainOrLibraryModule">
      <g:ref name="LibraryModule" lookahead="2"/>
      <g:ref name="MainModule"/>
    </g:choice>
  </g:production>
  <g:production name="VersionDecl" if="xquery">
    <g:string tokgroup="2">xquery</g:string>
    <g:string>version</g:string>
    <g:ref name="StringLiteral"/>
    <g:optional name="OptionalEncodingSpec">
      <g:string>encoding</g:string>
      <g:ref name="StringLiteral"/>
    </g:optional>
    <g:ref name="Separator"/>
  </g:production>
  <g:production name="MainModule" if="xquery">
    <g:ref name="Prolog"/>
    <g:ref name="QueryBody"/>
  </g:production>
  <g:production name="LibraryModule" if="xquery">
    <g:ref name="ModuleDecl"/>
    <g:ref name="Prolog"/>
  </g:production>

  <g:production name="ModuleDecl" if="xquery core">
    <g:string tokgroup="2">module</g:string>
    <g:string>namespace</g:string>
    <g:ref name="NCName"/>
    <g:string>=</g:string>
    <g:ref name="URILiteral"/>
    <g:ref name="Separator"/>
  </g:production>
  <g:production name="Prolog" if="xquery" editor-is-outline-presentation="no">
    <!-- g:zeroOrMore name="SetterList">
			<g:ref name="Setter"/>
			<g:ref name="Separator"/>
		</g:zeroOrMore -->
    <g:zeroOrMore name="DeclList" lookahead="2">
      <g:choice name="DeclChoice">
        <g:ref name="DefaultNamespaceDecl" lookahead="3"/>
        <g:ref name="Setter" lookahead="3"/>
        <g:ref name="NamespaceDecl" lookahead="2"/>
        <g:ref name="Import"/>
      </g:choice>
      <g:ref name="Separator"/>
    </g:zeroOrMore>
    <g:zeroOrMore name="FunctionsAndVarsList" lookahead="2">
      <g:choice name="FunctionOrVar">
        <g:ref name="VarDecl" lookahead="2"/>
        <g:ref name="FunctionDecl"  lookahead="2"/>
        <g:ref name="OptionDecl"  lookahead="2"/>
        <g:ref name="FTOptionDecl" lookahead="2" if="fulltext" not-if="xpath"/>
      </g:choice>
      <g:ref name="Separator"/>
    </g:zeroOrMore>
  </g:production>

  <g:production name="Setter" if="xquery">
    <g:choice name="SetterChoice">
      <g:ref name="BoundarySpaceDecl" lookahead="2" if="xquery"/>
      <g:ref name="DefaultCollationDecl" lookahead="3"/>
      <g:ref name="BaseURIDecl" lookahead="2"/>
      <g:ref name="ConstructionDecl" lookahead="2"/>
      <g:ref name="OrderingModeDecl" lookahead="2"/>
      <g:ref name="EmptyOrderDecl" lookahead="3"/>
      <g:ref name="RevalidationDecl" if="update" lookahead="2"/>
      <g:ref name="CopyNamespacesDecl"/>
    </g:choice>
  </g:production>
  <g:production name="Import" if="xquery">
    <g:choice name="Imports">
      <g:ref name="SchemaImport" lookahead="2"/>
      <g:ref name="ModuleImport"/>
    </g:choice>
  </g:production>
  <g:production name="Separator" if="xquery core">
    <g:string>;</g:string>
  </g:production>
  <g:production name="NamespaceDecl" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">declare</g:string>
    <g:string>namespace</g:string>
    <g:ref name="NCName"/>
    <g:string>=</g:string>
    <g:ref name="URILiteral"/>
  </g:production>
  <g:production name="BoundarySpaceDecl" if="xquery" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">declare</g:string>
    <g:string>boundary-space</g:string>
    <!-- g:ref name="XMLSpaceEquals"/ -->
    <g:choice name="XMLSpacePreserveOrStrip">
      <g:string process-value="yes">preserve</g:string>
      <g:string process-value="yes">strip</g:string>
    </g:choice>
  </g:production>
  <g:production name="DefaultNamespaceDecl" if="xquery core" editor-is-outline-presentation="yes">
	<g:string tokgroup="3">declare</g:string>
	<g:string>default</g:string>
    <g:choice name="DeclareDefaultElementOrFunction">
      <g:string process-value="yes">element</g:string>
      <g:string process-value="yes">function</g:string>
    </g:choice>
    <g:string>namespace</g:string>
    <!-- g:ref name="AssignEquals"/ -->
    <g:ref name="URILiteral"/>
  </g:production>
  <g:production name="OptionDecl" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">declare</g:string>
    <g:string>option</g:string>
    <g:ref name="QName"/>
    <g:ref name="StringLiteral"/>
  </g:production>
  <g:production name="FTOptionDecl" if="fulltext" not-if="xpath" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">declare</g:string>
    <g:string>ft-option</g:string>
    <g:oneOrMore name="FTMatchOptionListInProlog">
      <g:ref name="FTMatchOption"/>
    </g:oneOrMore>
  </g:production>
  <g:production name="OrderingModeDecl" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">declare</g:string>
    <g:string>ordering</g:string>
    <g:choice name="DeclareOrderingArgument">
      <g:string process-value="yes">ordered</g:string>
      <g:string process-value="yes">unordered</g:string>
    </g:choice>
  </g:production>
  <g:production name="EmptyOrderDecl" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="3">declare</g:string>
    <g:string>default</g:string>
    <g:string>order</g:string>
	<g:string tokgroup="2">empty</g:string>
    <g:choice name="DeclareEmptyOrderArgument">
		<g:ref name="Greatest"/>
		<g:ref name="Least"/>
    </g:choice>
  </g:production>
  <g:production name="CopyNamespacesDecl" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">declare</g:string>
    <g:string>copy-namespaces</g:string>
    <g:ref name="PreserveMode"/>
    <g:string>,</g:string>
    <g:ref name="InheritMode"/>
  </g:production>
  <g:production name="PreserveMode" if="xquery core">
    <g:choice name="ChoiceForPreserveMode">
      <g:string process-value="yes">preserve</g:string>
      <g:string process-value="yes">no-preserve</g:string>
    </g:choice>
  </g:production>
  <g:production name="InheritMode" if="xquery core">
    <g:choice name="ChoiceForInheritMode">
      <g:string process-value="yes">inherit</g:string>
      <g:string process-value="yes">no-inherit</g:string>
    </g:choice>
  </g:production>
  <g:production name="DefaultCollationDecl" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="3">declare</g:string>
    <g:string>default</g:string>
    <g:string>collation</g:string>
    <!-- ref name="StringLiteral"/ -->
    <g:ref name="URILiteral"/>
  </g:production>
  <g:production name="BaseURIDecl" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">declare</g:string>
    <g:string>base-uri</g:string>
    <g:ref name="URILiteral"/>
  </g:production>
  <g:production name="SchemaImport" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">import</g:string>
    <g:string>schema</g:string>
    <!-- See http://lists.w3.org/Archives/Member/w3c-xml-query-wg/2002Jan/0181.html -->
    <g:optional name="OptionalSchemaImportPrefixDecl">
      <g:ref name="SchemaPrefix"/>
    </g:optional>
    <g:ref name="URILiteral"/>
    <g:optional name="OptionalLocationHint">
      <g:string tokgroup="2">at</g:string>
      <g:ref name="URILiteral"/>
      <g:zeroOrMore name="AdditionalSchemaLocationHints">
        <g:string>,</g:string>
        <g:ref name="URILiteral"/>
      </g:zeroOrMore>
    </g:optional>
  </g:production>
  <g:production name="SchemaPrefix" if="xquery core">
    <g:choice name="SchemaPrefixNamespaceBinding">
      <g:sequence>
        <g:string>namespace</g:string>
        <g:ref name="NCName"/>
        <g:string>=</g:string>
      </g:sequence>
      <g:sequence>
        <g:string tokgroup="2">default</g:string>
        <g:string>element</g:string>
        <g:string>namespace</g:string>
        <!-- g:ref name="AssignEquals"/ -->
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="ModuleImport" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">import</g:string>
    <g:string>module</g:string>
    <g:optional name="ImportPrefixDecl">
      <g:string>namespace</g:string>
      <g:ref name="NCName"/>
      <g:string>=</g:string>
    </g:optional>
    <g:ref name="URILiteral"/>
    <g:optional name="LocationHint">
      <g:string tokgroup="2">at</g:string>
      <g:ref name="URILiteral"/>
      <g:zeroOrMore name="AdditionalModuleLocationHints">
        <g:string>,</g:string>
        <g:ref name="URILiteral"/>
      </g:zeroOrMore>
    </g:optional>
  </g:production>
  <g:production name="VarDecl" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">declare</g:string>
    <g:string>variable</g:string>
    <g:string>$</g:string>
    <g:ref name="QName"/>
    <g:optional name="VarDeclOptionalTypeDecl">
      <g:ref name="TypeDeclaration" if="xquery core"/>
    </g:optional>
    <g:choice name="VarDeclAssignmentOrExtern">
      <g:sequence>
        <g:string>:=</g:string>
        <g:ref name="ExprSingle"/>
      </g:sequence>
      <g:ref name="External"/>
    </g:choice>
  </g:production>
  <g:production name="ConstructionDecl" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">declare</g:string>
    <g:string>construction</g:string>
    <g:choice name="StripOrPreserve">
      <g:string process-value="yes">strip</g:string>
      <g:string process-value="yes">preserve</g:string>
    </g:choice>
  </g:production>
  <g:production name="FunctionDecl" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="3">declare</g:string>
    <g:optional name="optionalUpdateQualifierForFunctionDecl" if="update">
      <g:string if="update">updating</g:string>
    </g:optional>
	<g:string>function</g:string>
    <g:ref name="QName"/>
    <g:string>(</g:string>
    <!-- ref name="FuncPListOpen"/ -->
    <g:optional name="OptionalParamList">
      <g:ref name="ParamList"/>
    </g:optional>
    <g:string>)</g:string>
    <g:optional name="optionFuncType">
      <g:string>as</g:string>
      <!-- Was Datatype -->
      <g:ref name="SequenceType"/>
    </g:optional>
    <g:choice name="FunctionDeclBody">
      <g:ref name="EnclosedExpr"/>
      <g:ref name="External"/>
    </g:choice>
  </g:production>
  <g:production name="ParamList" if="xquery core">
    <g:ref name="Param"/>
    <g:zeroOrMore name="ParamListTail">
      <g:string>,</g:string>
      <g:ref name="Param"/>
    </g:zeroOrMore>
  </g:production>
  <g:production name="Param" if="xquery core">
    <g:string>$</g:string>
    <g:ref name="QName"/>
    <g:optional name="OptionalTypeDeclarationForParam">
      <g:ref name="TypeDeclaration"/>
    </g:optional>
  </g:production>
  <g:production name="EnclosedExpr" if="xquery core">
    <g:choice name="EnclosedExprOpening">
      <g:ref name="Lbrace"/>
      <g:ref name="LbraceExprEnclosure" show="no"/>
    </g:choice>
    <g:ref name="Expr"/>
    <g:ref name="Rbrace"/>
  </g:production>
  <!-- END PROLOG -->

  <g:production name="QueryBody" if="xquery" editor-is-outline-presentation="yes">
    <g:ref name="Expr"/>
  </g:production>

  <g:production name="Expr" if="xpath xquery core">
    <g:ref name="ExprSingle"/>
    <g:zeroOrMore name="CommaExpr">
      <g:string>,</g:string>
      <g:ref name="ExprSingle"/>
    </g:zeroOrMore>
  </g:production>
  <g:production name="ExprSingle" node-type="void">
    <g:choice break="true" name="ExprSingleChoice">
      <g:ref name="FLWORExpr" if="xquery core" lookahead="2"/>
      <g:ref name="ForExpr" if="xpath" lookahead="2"/>
      <g:ref name="QuantifiedExpr" if="xquery xpath core" lookahead="2"/>
      <g:ref name="TypeswitchExpr" if="xquery core" lookahead="2"/>
      <g:ref name="IfExpr" if="xpath core xquery" lookahead="2"/>
	  <g:ref name="InsertExpr" if="update" lookahead="2"/>
	  <g:ref name="DeleteExpr" if="update" lookahead="2"/>
	  <g:ref name="RenameExpr" if="update" lookahead="2"/>
	  <g:ref name="ReplaceExpr" if="update" lookahead="2"/>
	  <g:ref name="TransformExpr" if="update" lookahead="2"/>
      <g:ref name="OrExpr" if="xpath core xquery pathx1"/>
    </g:choice>
  </g:production>
  <g:production name="FLWORExpr" if="xquery core" editor-is-outline-presentation="yes">
    <g:oneOrMore if="xquery" name="FLWORClauseList">
      <g:choice name="ForOrLet">
        <g:ref name="ForClause"/>
        <g:ref name="LetClause"/>
      </g:choice>
    </g:oneOrMore>
    <g:choice if="core" name="ForOrLetCore">
      <g:ref name="ForClause"/>
      <g:ref name="LetClause"/>
    </g:choice>
    <g:optional if="xquery" name="OptionalWhere">
      <g:ref name="WhereClause"/>
    </g:optional>
    <g:optional if="xquery" name="OptionalOrderBy">
      <g:ref name="OrderByClause" if="xquery core"/>
    </g:optional>
    <g:string>return</g:string>
    <g:ref name="ExprSingle"/>
  </g:production>
  <g:production name="ForExpr" if="xpath">
    <g:ref name="SimpleForClause"/>
    <g:string>return</g:string>
    <g:ref name="ExprSingle"/>
  </g:production>
  <!-- ForClause is slightly different now for XQuery vs. XPath.  -sb -->
  <g:production name="ForClause" if="xquery core">
    <g:string tokgroup="2">for</g:string>
    <g:string>$</g:string>
    <g:ref name="VarName"/>
    <g:optional if="xquery core" name="ForTypeDeclarationOption">
      <g:ref name="TypeDeclaration" if="xquery core"/>
    </g:optional>
    <g:optional if="xquery core" name="PositionalVarOption">
      <g:ref name="PositionalVar" if="xquery core"/>
    </g:optional>
    <!-- JD: fulltext requires score variable option here. 2005-08-16 -->
    <g:optional if="fulltext" name="FTScoreOption">
      <g:ref name="FTScoreVar"/>
    </g:optional>
    <g:string>in</g:string>
    <g:ref name="ExprSingle"/>
    <g:zeroOrMore if="xquery" name="ForClauseTail">
      <g:string>,</g:string>
      <g:string>$</g:string>
      <g:ref name="VarName"/>
      <g:optional if="xquery core" name="ForTailTypeDeclarationOption">
        <g:ref name="TypeDeclaration" if="xquery core"/>
      </g:optional>
      <g:optional if="xquery core" name="TailPositionalVarOption">
        <g:ref name="PositionalVar" if="xquery core"/>
      </g:optional>
      <!-- JD: fulltext requires score variable option here. 2005-08-16 -->
      <g:optional if="fulltext" name="FTScoreOptionForForClause">
        <g:ref name="FTScoreVar"/>
      </g:optional>
      <g:string>in</g:string>
      <g:ref name="ExprSingle"/>
    </g:zeroOrMore>
  </g:production>
  <g:production name="PositionalVar" if="core xquery">
    <g:string>at</g:string>
    <g:string>$</g:string>
    <g:ref name="VarName"/>
  </g:production>
  <!-- SimpleForClause is slightly different now for XQuery vs. XPath.  -sb -->
  <g:production name="SimpleForClause" if="xpath" node-type="void">
    <g:string tokgroup="2">for</g:string>
    <g:string>$</g:string>
    <g:ref name="VarName"/>
    <!-- JD: fulltext requires score variable option here. 2005-08-16 -->
    <g:optional if="fulltext" name="FTScoreOptionForSimpleForClause">
      <g:ref name="FTScoreVar"/>
    </g:optional>
    <g:string>in</g:string>
    <g:ref name="ExprSingle"/>
    <g:zeroOrMore name="SimpleForClauseTail">
      <g:string>,</g:string>
      <g:string>$</g:string>
      <g:ref name="VarName"/>
      <!-- JD: fulltext requires score variable option here. 2005-08-16 -->
      <g:optional if="fulltext" name="FTScoreOptionForSimpleForClauseTail">
        <g:ref name="FTScoreVar"/>
      </g:optional>
      <g:string>in</g:string>
      <g:ref name="ExprSingle"/>
    </g:zeroOrMore>
  </g:production>
  <!-- JD: add a score variable option for fulltext 2005-08-16 -->
  <g:production name="FTScoreVar" if="fulltext">
    <g:string tokgroup="2">score</g:string>
    <g:string>$</g:string>
    <g:ref name="VarName"/>
  </g:production>
  <g:production name="LetClause" if="xquery core">
    <!-- JD: add a score variable option for fulltext 2005-08-16 -->
    <g:choice name="LetVarOrLetScoreVar">
      <g:sequence lookahead="2">
        <g:string tokgroup="2">let</g:string>
        <g:string>$</g:string>
        <g:ref name="VarName"/>
        <g:optional if="xquery core" name="LetTypeDeclarationOption">
          <g:ref name="TypeDeclaration" if="xquery core"/>
        </g:optional>
      </g:sequence>
      <g:sequence lookahead="2" if="fulltext">
        <!-- JD: the case where no let-binding
				  but only score-binding occurs. 2005-08-16 -->
        <g:string tokgroup="3">let</g:string>
        <g:string>score</g:string>
        <g:string>$</g:string>
        <g:ref name="VarName"/>
      </g:sequence>
    </g:choice>
    <g:string>:=</g:string>
    <g:ref name="ExprSingle"/>
    <g:zeroOrMore if="xquery" name="LetClauseTail">
      <g:string>,</g:string>
      <!-- JD: add a score variable option for fulltext 2005-08-16 -->
      <g:choice name="LetVarOrLetScoreVarTail">
        <g:sequence>
          <g:string>$</g:string>
          <g:ref name="VarName"/>
          <g:optional if="xquery core" name="LetTailTypeDeclarationOption">
            <g:ref name="TypeDeclaration" if="xquery core"/>
          </g:optional>
        </g:sequence>
        <g:ref name="FTScoreVar" if="fulltext"/>
      </g:choice>
      <g:string>:=</g:string>
      <g:ref name="ExprSingle"/>
    </g:zeroOrMore>
  </g:production>
  <g:production name="WhereClause" if="xquery">
    <g:string>where</g:string>
    <g:ref name="ExprSingle"/>
  </g:production>
  <g:production name="OrderByClause" if="xquery core">
    <g:choice break="false" name="OrderByOrOrderByStable">
      <g:sequence>
        <g:string tokgroup="2">order</g:string>
        <g:string>by</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="3">stable</g:string>
        <g:string>order</g:string>
        <g:string>by</g:string>
      </g:sequence>
    </g:choice>
    <g:ref name="OrderSpecList"/>
  </g:production>
  <g:production name="OrderSpecList" if="xquery core">
    <g:ref name="OrderSpec"/>
    <g:zeroOrMore name="OrderSpecListTail">
      <g:string>,</g:string>
      <g:ref name="OrderSpec"/>
    </g:zeroOrMore>
  </g:production>
  <g:production name="OrderSpec" if="xquery core">
    <g:ref name="ExprSingle"/>
    <g:ref name="OrderModifier"/>
  </g:production>
  <g:production name="OrderModifier" if="xquery core">
    <g:optional name="SortDirectionOption">
      <g:choice name="AscendingOrDescending">
		<g:ref name="Ascending"/>
		<g:ref name="Descending"/>
      </g:choice>
    </g:optional>
    <g:optional name="EmptyPosOption">
	  <g:string tokgroup="2">empty</g:string>
      <g:choice name="EmptyGreatestOrLeast">
		<g:ref name="Greatest"/>
		<g:ref name="Least"/>
      </g:choice>
    </g:optional>
    <g:optional name="CollationSpecOption">
      <g:string>collation</g:string>
      <g:ref name="URILiteral"/>
    </g:optional>
  </g:production>
  <g:production name="QuantifiedExpr" if="xquery xpath core">
    <g:choice name="SomeOrEvery">
      <g:string process-value="yes" tokgroup="2">some</g:string>
      <g:string process-value="yes" tokgroup="2">every</g:string>
    </g:choice>
    <g:string>$</g:string>
    <g:ref name="VarName"/>
    <g:optional if="xquery core" name="QuantifiedTypeDeclarationOption">
      <g:ref name="TypeDeclaration" if="xquery core"/>
    </g:optional>
    <g:string>in</g:string>
    <g:ref name="ExprSingle"/>
    <g:zeroOrMore name="QuantifiedVarDeclListTail">
      <g:string>,</g:string>
      <g:string>$</g:string>
      <g:ref name="VarName"/>
      <g:optional if="xquery core" name="QuantifiedTailTypeDeclarationOption">
        <g:ref name="TypeDeclaration" if="xquery core"/>
      </g:optional>
      <g:string>in</g:string>
      <g:ref name="ExprSingle"/>
    </g:zeroOrMore>
    <g:string>satisfies</g:string>
    <g:ref name="ExprSingle"/>
  </g:production>
  <g:production name="TypeswitchExpr" if="xquery core">
    <g:string tokgroup="2">typeswitch</g:string>
    <g:string>(</g:string>
    <g:ref name="Expr"/>
    <g:string>)</g:string>
    <g:oneOrMore name="CaseClauseList">
      <g:ref name="CaseClause"/>
    </g:oneOrMore>
    <g:string>default</g:string>
    <g:optional name="DefaultClauseVarBindingOption" if="xquery">
      <g:string>$</g:string>
      <g:ref name="VarName"/>
    </g:optional>
      <g:string if="core">$</g:string>
      <g:ref name="VarName" if="core"/>
    <g:string>return</g:string>
    <g:ref name="ExprSingle"/>
  </g:production>
  <g:production name="CaseClause" if="xquery core">
    <g:string>case</g:string>
    <g:optional name="CaseClauseVarBindingOption" if="xquery">
      <g:string>$</g:string>
      <g:ref name="VarName"/>
      <g:string>as</g:string>
    </g:optional>
      <g:string if="core">$</g:string>
      <g:ref name="VarName" if="core"/>
      <g:string if="core">as</g:string>
    <g:ref name="SequenceType"/>
    <g:string>return</g:string>
    <g:ref name="ExprSingle"/>
  </g:production>
  <g:production name="IfExpr" if="xpath core xquery">
    <g:string tokgroup="2">if</g:string>
    <g:string>(</g:string>
    <g:ref name="Expr"/>
    <g:string>)</g:string>
    <!-- XPath TF decision to remove, Oct 16, 2002 -->
    <g:string>then</g:string>
    <g:ref name="ExprSingle"/>
    <g:string>else</g:string>
    <g:ref name="ExprSingle"/>
  </g:production>
  <g:exprProduction name="OperatorExpr" node-type="void" if="xquery core xpath pathx1">
    <g:level>
      <g:binary name="OrExpr" if="core xpath xquery pathx1" condition="&gt; 1">
        <g:string>or</g:string>
      </g:binary>
    </g:level>
    <g:level>
      <g:binary name="AndExpr" if="core xpath xquery pathx1" condition="&gt; 1">
        <g:string>and</g:string>
      </g:binary>
    </g:level>
    <g:level>
      <g:binary name="ComparisonExpr" prefix-seq-type="?" if="xpath xquery" condition="&gt; 1">
        <g:choice break="true" name="ValueOrGeneralOrNodeComp">
          <g:ref name="ValueComp"/>
          <g:ref name="GeneralComp"/>
          <g:ref name="NodeComp"/>
        </g:choice>
      </g:binary>
    </g:level>
    <g:level>
      <g:postfix name="FTContainsExpr" prefix-seq-type="?" condition="&gt; 1" if="fulltext">
        <g:sequence name="FTContainsSeq">
          <g:string>ftcontains</g:string>
          <g:ref name="FTSelection"/>
          <g:optional name="FTContainsOption">
            <g:ref name="FTIgnoreOption"/>
          </g:optional>
        </g:sequence>
      </g:postfix>
    </g:level>
    <g:level>
      <g:binary name="RangeExpr" if="xquery xpath" prefix-seq-type="?" condition="&gt; 1">
        <g:string>to</g:string>
      </g:binary>
    </g:level>
    <g:level>
      <g:binary name="AdditiveExpr" if="xquery xpath pathx1" condition="&gt; 1">
        <g:choice name="AdditiveOps">
          <g:ref name="Plus"/>
          <g:ref name="Minus"/>
        </g:choice>
      </g:binary>
    </g:level>
    <g:level>
      <g:binary name="MultiplicativeExpr" if="xquery xpath pathx1" condition="&gt; 1">
        <g:choice name="MultiplicativeOps">
          <g:string>*</g:string>
          <g:string>div</g:string>
          <g:string>idiv</g:string>
          <g:string>mod</g:string>
        </g:choice>
      </g:binary>
    </g:level>
    <g:level>
      <g:binary name="UnionExpr" if="xquery xpath pathx1" condition="&gt; 1">
        <g:choice name="UnionOps">
          <g:string if="xquery xpath">union</g:string>
          <g:string>|</g:string>
        </g:choice>
      </g:binary>
    </g:level>
    <g:level>
      <g:binary name="IntersectExceptExpr" if="xquery xpath" condition="&gt; 1">
        <g:choice name="IntersectOps">
          <g:string>intersect</g:string>
          <g:string>except</g:string>
        </g:choice>
      </g:binary>
    </g:level>
    <g:level>
      <g:postfix name="InstanceofExpr" if="xquery xpath" prefix-seq-type="?" condition="&gt; 1">
        <g:sequence name="InstanceOfExprOps">
          <g:string tokgroup="2">instance</g:string>
          <g:string>of</g:string>
          <g:ref name="SequenceType"/>
        </g:sequence>
      </g:postfix>
    </g:level>
    <g:level>
      <g:postfix name="TreatExpr" if="xquery xpath" prefix-seq-type="?" condition="&gt; 1">
        <g:sequence name="TreatExprOps">
          <g:string tokgroup="2">treat</g:string>
          <g:string>as</g:string>
          <g:ref name="SequenceType"/>
        </g:sequence>
      </g:postfix>
    </g:level>
    <g:level>
      <g:postfix name="CastableExpr" if="core xquery xpath" prefix-seq-type="?" condition="&gt; 1">
        <g:sequence name="CastableExprOps">
          <g:string tokgroup="2">castable</g:string>
          <g:string>as</g:string>
          <g:ref name="SingleType"/>
        </g:sequence>
      </g:postfix>
    </g:level>
    <g:level>
      <g:postfix name="CastExpr" if="core xquery xpath" prefix-seq-type="?" condition="&gt; 1">
        <g:sequence name="CastExprOps">
          <g:string tokgroup="2">cast</g:string>
          <g:string>as</g:string>
          <g:ref name="SingleType"/>
        </g:sequence>
      </g:postfix>
    </g:level>
    <g:level node-type="UnaryExpr" level-user-action="boolean keepUnary=false;">
      <g:prefix name="UnaryExpr" if="xquery xpath pathx1" condition="keepUnary" prefix-seq-type="*">
        <g:choice name="UnaryExprOps">
          <g:ref name="Minus" token-user-action="keepUnary=true;"/>
          <g:ref name="Plus" if="xquery xpath core" token-user-action="keepUnary=true;"/>
        </g:choice>
      </g:prefix>
    </g:level>
    <g:level>
      <g:primary name="ValueExpr">
        <g:choice name="ValueExprChoices">
          <g:ref name="ValidateExpr" if="xquery core"  lookahead="2"/>
          <g:ref name="PathExpr" if="xquery xpath pathx1"/>
          <g:ref name="StepExpr" if="core"/>
          <g:ref name="ExtensionExpr" if="xquery core"/>
        </g:choice>
      </g:primary>
    </g:level>
  </g:exprProduction>
  <g:production name="GeneralComp" if="xpath xquery pathx1" is-binary="yes" node-type="void">
    <g:choice break="false" name="GeneralCompOps">
      <g:string>=</g:string>
      <g:string>!=</g:string>
	  <!-- This is a parser-context-based lexical state switch, which is
		very dangerous and not reliable if lookahead is past this point.
		The alternatives have been very carefully considered!
		-->
      <g:ref name="LessThanOpOrTagO" token-user-action="/* Careful! */ token_source.SwitchTo(DEFAULT); token_source.stateStack.pop(); "/>
      <g:string>&lt;=</g:string>
      <g:string>&gt;</g:string>
      <g:string>&gt;=</g:string>
    </g:choice>
  </g:production>
  <g:production name="ValueComp" if="xpath xquery" is-binary="yes" node-type="void">
    <g:choice break="false" name="ValueCompOps">
      <g:string>eq</g:string>
      <g:string>ne</g:string>
      <g:string>lt</g:string>
      <g:string>le</g:string>
      <g:string>gt</g:string>
      <g:string>ge</g:string>
    </g:choice>
  </g:production>
  <g:production name="NodeComp" if="xpath xquery" is-binary="yes" node-type="void">
    <g:choice break="false" name="NodeCompOps">
      <g:string>is</g:string>
      <!-- g:ref name="IsNot"/ -->
      <g:string>&lt;&lt;</g:string>
      <g:string>&gt;&gt;</g:string>
    </g:choice>
  </g:production>
  <g:production name="ValidateExpr" if="core xquery">
	<g:string tokgroup="2">validate</g:string>
	<g:optional name="OptionalValidationMode">
		<g:ref name="ValidationMode"/>
	</g:optional>
    <g:ref name="LbraceExprEnclosure"/>
    <g:ref name="Expr"/>
    <g:ref name="Rbrace"/>
  </g:production>
  <g:production name="ValidationMode" if="xquery core">
    <g:choice name="VModeChoice">
      <g:string process-value="yes">lax</g:string>
      <g:string process-value="yes">strict</g:string>
    </g:choice>
  </g:production>
  <g:production name="ExtensionExpr" if="xquery core">
    <g:oneOrMore name="Pragmas">
      <g:ref name="Pragma"/>
    </g:oneOrMore>
    <g:ref name="LbraceExprEnclosure"/>
    <g:optional name="OptionalExtensionExpr">
      <g:ref name="Expr"/>
    </g:optional>
    <g:ref name="Rbrace"/>
  </g:production>
  <g:production name="Pragma" if="xquery core" whitespace-spec="explicit">
    <g:ref name="PragmaOpen"/>
    <g:optional name="OptionalWhitespaceBeforeQNameForPragma">
      <g:ref name="S"/>
    </g:optional>
    <g:ref name="QNameForPragma"/>
	<g:optional>
		<g:ref name="SForPragma"/>
		<g:ref name="PragmaContents"/>
	</g:optional>
    <g:ref name="PragmaClose"/>
  </g:production>
  <g:production name="PragmaContents" if="xquery core">
    <g:zeroOrMore name="PragmaContent" subtract-reg-expr="(Char* '#)' Char*)">
      <g:ref name="ExtensionContentChar"/>
    </g:zeroOrMore>
  </g:production>
  <g:production name="PathExpr" xgc-id="leading-lone-slash" if="xquery xpath pathx1" condition="&gt;1">
    <g:choice break="true" name="PathExprChoices">
      <g:sequence>
        <g:ref name="Slash"/>
		<!-- tell the parser to shutup with lookahead="(1)" for "/ * /*" vs. "/*/*" -->
        <g:optional name="OptionalRootExprTail" lookahead="1">
          <g:ref name="RelativePathExpr"/>
        </g:optional>
      </g:sequence>
      <g:sequence>
        <g:ref name="SlashSlash"/>
        <g:ref name="RelativePathExpr"/>
      </g:sequence>
      <g:ref name="RelativePathExpr" if="xquery xpath"/>
    </g:choice>
  </g:production>
  <!-- g:production inline="yes" name="Root" value-type="id">
    <g:string>/</g:string>
  </g:production>
  <g:production inline="yes" name="RootDescendants" value-type="id">
    <g:string>//</g:string>
  </g:production -->
  <g:production name="RelativePathExpr" if="xquery xpath pathx1" node-type="void">
    <g:ref name="StepExpr"/>
    <g:zeroOrMore name="RelativePathExprTail">
      <g:choice name="RelativePathExprStepSep">
		<g:ref name="Slash" node-type="void"/>
        <g:ref name="SlashSlash"/>
      </g:choice>
      <g:ref name="StepExpr"/>
    </g:zeroOrMore>
  </g:production>
  <g:production name="StepExpr" node-type="StepExpr" if="core xquery xpath pathx1" condition="&gt;1 || isStep" prod-user-action="boolean savedIsStep = isStep; isStep=false;">
    <g:choice name="AxisOrFilterStep">
	  <!-- Need to look ahead 3 here for computed constructors: "element div {baz}" vs "element div baz". -->
      <g:ref name="FilterExpr" if="xpath xquery" nt-user-action-end="isStep = savedIsStep;" lookahead="3"/>
      <g:ref name="PrimaryExpr" if="core" lookahead="3"/>
      <g:ref name="AxisStep" nt-user-action-start="isStep=true;" nt-user-action-end="isStep = savedIsStep;"/>
    </g:choice>
  </g:production>
  <g:production name="RHSStepExpr" node-type="StepExpr" if="pathx1" condition="&gt;1 || isStep" prod-user-action="boolean savedIsStep = isStep; isStep=false;">
    <g:choice name="RHSAxisOrFilterStep">
      <g:ref name="AxisStep" nt-user-action-start="isStep=true;" nt-user-action-end="isStep = savedIsStep;"/>
      <g:ref name="FilterExpr" nt-user-action-end="isStep = savedIsStep;"/>
      <!-- g:ref name="PrimaryExpr" if="core"/ -->
    </g:choice>
  </g:production>
  <g:production name="AxisStep" node-type="void">
    <g:choice name="ForwardOrReverseStep">
      <g:ref name="ReverseStep" lookahead="2"/>
      <g:ref name="ForwardStep"/>
    </g:choice>
    <g:ref name="PredicateList" if="xquery xpath pathx1"/>
  </g:production>
  <g:production name="ForwardStep" node-type="void">
    <g:choice name="ForwardAxisOrAbbrev">
      <g:sequence lookahead="2">
        <g:ref name="ForwardAxis"/>
        <g:ref name="NodeTest"/>
      </g:sequence>
      <g:ref name="AbbrevForwardStep" if="xpath xquery pathx1"/>
    </g:choice>
  </g:production>
  <g:production name="ForwardAxis">
    <g:choice break="true" name="ForwardAxisNames">
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">child</g:string>
        <g:string>::</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">descendant</g:string>
        <g:string>::</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">attribute</g:string>
        <g:string>::</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">self</g:string>
        <g:string>::</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">descendant-or-self</g:string>
        <g:string>::</g:string>
      </g:sequence>
      <g:sequence  if="xquery xpath">
        <g:string process-value="yes" tokgroup="2">following-sibling</g:string>
        <g:string if="xquery xpath">::</g:string>
      </g:sequence>
      <g:sequence if="xquery xpath">
        <g:string process-value="yes" tokgroup="2">following</g:string>
        <g:string if="xquery xpath">::</g:string>
      </g:sequence>
      <g:sequence if="xpath core pathx1">
        <g:string process-value="yes" tokgroup="2">namespace</g:string>
        <g:string if="xpath core pathx1">::</g:string>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="AbbrevForwardStep" if="xquery xpath pathx1">
    <!-- g:ref name="Dot"/ -->
    <g:optional name="OptionalAtSugar">
      <g:string process-value="yes">@</g:string>
    </g:optional>
    <g:ref name="NodeTest"/>
    <!-- child axis -->
  </g:production>
  <g:production name="ReverseStep" node-type="void">
    <g:choice name="ReverseAxisOrAbbrev">
      <g:sequence>
        <g:ref name="ReverseAxis"/>
        <g:ref name="NodeTest"/>
      </g:sequence>
      <g:ref name="AbbrevReverseStep" if="xpath xquery pathx1"/>
    </g:choice>
  </g:production>
  <g:production name="ReverseAxis">
    <g:choice break="true" name="ReverseAxisNames">
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">parent</g:string>
        <g:string>::</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">ancestor</g:string>
        <g:string>::</g:string>
      </g:sequence>
      <g:sequence if="xquery xpath">
        <g:string process-value="yes" tokgroup="2">preceding-sibling</g:string>
        <g:string if="xquery xpath">::</g:string>
      </g:sequence>
      <g:sequence if="xquery xpath">
        <g:string process-value="yes" tokgroup="2">preceding</g:string>
        <g:string if="xquery xpath">::</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">ancestor-or-self</g:string>
        <g:string>::</g:string>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="AbbrevReverseStep" if="xquery xpath pathx1">
    <g:string>..</g:string>
  </g:production>
  <g:production name="NodeTest">
    <g:choice name="KindOrNameTest">
      <g:ref name="KindTest" lookahead="2"/>
      <g:ref name="NameTest"/>
    </g:choice>
  </g:production>
  <g:production name="NameTest">
    <g:choice name="QNameOrWildcard">
      <g:ref name="QName"/>
      <g:ref name="Wildcard"/>
    </g:choice>
  </g:production>
  <g:production name="Wildcard" whitespace-spec="explicit">
    <g:choice break="true" name="WildcardChoice">
      <g:string process-value="yes">*</g:string>
      <g:ref name="NCNameColonStar" needs-exposition-parens="yes"/>
      <g:ref name="StarColonNCName" if="xquery core xpath" needs-exposition-parens="yes"/>
    </g:choice>
  </g:production>
  <g:production name="FilterExpr" node-type="void" if="xquery xpath pathx1">
    <g:ref name="PrimaryExpr" if="xpath xquery"/>
    <g:ref name="RHSPrimaryExpr" if="pathx1"/>
    <g:ref name="PredicateList"/>
  </g:production>
  <g:production name="PredicateList" if="xquery xpath pathx1" condition="&gt; 0">
    <g:zeroOrMore name="PredicatesListX">
      <g:ref name="Predicate"/>
    </g:zeroOrMore>
  </g:production>
  <g:production name="Predicate" if="xquery xpath pathx1" condition="&gt; 0">
    <g:string>[</g:string>
    <g:ref name="Expr" if="xpath xquery core"/>
    <g:ref name="ExprSingle" if="pathx1"/>
    <g:string>]</g:string>
  </g:production>
  <g:production name="RHSPrimaryExpr" node-type="void" if="pathx1">
    <g:choice name="RHSPrimaryExprChoices">
      <g:ref name="VarRef"/>
      <g:ref name="ParenthesizedExpr"/>
      <g:ref name="ContextItemExpr" nt-user-action-start="isStep=true;" if="xquery xpath pathx1"/>
      <g:ref name="FunctionCall"/>
    </g:choice>
  </g:production>
  <g:production name="PrimaryExpr" node-type="void">
    <g:choice name="PrimaryExprChoices">
      <g:ref name="Literal"/>
      <g:ref name="VarRef" if="xpath xquery core"/>
      <g:ref name="ParenthesizedExpr" if="xpath xquery core"/>
      <g:ref name="ContextItemExpr" nt-user-action-start="isStep=true;" if="xquery xpath"/>
      <g:ref name="FunctionCall" if="xpath xquery core" lookahead="2"/>
      <g:ref name="OrderedExpr" if="xquery core" lookahead="2"/>
      <g:ref name="UnorderedExpr" if="xquery core" lookahead="2"/>
      <g:ref name="Constructor" if="xquery core" />
    </g:choice>
  </g:production>
  <g:production name="Literal" node-type="void">
    <g:choice name="NumericOrStringLit">
      <g:ref name="NumericLiteral"/>
      <g:ref name="StringLiteral"/>
    </g:choice>
  </g:production>
  <g:production name="NumericLiteral" node-type="void">
    <g:choice name="NumericLitChoice">
      <g:ref name="IntegerLiteral"/>
      <g:ref name="DecimalLiteral"/>
      <g:ref name="DoubleLiteral" if="xpath xquery core"/>
    </g:choice>
  </g:production>
  <g:production name="VarRef" node-type="void">
    <g:string>$</g:string>
    <g:ref name="VarName"/>
  </g:production>
  <g:production name="VarName">
    <g:ref name="QName"/>
  </g:production>
  <g:production name="ParenthesizedExpr">
    <g:string>(</g:string>
    <g:optional name="OptionalExpr">
      <g:ref name="Expr"/>
    </g:optional>
    <g:ref name="ExprSingle" if="pathx1"/>
    <g:string>)</g:string>
  </g:production>
  <g:production name="ContextItemExpr" if="xquery xpath pathx1">
    <g:string process-value="yes">.</g:string>
  </g:production>
  <g:production name="OrderedExpr" if="xquery core">
    <g:string tokgroup="2">ordered</g:string>
    <g:ref name="LbraceExprEnclosure"/>
    <g:ref name="Expr"/>
    <g:ref name="Rbrace"/>
  </g:production>
  <g:production name="UnorderedExpr" if="xquery core">
    <g:string tokgroup="2">unordered</g:string>
    <g:ref name="LbraceExprEnclosure"/>
    <g:ref name="Expr"/>
    <g:ref name="Rbrace"/>
  </g:production>
  <g:production name="FunctionCall" comment-id="parens" xgc-id="reserved-function-names">
     <g:ref name="FunctionQName" tokgroup="2"/>
     <g:string>(</g:string>
     <g:optional name="ArgList">
      <g:ref name="ExprSingle"/>
      <g:zeroOrMore name="ArgListTail">
        <g:string>,</g:string>
        <g:ref name="ExprSingle"/>
      </g:zeroOrMore>
    </g:optional>
    <g:string>)</g:string>
  </g:production>
  <g:production name="Constructor" if="xquery core">
    <g:choice break="true" name="ConstructorChoice">
      <g:ref name="DirectConstructor" if="xquery"/>
      <g:ref name="ComputedConstructor"/>
    </g:choice>
  </g:production>
  <g:production name="DirectConstructor" if="xquery">
    <g:choice break="true" name="DirectConstructorChoice">
      <g:ref name="DirElemConstructor"/>
      <g:ref name="DirCommentConstructor"/>
      <g:ref name="DirPIConstructor"/>
    </g:choice>
  </g:production>
  <g:production name="DirElemConstructor" if="xquery" whitespace-spec="explicit" editor-is-outline-presentation="yes">
    <g:choice name="TagOpenStart">
      <g:ref name="LessThanOpOrTagO" show="no"/>
      <g:ref name="StartTagOpen"/>
    </g:choice>
    <g:ref name="TagQName" token-user-action="_elementStack.push(token.image); "/>
    <g:ref name="DirAttributeList"/>
    <g:choice name="TagClose">
      <g:ref name="EmptyTagClose" token-user-action="_elementStack.pop(); "/>
      <g:sequence name="TagContent">
        <g:ref name="StartTagClose"/>
        <g:zeroOrMore name="ElementContentBody">
          <g:ref name="DirElemContent"/>
        </g:zeroOrMore>
        <g:ref name="EndTagOpen" node-type="void"/>
        <g:ref name="EndTagQName"
			token-user-action="if(!token.image.equals(_elementStack.pop())) throw new ParseException(&quot;Error: In a direct element constructor, the name used in the end tag must exactly match the name used in the corresponding start tag, including its prefix or absence of a prefix. Line: &quot; + token.beginLine); "/>
        <g:optional name="OptionalWhitespaceBeforeEndTagClose">
          <g:ref name="S" node-type="void"/>
        </g:optional>
        <g:ref name="EndTagClose" node-type="void"/>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="DirAttributeList" if="xquery" whitespace-spec="explicit">
    <g:zeroOrMore name="OptionalAttributeList">
      <g:ref name="S"/>
      <g:optional name="OptionalAttribute">
        <g:ref name="TagQName"/>
        <g:optional name="OptionalWhitespaceBeforeValueIndicator">
          <g:ref name="S"/>
        </g:optional>
        <g:ref name="ValueIndicator"/>
        <g:optional name="OptionalWhitespaceBeforeAttributeValue">
          <g:ref name="S"/>
        </g:optional>
        <g:ref name="DirAttributeValue"/>
      </g:optional>
    </g:zeroOrMore>
  </g:production>
  <g:production name="DirAttributeValue" if="xquery" whitespace-spec="explicit">
    <g:choice break="true" name="AttributeValueComponent">
      <g:sequence>
        <g:ref name="OpenQuot"/>
        <g:zeroOrMore name="QuotAttributeValueContents">
          <g:choice name="QuotContentOrEscape">
            <g:ref name="EscapeQuot"/>
            <g:ref name="QuotAttrValueContent"/>
          </g:choice>
        </g:zeroOrMore>
        <g:ref name="CloseQuot"/>
      </g:sequence>
      <g:sequence>
        <g:ref name="OpenApos"/>
        <g:zeroOrMore name="AposAttributeValueContents">
          <g:choice name="AposContentOrEscape">
            <g:ref name="EscapeApos"/>
            <g:ref name="AposAttrValueContent"/>
          </g:choice>
        </g:zeroOrMore>
        <g:ref name="CloseApos"/>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="QuotAttrValueContent" if="xquery">
    <g:choice break="true" name="QuotAttrValueComponent">
      <g:ref name="QuotAttrContentChar"/>
      <g:ref name="CommonContent"/>
    </g:choice>
  </g:production>
  <g:production name="AposAttrValueContent" if="xquery">
    <g:choice break="true" name="AposAttrValueComponent">
      <g:ref name="AposAttrContentChar"/>
      <g:ref name="CommonContent"/>
    </g:choice>
  </g:production>
  <g:production name="DirElemContent" if="xquery">
    <g:choice break="true" name="ElementContentComponents">
      <g:ref name="DirectConstructor"/>
      <g:ref name="CDataSection"/>
      <g:ref name="CommonContent"/>
      <g:ref name="ElementContentChar"/>
    </g:choice>
  </g:production>
  <g:production name="CommonContent" if="xquery">
    <g:choice name="CommonContentChoice">
      <g:ref name="PredefinedEntityRef"/>
      <g:ref name="CharRef" token-user-action="checkCharRef(token.image);"/>
      <g:ref name="LCurlyBraceEscape"/>
      <g:ref name="RCurlyBraceEscape"/>
      <g:ref name="EnclosedExpr"/>
    </g:choice>
  </g:production>
  <g:production name="DirCommentConstructor" if="xquery" whitespace-spec="explicit">
    <g:choice name="XmlCommentStartOpen">
      <g:ref name="XmlCommentStartForElementContent" show="no"/>
      <g:ref name="XmlCommentStart"/>
    </g:choice>
    <g:ref name="DirCommentContents"/>
    <g:ref name="XmlCommentEnd"/>
  </g:production>
  <g:production name="DirCommentContents" if="xquery" whitespace-spec="explicit">
    <g:zeroOrMore name="XmlCommentContents">
      <g:choice name="XmlCommentContentsChar">
        <g:ref name="CommentContentChar"/>
        <g:ref name="CommentContentCharDash" needs-exposition-parens="yes"/>
      </g:choice>
    </g:zeroOrMore>
  </g:production>
  <g:production name="DirPIConstructor" if="xquery" whitespace-spec="explicit">
    <g:choice name="ProcessingInstructionStartOpen">
      <g:ref name="ProcessingInstructionStartForElementContent" show="no"/>
      <g:ref name="ProcessingInstructionStart"/>
    </g:choice>
    <g:ref name="PITarget"/>
    <g:optional name="OptionalPIContent">
      <g:ref name="SForPI"/>
      <g:ref name="DirPIContents"/>
    </g:optional>
    <g:ref name="ProcessingInstructionEnd"/>
  </g:production>
  <g:production name="DirPIContents" if="xquery" whitespace-spec="explicit">
    <g:zeroOrMore name="XmlPIContentBody" subtract-reg-expr="(Char* '?&gt;' Char*)">
      <g:ref name="PIContentChar"/>
    </g:zeroOrMore>
  </g:production>
  <g:production name="CDataSection" if="xquery" whitespace-spec="explicit">
    <g:choice name="CdataSectionOpen">
      <g:ref name="CdataSectionStartForElementContent" show="no"/>
      <g:ref name="CdataSectionStart"/>
    </g:choice>
    <g:ref name="CDataSectionContents"/>
    <g:ref name="CdataSectionEnd"/>
  </g:production>
  <g:production name="CDataSectionContents" if="xquery" whitespace-spec="explicit">
    <g:zeroOrMore name="CdataSectionBody" subtract-reg-expr="(Char* ']]&gt;' Char*)">
      <g:ref name="CDataSectionChar"/>
    </g:zeroOrMore>
  </g:production>
  <g:production name="ComputedConstructor" if="xquery core">
    <g:choice break="true" name="ComputedConstructorChoice">
      <g:ref name="CompDocConstructor" if="xquery core"/>
      <g:ref name="CompElemConstructor" if="xquery core"/>
      <g:ref name="CompAttrConstructor" if="xquery core"/>
      <g:ref name="CompTextConstructor" if="xquery core"/>
      <g:ref name="CompCommentConstructor" if="xquery core"/>
      <g:ref name="CompPIConstructor" if="xquery core"/>
    </g:choice>
  </g:production>
  <g:production name="CompDocConstructor" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="2">document</g:string>
    <g:ref name="LbraceExprEnclosure"/>
    <g:ref name="Expr"/>
    <g:ref name="Rbrace"/>
  </g:production>
  <g:production name="CompElemConstructor" if="xquery core" editor-is-outline-presentation="yes">
    <g:string tokgroup="3">element</g:string>
    <g:choice name="CompElemConstructorSpec">
       <g:ref name="QName"/>
       <g:sequence>
        <g:ref name="LbraceExprEnclosure"/>
        <g:ref name="Expr"/>
        <g:ref name="Rbrace"/>
      </g:sequence>
    </g:choice>
    <g:ref name="LbraceExprEnclosure"/>
    <g:optional if="xquery" name="OptionalContentExpr">
      <g:ref name="ContentExpr"/>
    </g:optional>
    <g:ref if="core" name="ContentExpr"/>
    <g:ref name="Rbrace"/>
    <g:ref if="core" name="LbraceExprEnclosure"/>
    <g:zeroOrMore if="core">
      <g:ref if="core" name="NamespaceBinding"/>
    </g:zeroOrMore>
    <g:ref if="core" name="Rbrace"/>
  </g:production>
  <g:production if="core" name="NamespaceBinding">
    <g:string if="core">namespace</g:string>
    <g:ref if="core" name="NCName"/>
    <g:ref if="core" name="Lbrace"/>
    <g:ref if="core" name="URILiteral"/>
    <g:ref if="core" name="Rbrace"/>
  </g:production>
  <g:production name="ContentExpr" if="xquery core">
    <!-- g:choice name="CompElemNamespaceOrExprSingle">
			<g:ref name="LocalNamespaceDecl"/>
			<g:ref name="ExprSingle"/>
		</g:choice>
		<g:zeroOrMore name="CompElemBodyTail">
			<g:ref name="Comma"/>
			<g:choice name="TailCompElemNamespaceOrExprSingle">
				<g:ref name="LocalNamespaceDecl"/>
				<g:ref name="ExprSingle"/>
			</g:choice>
		</g:zeroOrMore -->
    <g:ref name="Expr"/>
  </g:production>
  <g:production name="CompAttrConstructor" if="xquery core">
    <g:string tokgroup="3">attribute</g:string>
    <g:choice name="CompAttrConstructorOpening">
      <g:ref name="QName"/>
      <g:sequence>
        <g:ref name="LbraceExprEnclosure"/>
        <g:ref name="Expr"/>
        <g:ref name="Rbrace"/>
      </g:sequence>
    </g:choice>
    <g:ref name="LbraceExprEnclosure"/>
    <g:optional if="xquery" name="OptionalCompAttrValExpr">
      <g:ref name="Expr"/>
    </g:optional>
    <g:ref if="core" name="Expr"/>
    <g:ref name="Rbrace"/>
  </g:production>
  <g:production name="CompTextConstructor" if="xquery core">
    <g:string tokgroup="2">text</g:string>
    <g:ref name="LbraceExprEnclosure"/>
    <g:ref name="Expr"/>
    <g:ref name="Rbrace"/>
  </g:production>
  <g:production name="CompCommentConstructor" if="xquery core">
    <g:string tokgroup="2">comment</g:string>
    <g:ref name="LbraceExprEnclosure"/>
    <g:ref name="Expr"/>
    <g:ref name="Rbrace"/>
  </g:production>
  <g:production name="CompPIConstructor" if="xquery core">
    <g:string tokgroup="3">processing-instruction</g:string>
    <g:choice name="CompXmlPIOpening">
      <g:ref name="NCName"/>
      <g:sequence>
        <g:ref name="LbraceExprEnclosure"/>
        <g:ref name="Expr"/>
        <g:ref name="Rbrace"/>
      </g:sequence>
    </g:choice>
    <g:ref name="LbraceExprEnclosure"/>
    <g:optional name="OptionalCompXmlPIExpr">
      <g:ref name="Expr"/>
    </g:optional>
    <g:ref name="Rbrace"/>
  </g:production>
  <g:production name="SingleType">
    <g:ref name="AtomicType"/>
    <g:optional name="OptionalOccurrenceIndicator">
      <g:string process-value="yes">?</g:string>
    </g:optional>
  </g:production>
  <g:production name="TypeDeclaration" if="xquery core">
    <g:string>as</g:string>
    <g:ref name="SequenceType"/>
  </g:production>
  <g:production name="SequenceType">
    <g:choice break="true" name="ItemTypeOrEmpty">
      <g:sequence lookahead="2">
        <g:string process-value="yes" tokgroup="3">empty-sequence</g:string>
        <g:string>(</g:string>
        <g:string>)</g:string>
      </g:sequence>
      <g:sequence>
        <g:ref name="ItemType"/>
        <g:optional name="OptionalOccurrenceIndicatorForSequenceType" lookahead="1">
          <g:ref name="OccurrenceIndicator"/>
        </g:optional>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="OccurrenceIndicator" xgc-id="occurrence-indicators">
    <g:choice name="OccurrenceIndicatorOps">
      <!-- ref name="Star" if="xpath xquery core" show="no"/>
        <g:ref name="Multiply" if="xpath xquery core"/>
        <g:ref name="Plus"/>
        <g:ref name="QMark"/ -->
      <g:string process-value="yes">?</g:string>
      <g:string process-value="yes">*</g:string>
      <g:ref node-type="void" name="Plus"/>
    </g:choice>
  </g:production>
  <g:production name="ItemType">
    <g:choice break="false" name="ItemTypeChoice">
      <g:ref name="KindTest" lookahead="2"/>
      <g:sequence lookahead="2">
        <g:string process-value="yes" tokgroup="3">item</g:string>
        <g:string>(</g:string>
        <g:string>)</g:string>
      </g:sequence>
      <g:ref name="AtomicType"/>
    </g:choice>
  </g:production>
  <g:production name="AtomicType">
    <g:ref name="QName"/>
  </g:production>
  <g:production name="KindTest" node-type="void">
    <g:choice break="true" name="KindTestChoice">
      <g:ref name="DocumentTest"/>
      <g:ref name="ElementTest"/>
      <g:ref name="AttributeTest"/>
      <g:ref name="SchemaElementTest"/>
      <g:ref name="SchemaAttributeTest"/>
      <g:ref name="PITest"/>
      <g:ref name="CommentTest"/>
      <g:ref name="TextTest"/>
      <g:ref name="AnyKindTest"/>
    </g:choice>
  </g:production>
  <g:production name="AnyKindTest">
    <g:string tokgroup="2">node</g:string>
    <g:string>(</g:string>
    <g:string>)</g:string>
  </g:production>
  <g:production name="DocumentTest">
    <g:string tokgroup="2">document-node</g:string>
	<g:string>(</g:string>
    <g:optional name="OptionalDocumentTestBody">
      <g:choice name="DocumentTestBodyChoice">
        <g:ref name="ElementTest"/>
        <g:ref name="SchemaElementTest"/>
      </g:choice>
    </g:optional>
    <g:string>)</g:string>
  </g:production>
  <g:production name="TextTest">
    <g:string tokgroup="2">text</g:string>
    <g:string>(</g:string>
    <g:string>)</g:string>
  </g:production>
  <g:production name="CommentTest">
	<g:string tokgroup="2">comment</g:string>
	<g:string>(</g:string>
	<g:string>)</g:string>
  </g:production>
  <g:production name="PITest">
    <g:string tokgroup="2">processing-instruction</g:string>
    <g:string>(</g:string>
    <g:optional name="OptionalPITestBody">
      <g:choice name="NCNameForPIOrStringLit">
        <g:ref name="NCName" if="xpath xquery core"/>
        <g:ref name="StringLiteral"/>
      </g:choice>
    </g:optional>
    <g:string>)</g:string>
  </g:production>
  <g:production name="AttributeTest">
    <g:string tokgroup="2">attribute</g:string>
    <g:string>(</g:string>
    <g:optional name="OptionalAttributeTestBody">
      <g:sequence>
        <!-- g:ref name="At"/ -->
        <g:ref name="AttribNameOrWildcard"/>
        <g:optional name="AttributeTestBodyOptionalParam">
          <g:string>,</g:string>
          <g:ref name="TypeName"/>
        </g:optional>
      </g:sequence>
    </g:optional>
    <g:string>)</g:string>
  </g:production>
  <g:production name="AttribNameOrWildcard" if="xpath xquery core">
    <g:choice name="AttrNameOrWildcardChoice">
      <g:ref name="AttributeName"/>
      <g:string process-value="yes">*</g:string>
    </g:choice>
  </g:production>
  <g:production name="SchemaAttributeTest">
    <g:string tokgroup="2">schema-attribute</g:string>
    <g:string>(</g:string>
    <g:ref name="AttributeDeclaration"/>
    <g:string>)</g:string>
  </g:production>
  <g:production name="AttributeDeclaration">
    <g:ref name="AttributeName"/>
  </g:production>
  <g:production name="ElementTest">
	<g:string tokgroup="2">element</g:string>
	<g:string>(</g:string>
    <g:optional name="OptionalElementTestBody">
      <g:sequence>
        <g:ref name="ElementNameOrWildcard"/>
        <g:optional name="ElementTestBodyOptionalParam">
          <g:string>,</g:string>
          <g:ref name="TypeName"/>
          <g:optional name="Nillable">
            <g:string process-value="yes">?</g:string>
          </g:optional>
        </g:optional>
      </g:sequence>
    </g:optional>
    <g:string>)</g:string>
  </g:production>
  <g:production name="ElementNameOrWildcard" if="xpath xquery core">
    <g:choice name="ElemNameOrWildcardChoice">
      <g:ref name="ElementName"/>
      <g:string process-value="yes">*</g:string>
    </g:choice>
  </g:production>
  <g:production name="SchemaElementTest">
	<g:string tokgroup="2">schema-element</g:string>
	<g:string>(</g:string>
    <g:ref name="ElementDeclaration"/>
    <g:string>)</g:string>
  </g:production>
  <g:production name="ElementDeclaration" if="xpath xquery core">
    <g:ref name="ElementName"/>
  </g:production>
  <g:production name="AttributeName" if="xpath xquery core">
    <g:ref name="QName"/>
  </g:production>
  <g:production name="ElementName" if="xpath xquery core">
    <g:ref name="QName"/>
  </g:production>
  <g:production name="TypeName" if="xpath xquery core">
    <g:ref name="QName"/>
  </g:production>
  <g:production name="URILiteral" if="xquery core fulltext" inline="false" reduce-contained="yes">
	<g:ref name="StringLiteral"/>
  </g:production>

  <!-- ============================== -->
  <!-- XSLT PATTERNS -->
  <!-- ============================== -->
  <g:production name="Pattern" if="xslt-patterns">
    <g:ref name="PathPattern"/>
    <g:optional name="PathPatternTail">
      <g:choice name="UnionSpecifier">
        <g:string if="xquery xpath">union</g:string>
        <g:string>|</g:string>
      </g:choice>
      <g:ref name="Pattern"/>
    </g:optional>
  </g:production>
  <g:production name="PathPattern" if="xslt-patterns" xgc-id="leading-lone-slash">
    <g:choice break="true" name="PathPatternChoices">
      <g:sequence>
        <g:ref name="Slash"/>
        <g:optional name="OptionalRelativePathPattern" lookahead="1">
          <g:ref name="RelativePathPattern"/>
        </g:optional>
      </g:sequence>
      <g:sequence>
        <g:ref name="SlashSlash"/>
        <g:ref name="RelativePathPattern"/>
      </g:sequence>
      <g:ref name="RelativePathPattern"/>
    </g:choice>
  </g:production>
  <g:production name="RelativePathPattern" if="xslt-patterns" node-type="void">
    <g:ref name="PatternStep"/>
    <g:optional name="RelativePathPatternTail">
      <g:choice name="PatternStepSep">
        <g:ref name="Slash" node-type="void"/>
        <g:ref name="SlashSlash"/>
      </g:choice>
      <g:ref name="RelativePathPattern"/>
    </g:optional>
  </g:production>
  <g:production name="PatternStep" if="xslt-patterns">
    <g:optional name="OptionalPatternAxis" lookahead="2">
      <g:ref name="PatternAxis"/>
    </g:optional>
    <g:ref name="NodeTest"/>
    <g:ref name="PredicateList"/>
  </g:production>
  <g:production name="PatternAxis" if="xslt-patterns">
    <g:choice break="true" name="AxisChoice">
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">child</g:string>
        <g:string>::</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">attribute</g:string>
        <g:string>::</g:string>
      </g:sequence>
      <g:string>@</g:string>
    </g:choice>
  </g:production>
  <g:production name="IdKeyPattern" if="pathx1" sub-spec="xslt-patterns">
    <g:choice name="KeyOrIDPattern">
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">id</g:string>
        <g:string>(</g:string>
        <g:ref name="IdKeyValue"/>
        <g:string>)</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">key</g:string>
        <g:string>(</g:string>
        <g:ref name="StringLiteral"/>
        <g:string>,</g:string>
        <g:ref name="IdKeyValue"/>
        <g:string>)</g:string>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="IdKeyValue" if="pathx1" node-type="void" sub-spec="xslt-patterns">
    <g:choice name="VarOrKeyValue">
      <g:ref name="StringLiteral"/>
      <g:sequence>
        <g:string>$</g:string>
        <g:ref name="VarName"/>
      </g:sequence>
    </g:choice>
  </g:production>
  <!-- SJB Full Text Productions start -->
  <g:production name="FTSelection" if="fulltext">
    <g:ref name="FTOr"/>
    <g:zeroOrMore name="FTSelectionzeroOrMore" lookahead="2">
      <g:choice name="FTSelectionChoice">
        <g:ref name="FTMatchOption"/>
        <g:ref name="FTProximity"/>
      </g:choice>
    </g:zeroOrMore>
    <g:optional name="FTWeightOptional" if="fulltext">
      <g:string>weight</g:string>
      <g:ref name="RangeExpr"/>
    </g:optional>
  </g:production>
  <g:exprProduction name="FTOrExpr" if="fulltext">
    <g:level if="fulltext">
      <g:binary name="FTOr" if="fulltext" condition="&gt; 1">
        <g:string>||</g:string>
      </g:binary>
    </g:level>
    <g:level>
      <g:binary name="FTAnd" if="fulltext" condition="&gt; 1">
        <g:string>&amp;&amp;</g:string>
      </g:binary>
    </g:level>
    <!-- binary NOT -->
    <!-- take this out - may put it back later -->
    <!-- <g:level>
			<g:binary name="FTNot" if="fulltext" prefix-seq-type="?" condition="> 1">
				<g:ref name="FTNotIndicator" />
			</g:binary>
		</g:level> -->
    <g:level>
      <g:binary name="FTMildNot" if="fulltext" condition="&gt; 1">
        <g:sequence>
          <g:string tokgroup="2">not</g:string>
          <g:string>in</g:string>
        </g:sequence>
      </g:binary>
    </g:level>
    <g:level node-type="FTUnaryNot" level-user-action="boolean keepUnary=false;" if="fulltext">
      <g:prefix name="FTUnaryNot" if="fulltext" prefix-seq-type="?" condition="keepUnary">
        <g:sequence>
          <g:string token-user-action="keepUnary=true;">!</g:string>
        </g:sequence>
      </g:prefix>
    </g:level>
    <g:level>
      <g:primary name="FTWordsSelection">
        <g:choice name="FTWordsSelectionChoice">
          <!-- <g:ref name="FTWords" lookahead="FTWords()"/> -->
          <g:sequence>
            <g:ref name="FTWords"/>
            <g:optional name="FTTimesOption">
              <g:ref name="FTTimes"/>
            </g:optional>
          </g:sequence>
          <g:sequence>
            <g:string>(</g:string>
            <g:ref name="FTSelection"/>
            <g:string>)</g:string>
          </g:sequence>
        </g:choice>
      </g:primary>
    </g:level>
  </g:exprProduction>
  <g:production name="FTWords" if="fulltext">
    <g:ref name="FTWordsValue"/>
    <g:optional name="FTWordsOption">
      <g:ref name="FTAnyallOption"/>
    </g:optional>
  </g:production>
  <g:production name="FTWordsValue" if="fulltext">
    <g:choice name="FTWordExpr">
      <g:ref name="Literal"/>
      <g:sequence name="FTEnclosedExpr">
        <g:ref name="LbraceExprEnclosure"/>
        <g:ref name="Expr"/>
        <g:ref name="Rbrace"/>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="FTProximity" if="fulltext">
    <g:choice name="FTProximityChoice">
      <g:ref name="FTOrder"/>
      <g:ref name="FTWindow"/>
      <g:ref name="FTDistance"/>
      <g:ref name="FTScope"/>
      <g:ref name="FTContent"/>
    </g:choice>
  </g:production>
  <g:production name="FTOrder" if="fulltext">
    <g:string>ordered</g:string>
  </g:production>

  <g:production name="FTMatchOption" if="fulltext">
    <g:choice name="FTMatchOptionChoice" break="true" if="fulltext">
      <g:ref name="FTCaseOption"/>
      <g:ref name="FTDiacriticsOption" lookahead="2"/>
      <!-- <g:ref name="FTSpecialcharOption"/> -->
      <g:ref name="FTStemOption" lookahead="2"/>
      <g:ref name="FTThesaurusOption" lookahead="2"/>
      <g:ref name="FTStopwordOption"  lookahead="2"/>
      <g:ref name="FTLanguageOption"  lookahead="2"/>
      <g:ref name="FTWildCardOption"/>
      <!-- g:ref name="FTContent"/ -->
      <!-- g:ref name="FTIgnoreOption"/ -->
    </g:choice>
  </g:production>
  <g:production name="FTCaseOption" if="fulltext">
    <g:choice name="FTCaseOptionChoice" break="true" if="fulltext">
      <g:string process-value="yes" >lowercase</g:string>
      <g:string process-value="yes" >uppercase</g:string>
      <g:sequence lookahead="2">
        <g:string tokgroup="2">case</g:string>
        <g:string process-value="yes">sensitive</g:string>
      </g:sequence>
      <g:sequence lookahead="2">
        <g:string tokgroup="2">case</g:string>
        <g:string process-value="yes">insensitive</g:string>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="FTDiacriticsOption" if="fulltext">
    <g:choice name="FTDiacriticsOptionChoice" break="true" if="fulltext">
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">with</g:string>
        <g:string>diacritics</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">without</g:string>
        <g:string>diacritics</g:string>
      </g:sequence>
      <g:sequence lookahead="2">
        <g:string tokgroup="2">diacritics</g:string>
        <g:string process-value="yes">sensitive</g:string>
      </g:sequence>
      <g:sequence lookahead="2">
        <g:string tokgroup="2">diacritics</g:string>
        <g:string process-value="yes">insensitive</g:string>
      </g:sequence>
    </g:choice>
  </g:production>
  <!-- SJB: remove special characters, may put them back later - Feb2005 -->
  <g:production name="FTStemOption" if="fulltext">
    <g:choice name="FTStemOptionChoice">
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">with</g:string>
        <g:string>stemming</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">without</g:string>
        <g:string>stemming</g:string>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="FTThesaurusOption" if="fulltext">
    <g:choice name="FTThesaurusChoice" break="true">
      <g:sequence name="FTWithThesaurusSeq" lookahead="3">
        <g:string tokgroup="2" process-value="yes">with</g:string>
        <g:string>thesaurus</g:string>
        <g:choice name="FTThesaurusIDChoice">
          <g:ref name="FTThesaurusID"/>
          <g:string>default</g:string>
        </g:choice>
      </g:sequence>
      <g:sequence name="FTWithThesaurusGroupSeq" lookahead="3">
        <g:string tokgroup="3" process-value="yes">with</g:string>
        <g:string>thesaurus</g:string>
        <g:string>(</g:string>
        <g:choice name="FTThesaurusIDChoice2">
          <g:ref name="FTThesaurusID"/>
          <g:string>default</g:string>
        </g:choice>
        <g:zeroOrMore name="FTThesaurusIDZeroOrMore">
          <g:string>,</g:string>
          <g:ref name="FTThesaurusID"/>
        </g:zeroOrMore>
        <g:string>)</g:string>
      </g:sequence>
      <g:sequence>
        <g:string tokgroup="2" process-value="yes">without</g:string>
        <g:string>thesaurus</g:string>
      </g:sequence>
      <!-- g:sequence name="FTWithDefaultThesaurusSeq">
				<g:ref name="FTWithDefaultThesaurusIndicator"/>
				<g:zeroOrMore name="FTThesaurusIDZeroOrMoreForFTWithDefaultThesaurusSeq">
					<g:ref name="Comma"/>
					<g:ref name="FTThesaurusID"/>
				</g:zeroOrMore>
			</g:sequence -->
    </g:choice>
  </g:production>
  <g:production name="FTThesaurusID" if="fulltext">
    <g:string tokgroup="2">at</g:string>
    <g:ref name="URILiteral"/>
    <g:optional name="FTRelationshipOption">
      <g:string tokgroup="2">relationship</g:string>
      <g:ref name="StringLiteral"/>
    </g:optional>
    <g:optional name="FTRangeOption" lookahead="2">
      <g:ref name="FTRange"/>
      <g:string>levels</g:string>
    </g:optional>
  </g:production>
  <g:production name="FTStopwordOption" if="fulltext">
    <g:choice name="FTStopwordOptionChoice" break="true">
      <g:sequence lookahead="2">
        <g:string process-value="yes" tokgroup="3">with</g:string>
        <g:string>stop</g:string>
        <g:string>words</g:string>
        <g:ref name="FTRefOrList"/>
        <g:zeroOrMore name="FTInclExlZeroOrMore">
          <g:ref name="FTInclExclStringLiteral"/>
        </g:zeroOrMore>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="3">without</g:string>
        <g:string>stop</g:string>
        <g:string>words</g:string>
      </g:sequence>
      <g:sequence lookahead="2">
        <g:string tokgroup="4">with</g:string>
        <g:string process-value="yes">default</g:string>
        <g:string>stop</g:string>
        <g:string>words</g:string>
        <g:zeroOrMore name="FTInclExlZeroOrMoreForFTStopwordOptionChoice">
          <g:ref name="FTInclExclStringLiteral"/>
        </g:zeroOrMore>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="FTRefOrList" if="fulltext" is-binary="yes">
    <g:choice name="FTRefOrListChoice" break="true">
      <g:sequence>
        <g:string tokgroup="2">at</g:string>
        <g:ref name="URILiteral"/>
      </g:sequence>
      <g:sequence>
        <g:string>(</g:string>
        <g:ref name="StringLiteral"/>
        <g:zeroOrMore name="FTCommaOption">
          <g:string>,</g:string>
          <g:ref name="StringLiteral"/>
        </g:zeroOrMore>
        <g:string>)</g:string>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="FTInclExclStringLiteral" if="fulltext">
    <g:choice name="FTUnionChoice">
      <g:string process-value="yes">union</g:string>
      <g:string process-value="yes">except</g:string>
    </g:choice>
    <g:ref name="FTRefOrList"/>
  </g:production>
  <g:production name="FTLanguageOption" if="fulltext">
    <g:string>language</g:string>
    <g:ref name="StringLiteral"/>
  </g:production>
  <g:production name="FTWildCardOption" if="fulltext">
    <g:choice name="FTWildCardOptionChoice" break="false" if="fulltext">
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">with</g:string>
        <g:string>wildcards</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">without</g:string>
        <g:string>wildcards</g:string>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="FTContent" if="fulltext">
    <g:choice name="FTStartEndEntireChoice" break="false" if="fulltext">
      <g:sequence lookahead="2">
        <g:string tokgroup="2">at</g:string>
        <g:string process-value="yes">start</g:string>
      </g:sequence>
      <g:sequence lookahead="2">
        <g:string tokgroup="2">at</g:string>
        <g:string process-value="yes">end</g:string>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">entire</g:string>
        <g:string>content</g:string>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="FTAnyallOption" if="fulltext">
    <g:choice name="FTAnyallOptionChoice" break="false" if="fulltext">
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">any</g:string>
		<g:optional name="FTAnyWordOption">
			<g:string process-value="yes">word</g:string>
		</g:optional>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes" tokgroup="2">all</g:string>
		<g:optional name="FTAllWordsOption">
			<g:string process-value="yes">words</g:string>
		</g:optional>
      </g:sequence>
      <g:string process-value="yes">phrase</g:string>
    </g:choice>
  </g:production>
  <g:production name="FTRange" if="fulltext">
    <g:choice name="FTRangeChoice" break="true" if="fulltext">
      <g:sequence>
        <g:string process-value="yes">exactly</g:string>
        <g:ref name="AdditiveExpr"/>
      </g:sequence>
      <g:sequence lookahead="2">
        <g:string tokgroup="2">at</g:string>
        <g:ref name="Least" node-type="void"/>
        <g:ref name="AdditiveExpr"/>
      </g:sequence>
      <g:sequence lookahead="2">
        <g:string tokgroup="2">at</g:string>
        <g:string process-value="yes">most</g:string>
        <g:ref name="AdditiveExpr"/>
      </g:sequence>
      <g:sequence>
        <g:string process-value="yes">from</g:string>
        <g:ref name="AdditiveExpr"/>
        <g:string>to</g:string>
        <g:ref name="AdditiveExpr"/>
      </g:sequence>
    </g:choice>
  </g:production>
  <g:production name="FTDistance" if="fulltext">
    <g:string>distance</g:string>
    <g:ref name="FTRange"/>
    <g:ref name="FTUnit"/>
  </g:production>
  <g:production name="FTWindow" if="fulltext">
    <g:string>window</g:string>
    <g:ref name="AdditiveExpr"/>
    <g:ref name="FTUnit"/>
  </g:production>
  <g:production name="FTTimes" if="fulltext">
    <g:string>occurs</g:string>
    <g:ref name="FTRange"/>
    <g:string>times</g:string>
  </g:production>
  <g:production name="FTScope" if="fulltext">
    <g:choice name="FTScopeChoice">
      <g:string process-value="yes">same</g:string>
      <g:string process-value="yes">different</g:string>
    </g:choice>
    <g:ref name="FTBigUnit"/>
  </g:production>
  <g:production name="FTUnit" if="fulltext">
    <g:choice name="FTUnitOption">
      <g:string process-value="yes">words</g:string>
      <g:string process-value="yes">sentences</g:string>
      <g:string process-value="yes">paragraphs</g:string>
    </g:choice>
  </g:production>
  <g:production name="FTBigUnit" if="fulltext">
    <g:choice name="FTBigUnitOption">
      <g:string process-value="yes">sentence</g:string>
      <g:string process-value="yes">paragraph</g:string>
    </g:choice>
  </g:production>
  <!--SJB FTMatchOption and children END -->
  <g:production name="FTIgnoreOption" if="fulltext">
    <g:string tokgroup="2">without</g:string>
    <g:string>content</g:string>
    <g:ref name="UnionExpr"/>
  </g:production>
  <!-- SJB Full Text Productions end -->
  <!-- XQuery Update Facility Start -->
  <g:production name="RevalidationDecl" if="update">
    <g:string tokgroup="2">declare</g:string>
    <g:string>revalidation</g:string>
    <g:choice name="RevalidationChoice">
      <g:string process-value="yes">strict</g:string>
      <g:string process-value="yes">lax</g:string>
      <g:string process-value="yes">skip</g:string>
    </g:choice>
  </g:production>
  <g:production name="InsertExpr" if="update">
    <g:string>do</g:string>
    <g:string>insert</g:string>
    <g:ref name="SourceExpr"/>
    <g:choice break="true" name="InsertExprTargetChoice">
      <g:sequence>
        <g:optional name="InsertExprAsOption">
          <g:string>as</g:string>
          <g:choice name="InsertExprAsChoice">
            <g:string process-value="yes">first</g:string>
            <g:string process-value="yes">last</g:string>
          </g:choice>
        </g:optional>
        <g:string>into</g:string>
      </g:sequence>
      <g:string process-value="yes">after</g:string>
      <g:string process-value="yes">before</g:string>
    </g:choice>
    <g:ref name="TargetExpr"/>
  </g:production>
  <g:production name="DeleteExpr" if="update">
    <g:string>do</g:string>
    <g:string>delete</g:string>
    <g:ref name="TargetExpr"/>
  </g:production>
  <g:production name="ReplaceExpr" if="update">
    <g:string>do</g:string>
    <g:string>replace</g:string>
    <g:optional name="ReplaceValueOfOption" lookahead="2">
		<g:string>value</g:string>
		<g:string>of</g:string>
    </g:optional>
    <g:ref name="TargetExpr"/>
    <g:string>with</g:string>
    <g:ref name="ExprSingle"/>
    <!-- g:zeroOrMore name="ReplaceExprTail" lookahead="2">
      <g:string>,</g:string>
      <g:ref name="LbraceExprEnclosure"/>
      <g:ref name="TargetExpr"/>
      <g:ref name="Rbrace"/>
      <g:string>with</g:string>
      <g:ref name="ExprSingle"/>
    </g:zeroOrMore -->
  </g:production>
  <g:production name="RenameExpr" if="update">
    <g:string>do</g:string>
    <g:string tokgroup="2">rename</g:string>
    <g:ref name="TargetExpr"/>
    <g:string>as</g:string>
    <g:ref name="NewNameExpr"/>
  </g:production>
  <g:production name="SourceExpr" if="update">
	<g:ref name="ExprSingle"/>
  </g:production>
  <g:production name="TargetExpr" if="update">
	<g:ref name="ExprSingle"/>
  </g:production>
  <g:production name="NewNameExpr" if="update">
	<g:ref name="ExprSingle"/>
  </g:production>
  <g:production name="TransformExpr" if="update">
    <g:string tokgroup="2">transform</g:string>
    <g:string>copy</g:string>
    <g:string>$</g:string>
    <g:ref name="VarName"/>
    <g:string>:=</g:string>
    <g:ref name="ExprSingle"/>
    <g:zeroOrMore name="TransformExprVarDeclsRest">
      <g:string>,</g:string>
      <g:string>$</g:string>
      <g:ref name="VarName"/>
      <g:string>:=</g:string>
      <g:ref name="ExprSingle"/>
    </g:zeroOrMore>
    <g:string>modify</g:string>
    <g:ref name="ExprSingle"/>
    <g:string>return</g:string>
    <g:ref name="ExprSingle"/>
  </g:production>
  <!-- End XQuery Update Facility -->

  <g:production name="NCName" show="no" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml-names/#NT-NCName" xgc-id="xml-version"
	reduce-contained="yes">
	<!-- TODO: For right now, parser has to flag NCName with ":" in it!  -->
	<!-- One would like to structure QName as a multi-part production... however, the problem with this
		is it makes it necessary to make a look-ahead of 4 for many choices... for instance, functionCall:
		foo:baz(). Also whitespace is easier to control if QName is a single token!  -->
	<g:ref name="QName"/>
  </g:production>
  <g:production name="QName" show="no" xgc-id="xml-version" xhref="http://www.w3.org/TR/REC-xml-names/#NT-QName" is-xml="yes"
	reduce-contained="yes">
    <g:choice name="QNameChoiceList">
      <g:ref name="FunctionQName"/>
	  <g:string process-value="yes">attribute</g:string>
	  <g:string process-value="yes">comment</g:string>
	  <g:string process-value="yes">document-node</g:string>
	  <g:string process-value="yes">element</g:string>
	  <g:string process-value="yes" if="xpath core xquery">if</g:string>
	  <g:string process-value="yes">item</g:string>
	  <g:string process-value="yes">node</g:string>
	  <g:string process-value="yes">processing-instruction</g:string>
	  <g:string process-value="yes">schema-attribute</g:string>
	  <g:string process-value="yes">schema-element</g:string>
	  <g:string process-value="yes">text</g:string>
	  <g:string process-value="yes" if="xquery core">typeswitch</g:string>
	  <g:string process-value="yes">empty-sequence</g:string>
	</g:choice>
  </g:production>

  <g:production name="FunctionQName" exposition-name="QName" show="no" xgc-id="xml-version"
	xhref="http://www.w3.org/TR/REC-xml-names/#NT-QName" is-xml="yes" reduce-contained="yes">
    <g:choice name="FunctionQNameChoiceList">
      <g:ref name="QNameToken" show="no"/>
	  <g:ref node-type="void" name="External"/>
	  <g:string process-value="yes" if="xquery core">xquery</g:string>
	  <g:string process-value="yes"  if="xquery core">version</g:string>
	  <g:string process-value="yes" if="xquery core">encoding</g:string>
	  <g:string process-value="yes" if="xquery core">module</g:string>
	  <g:string process-value="yes" if="xquery core">namespace</g:string>
	  <g:string process-value="yes" if="xquery core">declare</g:string>
	  <g:string process-value="yes" if="xquery">boundary-space</g:string>
	  <g:string process-value="yes" if="xquery">preserve</g:string>
	  <g:string process-value="yes" if="xquery">strip</g:string>
	  <g:string process-value="yes" if="xquery core">default</g:string>
	  <g:string process-value="yes" if="xquery core">function</g:string>
	  <g:string process-value="yes" if="xquery core">option</g:string>
	  <g:string process-value="yes" if="fulltext">ft-option</g:string>
	  <g:string process-value="yes" if="xquery core">ordering</g:string>
	  <g:string process-value="yes" if="xquery core">ordered</g:string>
	  <g:string process-value="yes" if="xquery core">unordered</g:string>
	  <g:string process-value="yes" if="xquery core">order</g:string>
	  <g:string process-value="yes" if="xquery core">empty</g:string>
	  <g:ref name="Greatest" node-type="void" if="xquery core"/>
	  <g:ref name="Least" node-type="void" if="xquery core fulltext"/>
	  <g:string process-value="yes" if="xquery core">copy-namespaces</g:string>
	  <g:string process-value="yes" if="xquery core">no-preserve</g:string>
	  <g:string process-value="yes" if="xquery core">inherit</g:string>
	  <g:string process-value="yes" if="xquery core">no-inherit</g:string>
	  <g:string process-value="yes" if="xquery core">collation</g:string>
	  <g:string process-value="yes" if="xquery core">base-uri</g:string>
	  <g:string process-value="yes" if="xquery core">import</g:string>
	  <g:string process-value="yes" if="xquery core">schema</g:string>
	  <g:string process-value="yes" if="xquery core">at</g:string>
	  <g:string process-value="yes" if="xquery core">variable</g:string>
	  <g:string process-value="yes" if="xquery core">construction</g:string>
	  <g:string process-value="yes" if="update">update</g:string>
	  <g:string process-value="yes" if="xquery core">as</g:string>
	  <g:string process-value="yes" if="xquery core">lax</g:string>
	  <g:string process-value="yes" if="xquery core">strict</g:string>
	  <g:string process-value="yes">return</g:string>
	  <g:string process-value="yes" if="update">transform</g:string>
	  <g:string process-value="yes" if="update">do</g:string>
	  <g:string process-value="yes">for</g:string>
	  <g:string process-value="yes">in</g:string>
	  <g:string process-value="yes" if="fulltext">score</g:string>
	  <g:string process-value="yes" if="xquery core">let</g:string>
	  <g:string process-value="yes" if="xquery">where</g:string>
	  <g:string process-value="yes" if="xquery core">by</g:string>
	  <g:string process-value="yes" if="xquery core">stable</g:string>
	  <g:ref name="Ascending" node-type="void" if="xquery core"/>
	  <g:ref name="Descending" node-type="void" if="xquery core"/>
	  <g:string process-value="yes" if="xquery xpath core">some</g:string>
	  <g:string process-value="yes" if="xquery xpath core">every</g:string>
	  <g:string process-value="yes" if="xquery xpath core">satisfies</g:string>
	  <g:string process-value="yes" if="xquery core">case</g:string>
	  <g:string process-value="yes" if="xpath core xquery">then</g:string>
	  <g:string process-value="yes" if="xpath core xquery">else</g:string>
	  <g:string process-value="yes" if="core xpath xquery pathx1">or</g:string>
	  <g:string process-value="yes" if="core xpath xquery pathx1">and</g:string>
	  <g:string process-value="yes" if="fulltext">ftcontains</g:string>
	  <g:string process-value="yes" if="xquery xpath">to</g:string>
	  <g:string process-value="yes">div</g:string>
	  <g:string process-value="yes" if="xquery xpath pathx1">idiv</g:string>
	  <g:string process-value="yes" if="xquery xpath pathx1">mod</g:string>
	  <g:string process-value="yes" if="xquery xpath">union</g:string>
	  <g:string process-value="yes" if="xquery xpath">intersect</g:string>
	  <g:string process-value="yes" if="xquery xpath">except</g:string>
	  <g:string process-value="yes" if="xquery xpath">instance</g:string>
	  <g:string process-value="yes" if="xquery xpath">of</g:string>
	  <g:string process-value="yes" if="xquery xpath">treat</g:string>
	  <g:string process-value="yes" if="core xquery xpath">castable</g:string>
	  <g:string process-value="yes" if="core xquery xpath">cast</g:string>
	  <g:string process-value="yes" if="xpath xquery">eq</g:string>
	  <g:string process-value="yes" if="xpath xquery">ne</g:string>
	  <g:string process-value="yes" if="xpath xquery">lt</g:string>
	  <g:string process-value="yes" if="xpath xquery">le</g:string>
	  <g:string process-value="yes" if="xpath xquery">gt</g:string>
	  <g:string process-value="yes" if="xpath xquery">ge</g:string>
	  <g:string process-value="yes" if="xpath xquery">is</g:string>
	  <g:string process-value="yes" if="core xquery">validate</g:string>
	  <g:string process-value="yes">child</g:string>
	  <g:string process-value="yes">descendant</g:string>
	  <g:string process-value="yes">self</g:string>
	  <g:string process-value="yes">descendant-or-self</g:string>
	  <g:string process-value="yes" if="xquery xpath">following-sibling</g:string>
	  <g:string process-value="yes" if="xquery xpath">following</g:string>
	  <g:string process-value="yes">parent</g:string>
	  <g:string process-value="yes">ancestor</g:string>
	  <g:string process-value="yes" if="xquery xpath">preceding-sibling</g:string>
	  <g:string process-value="yes" if="xquery xpath">preceding</g:string>
	  <g:string process-value="yes">ancestor-or-self</g:string>
	  <g:string process-value="yes" if="xquery core">document</g:string>
	  <g:string process-value="yes" if="pathx1">id</g:string>
	  <g:string process-value="yes" if="pathx1">key</g:string>
	  <g:string process-value="yes" if="fulltext">weight</g:string>
	  <g:string process-value="yes" if="fulltext">not</g:string>
	  <g:string process-value="yes" if="fulltext">lowercase</g:string>
	  <g:string process-value="yes" if="fulltext">uppercase</g:string>
	  <g:string process-value="yes" if="fulltext">sensitive</g:string>
	  <g:string process-value="yes" if="fulltext">insensitive</g:string>
	  <g:string process-value="yes" if="fulltext">with</g:string>
	  <g:string process-value="yes" if="fulltext">diacritics</g:string>
	  <g:string process-value="yes" if="fulltext">without</g:string>
	  <g:string process-value="yes" if="fulltext">stemming</g:string>
	  <g:string process-value="yes" if="fulltext">thesaurus</g:string>
	  <g:string process-value="yes" if="fulltext">relationship</g:string>
	  <g:string process-value="yes" if="fulltext">levels</g:string>
	  <g:string process-value="yes" if="fulltext">stop</g:string>
	  <g:string process-value="yes" if="fulltext">words</g:string>
	  <g:string process-value="yes" if="fulltext">language</g:string>
	  <g:string process-value="yes" if="fulltext">wildcards</g:string>
	  <g:string process-value="yes" if="fulltext">start</g:string>
	  <g:string process-value="yes" if="fulltext">end</g:string>
	  <g:string process-value="yes" if="fulltext">entire</g:string>
	  <g:string process-value="yes" if="fulltext">content</g:string>
	  <g:string process-value="yes" if="fulltext">any</g:string>
	  <g:string process-value="yes" if="fulltext">all</g:string>
	  <g:string process-value="yes" if="fulltext">phrase</g:string>
	  <g:string process-value="yes" if="fulltext">word</g:string>
	  <g:string process-value="yes" if="fulltext">exactly</g:string>
	  <g:string process-value="yes" if="fulltext">most</g:string>
	  <g:string process-value="yes" if="fulltext">from</g:string>
	  <g:string process-value="yes" if="fulltext">distance</g:string>
	  <g:string process-value="yes" if="fulltext">window</g:string>
	  <g:string process-value="yes" if="fulltext">occurs</g:string>
	  <g:string process-value="yes" if="fulltext">times</g:string>
	  <g:string process-value="yes" if="fulltext">same</g:string>
	  <g:string process-value="yes" if="fulltext">different</g:string>
	  <g:string process-value="yes" if="fulltext">sentences</g:string>
	  <g:string process-value="yes" if="fulltext">paragraphs</g:string>
	  <g:string process-value="yes" if="fulltext">sentence</g:string>
	  <g:string process-value="yes" if="fulltext">paragraph</g:string>
	  <g:string process-value="yes" if="update">insert</g:string>
	  <g:string process-value="yes" if="update">first</g:string>
	  <g:string process-value="yes" if="update">last</g:string>
	  <g:string process-value="yes" if="update">into</g:string>
	  <g:string process-value="yes" if="update">after</g:string>
	  <g:string process-value="yes" if="update">before</g:string>
	  <g:string process-value="yes" if="update">delete</g:string>
	  <g:string process-value="yes" if="update">replace</g:string>
	  <g:string process-value="yes" if="update">value</g:string>
	  <g:string process-value="yes" if="update">rename</g:string>
	  <g:string process-value="yes" if="update">copy</g:string>
	  <g:string process-value="yes" if="update">modify</g:string>
	  <g:string process-value="yes">type</g:string>
	</g:choice>
  </g:production>


  <!-- ====================== Lexical Specifications ==================== -->
  <!-- re-use "To" -->
  <!-- We may need to use an alias for "To", IF we decide the FTToIndicator goes in a different state from "To" -->
  <!-- SJB this is the same as AtString Literal, but with different transitions -->
  <!-- SJB add Full Text terminals END -->
  <!-- XQuery Update Facility -->
  <!-- XQeary Update Facility End -->
  <g:token name="IntegerLiteral" inline="false" value-type="number" type="literal" delimiter-type="nondelimiting">
    <g:ref name="Digits"/>
  </g:token>
  <g:token name="DecimalLiteral" inline="false" value-type="number" type="literal" whitespace-spec="explicit" delimiter-type="nondelimiting">
    <g:choice name="DecimalString">
      <g:sequence>
        <g:string>.</g:string>
        <g:ref name="Digits"/>
      </g:sequence>
      <g:sequence>
        <g:ref name="Digits"/>
        <g:string>.</g:string>
        <g:zeroOrMore name="DecimalFractionPart">
          <g:charClass>
            <g:charRange minChar="0" maxChar="9"/>
          </g:charClass>
        </g:zeroOrMore>
      </g:sequence>
    </g:choice>
  </g:token>
  <g:token name="DoubleLiteral" inline="false" delimiter-type="nondelimiting" value-type="number" type="literal" whitespace-spec="explicit" if="xpath xquery core">
    <g:choice name="DoubleString">
      <g:sequence>
        <g:string>.</g:string>
        <g:ref name="Digits"/>
      </g:sequence>
      <g:sequence>
        <g:ref name="Digits"/>
        <g:optional name="DoubleOptionFractionPart">
          <g:string>.</g:string>
          <g:zeroOrMore name="DoubleFractionPart">
            <g:charClass>
              <g:charRange minChar="0" maxChar="9"/>
            </g:charClass>
          </g:zeroOrMore>
        </g:optional>
      </g:sequence>
    </g:choice>
    <g:charClass>
      <g:char>e</g:char>
      <g:char>E</g:char>
    </g:charClass>
    <g:optional name="DoubleNegOrPos">
      <g:charClass>
        <g:char>+</g:char>
        <g:char>-</g:char>
      </g:charClass>
    </g:optional>
    <g:ref name="Digits"/>
  </g:token>

  <g:token name="StringLiteral" inline="false" value-type="string" type="literal"
	          whitespace-spec="explicit" delimiter-type="delimiting">
    <g:choice name="StringDilimitType">
      <g:sequence>
        <g:string>"</g:string>
        <g:zeroOrMore name="CharsInQuote">
          <g:choice name="QuoteTypeChar">
            <g:ref name="PredefinedEntityRef" if="xquery"/>
            <g:ref name="CharRef" if="xquery"  token-user-action="checkCharRef(token.image);"/>
            <g:ref name="EscapeQuot"/>
            <g:complement>
              <g:charClass>
                <g:char>"</g:char>
                <g:char if="xquery">&amp;</g:char>
              </g:charClass>
            </g:complement>
          </g:choice>
        </g:zeroOrMore>
        <g:string>"</g:string>
      </g:sequence>
      <g:sequence>
        <g:string>'</g:string>
        <g:zeroOrMore name="CharsInApos">
          <g:choice name="AposTypeChar">
            <g:ref name="PredefinedEntityRef" if="xquery"/>
            <g:ref name="CharRef" if="xquery"  token-user-action="checkCharRef(token.image);"/>
            <g:ref name="EscapeApos"/>
            <g:complement>
              <g:charClass>
                <g:char>'</g:char>
                <g:char if="xquery">&amp;</g:char>
              </g:charClass>
            </g:complement>
          </g:choice>
        </g:zeroOrMore>
        <g:string>'</g:string>
      </g:sequence>
    </g:choice>
  </g:token>
  <g:skip recognize="FTPROXIMITY FTMATCHOPTION PROLOG_SPECIAL PROLOG_NCNAME DECLAREORDERING DEFAULT PROLOG OPERAND OPERATOR KINDTEST NAMESPACEDECL SINGLETYPE ITEMTYPE NAMESPACEKEYWORD VARNAME OCCURRENCEINDICATOR CLOSEKINDTEST XQUERYVERSION PRAGMA OPTION URITOOPERATOR" if="xquery fulltext core">
    <g:choice name="WhiteSpacePatterns">
      <g:sequence>
        <g:oneOrMore name="SkippedWhitespaceString">
          <g:ref name="WhitespaceChar"/>
        </g:oneOrMore>
      </g:sequence>
      <!-- g:ref name="Comment"/ -->
      <!-- g:sequence>
                <g:ref name="CommentStart"/>
                <g:zeroOrMore name="WhitespaceCommentContentBody">
                    <g:choice name="WhitespaceCharOrComment">
                        <g:ref name="CommentContent"/>
                    </g:choice>
                </g:zeroOrMore>
                <g:ref name="CommentEnd"/>
	        </g:sequence -->
    </g:choice>
  </g:skip>

  <g:skip recognize="DEFAULT OPERAND OPERATOR SINGLETYPE ITEMTYPE KINDTEST CLOSEKINDTEST OCCURRENCEINDICATOR VARNAME" if="xpath">
    <g:oneOrMore name="SkippedWhitespaceStringForXPath">
      <g:ref name="WhitespaceChar"/>
    </g:oneOrMore>
  </g:skip>
  <!-- g:token name="NotOccurrenceIndicator" skip="yes">
    <g:complement>
      <g:charClass>
        <g:char>*</g:char>
        <g:char>?</g:char>
        <g:char>+</g:char>
      </g:charClass>
    </g:complement>
  </g:token -->
  <g:skip recognize="DEFAULT OPERAND OPERATOR QNAME" if="pathx1">
    <g:oneOrMore name="SkippedWhitespaceStringPathx1">
      <g:ref name="WhitespaceChar"/>
    </g:oneOrMore>
  </g:skip>

  <g:token name="Minus" value-type="id">
    <g:string>-</g:string>
  </g:token>
  <g:token name="Plus" value-type="id">
    <g:string>+</g:string>
  </g:token>
  <g:token name="External" value-type="id">
    <g:string>external</g:string>
  </g:token>
  <g:token name="Ascending" if="xquery core">
	<g:string>ascending</g:string>
  </g:token>
  <g:token name="Descending" if="xquery core">
	<g:string>descending</g:string>
  </g:token>
  <g:token name="Greatest" if="xquery core">
	<g:string>greatest</g:string>
  </g:token>
  <g:token name="Least" if="xquery core fulltext">
	<g:string>least</g:string>
  </g:token>

  <!-- JD: fulltext match options may be declared in prolog. 2005-08-16 -->
  <g:token name="Prefix" value-type="string" visible="false" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml-names/#NT-Prefix" xgc-id="xml-version">
    <g:ref name="NCNameTok"/>
  </g:token>
  <g:token name="LocalPart" value-type="string" visible="false" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml-names/#NT-LocalPart" xgc-id="xml-version">
    <g:ref name="NCNameTok"/>
  </g:token>
  <g:token name="Nmstart" inline="false" visible="false">
    <g:choice name="NmstartChar">
      <g:ref name="Letter"/>
      <g:string>_</g:string>
    </g:choice>
  </g:token>
  <g:token name="Nmchar" inline="false" visible="false">
    <g:choice name="NmcharChoice">
      <g:ref name="Letter"/>
      <g:ref name="CombiningChar"/>
      <g:ref name="Extender"/>
      <g:ref name="Digit"/>
      <g:string>.</g:string>
      <g:string>-</g:string>
      <g:string>_</g:string>
    </g:choice>
  </g:token>

  <!-- OpenQuot and CloseQuote need to be before StringLiteral in
	order for them to be matched by flex. -->
  <!-- Recognizing it in content disallows ]]> in content same as XML. -->
  <!-- This effectively disallows in element content and attribute
       values ampersands that are not part of entity or character
       references. -->
  <g:token name="PredefinedEntityRef" if="xquery" inline="false" whitespace-spec="explicit" delimiter-type="hide">
    <g:string>&amp;</g:string>
    <g:choice name="PredefinedEntityNames">
      <g:string>lt</g:string>
      <g:string>gt</g:string>
      <g:string>amp</g:string>
      <g:string>quot</g:string>
      <g:string>apos</g:string>
    </g:choice>
    <g:string>;</g:string>
  </g:token>

  <!-- Recognize in OPERATOR state for function definitions. -->
  <!-- These should be query only, once we get the validate issue fixed! -->
  <!-- Should only be recognized in attribute content. -->
  <g:token name="EscapeQuot" inline="false" override="yes" delimiter-type="hide">
    <g:string>""</g:string>
  </g:token>
  <g:token name="EscapeApos" inline="false" delimiter-type="hide">
    <g:string>''</g:string>
  </g:token>

  <g:token name="HexDigits" inline="false" if="xquery" show="no" visible="false">
    <g:oneOrMore name="HexDigitsString">
      <g:charClass>
        <g:charRange minChar="0" maxChar="9"/>
        <g:charRange minChar="a" maxChar="f"/>
        <g:charRange minChar="A" maxChar="F"/>
      </g:charClass>
    </g:oneOrMore>
  </g:token>
  <g:token name="Lbrace" if="xquery core fulltext update" override="yes">
    <g:string>{</g:string>
  </g:token>
  <g:token name="LbraceExprEnclosure" alias-for="Lbrace" if="xquery core fulltext update"/>
  <g:token name="Rbrace" if="xquery core fulltext" override="yes">
    <g:string>}</g:string>
  </g:token>
  <g:token name="RbraceErrorInContent" alias-for="Rbrace" if="xquery core"/>
  <g:token name="LCurlyBraceEscape" delimiter-type="hide" if="xquery" override="yes">
    <g:string>{{</g:string>
  </g:token>
  <g:token name="RCurlyBraceEscape" delimiter-type="hide" if="xquery" override="yes">
    <g:string>}}</g:string>
  </g:token>
  <g:token name="Amp" override="yes" if="core xquery" show="no">
    <g:string>&amp;</g:string>
  </g:token>
  <g:token name="LessThanOpOrTagO" override="yes">
    <g:string>&lt;</g:string>
  </g:token>
  <g:token name="StartTagOpen" alias-for="LessThanOpOrTagO" override="yes" if="xquery"/>
  <g:token name="AttrLTCharError" alias-for="LessThanOpOrTagO" override="yes" if="xquery"/>
  <g:token name="StartTagClose" if="xquery">
    <g:string>&gt;</g:string>
  </g:token>
  <g:token name="OpenQuot" delimiter-type="hide" if="xquery core">
    <g:string>"</g:string>
  </g:token>
  <g:token name="CloseQuot" delimiter-type="hide" if="xquery core">
    <g:string>"</g:string>
  </g:token>
  <g:token name="OpenApos" delimiter-type="hide" if="xquery">
    <g:string>'</g:string>
  </g:token>
  <g:token name="CloseApos" delimiter-type="hide" override="yes" if="xquery">
    <g:string>'</g:string>
  </g:token>
  <g:token name="ExtensionContentChar" if="xquery core" inline="true" value-type="string">
    <g:ref name="Char"/>
  </g:token>
  <g:token name="ElementContentChar" delimiter-type="hide" if="xquery core" inline="false" value-type="string" subtract-reg-expr="[{}&lt;&amp;]">
	<g:ref name="Char"/>
  </g:token>
  <g:token name="QuotAttrContentChar" delimiter-type="hide" if="xquery core" inline="false" value-type="string" subtract-reg-expr="[&quot;{}&lt;&amp;]">
    <g:ref name="Char"/>
  </g:token>
  <g:token name="AposAttrContentChar" delimiter-type="hide" if="xquery core" inline="false" value-type="string" subtract-reg-expr="['{}&lt;&amp;]">
    <g:ref name="Char"/>
  </g:token>
  <g:token name="CommentContentChar" delimiter-type="hide" if="xquery core">
    <g:ref name="Char" subtract-reg-expr="'-'"/>
  </g:token>
  <g:token name="EmptyTagClose" if="xquery">
    <g:string>/&gt;</g:string>
  </g:token>
  <g:token name="EndTagOpen" if="xquery">
    <g:string>&lt;/</g:string>
  </g:token>
  <g:token name="EndTagClose" if="xquery">
    <g:string>&gt;</g:string>
  </g:token>
  <g:token name="ValueIndicator" if="xquery">
    <g:string>=</g:string>
  </g:token>
  <g:token name="PragmaOpen" if="xquery core" override="yes">
    <g:string>(#</g:string>
  </g:token>
  <g:token name="PragmaClose" if="xquery core" override="yes">
    <g:string>#)</g:string>
  </g:token>
  <g:token name="XMLCommentDoubleDashError" delimiter-type="hide" if="xquery core">
    <g:char force-quote="single">-</g:char>
    <g:char force-quote="single">-</g:char>
  </g:token>
  <g:token name="CommentContentCharDash" delimiter-type="hide" if="xquery core">
    <g:char force-quote="single">-</g:char>
    <g:ref name="Char" subtract-reg-expr="'-'"/>
  </g:token>
  <g:token name="ProcessingInstructionStart" if="xquery core">
    <g:string>&lt;?</g:string>
  </g:token>
  <g:token name="ProcessingInstructionStartForElementContent" alias-for="ProcessingInstructionStart" if="xquery core"/>
  <g:token name="ProcessingInstructionEnd" if="xquery core">
    <g:string>?&gt;</g:string>
  </g:token>
  <g:token name="PIContentChar" if="xquery core" alias-for="Char"/>
  <g:token name="CDataSectionChar" if="xquery core" alias-for="Char"/>
  <g:token name="CdataSectionStart" if="xquery core">
    <g:string>&lt;![CDATA[</g:string>
  </g:token>
  <g:token name="CdataSectionStartForElementContent" alias-for="CdataSectionStart" if="xquery core"/>
  <!-- Recognizing it in content disallows ]]> in content same as XML. -->
  <g:token name="CdataSectionEnd" if="xquery core">
    <g:string>]]&gt;</g:string>
  </g:token>
  <g:token name="XmlCommentStart" if="xquery">
    <g:string>&lt;!--</g:string>
  </g:token>
  <g:token name="XmlCommentStartForElementContent" alias-for="XmlCommentStart" if="xquery"/>
  <g:token name="XmlCommentEnd" if="xquery">
    <g:string>--&gt;</g:string>
  </g:token>
  <g:token name="Comment" if="xquery xpath" inline="false" comment-id="comments" special="yes" type="skip-token" whitespace-spec="explicit" delimiter-type="delimiting">
    <g:ref name="CommentStart"/>
    <g:zeroOrMore name="OptionalCommentContent">
      <g:choice name="CharOrComment">
        <g:ref name="CommentContents"/>
        <g:ref name="Comment" notational-only="yes"/>
      </g:choice>
    </g:zeroOrMore>
    <g:ref name="CommentEnd"/>
  </g:token>
  <g:token name="CommentStart" special="yes" inline="true" type="skip-token" comment-id="comments">
    <g:string>(:</g:string>
  </g:token>
  <!-- For the moment removed special="yes" from CommentContent-->
  <g:token name="CommentContent" special="yes" inline="true" type="skip-token">
    <g:ref name="Char"/>
  </g:token>
  <g:token name="CommentEnd" special="yes" inline="true" type="skip-token">
    <g:string>:)</g:string>
  </g:token>
  <g:token name="Slash">
    <g:string>/</g:string>
  </g:token>
  <g:token name="SlashSlash">
    <g:string>//</g:string>
  </g:token>
  <g:token name="PITargetError" if="xquery core">
	<g:choice name="PITargetErrorVariations">
		<g:string>xml</g:string>
		<g:string>Xml</g:string>
		<g:string>xMl</g:string>
		<g:string>xmL</g:string>
		<g:string>XMl</g:string>
		<g:string>xML</g:string>
		<g:string>xMl</g:string>
		<g:string>XML</g:string>
		<g:string>XmL</g:string>
	</g:choice>
  </g:token>
  <g:token name="PITarget" delimiter-type="hide" inline="false" if="xquery core" value-type="string" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml#NT-PITarget" xgc-id="xml-version">
    <g:ref name="NCNameTok"/>
  </g:token>
  <g:token name="CharRef" if="xquery" inline="false" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml#NT-CharRef" xgc-id="xml-version" delimiter-type="hide">
    <g:string>&amp;#</g:string>
    <g:choice name="CharRefChars">
      <g:ref name="Digits"/>
      <g:sequence>
        <g:string>x</g:string>
        <g:ref name="HexDigits"/>
      </g:sequence>
    </g:choice>
    <g:string>;</g:string>
  </g:token>
  <g:token name="QNameToken" exposition-name="QName" delimiter-type="nondelimiting" inline="false" node-type="void" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml-names/#NT-QName" xgc-id="xml-version">
    <g:optional name="QNamePrefixAndDelimiter">
      <g:ref name="Prefix"/>
      <g:string>:</g:string>
    </g:optional>
    <g:ref name="LocalPart"/>
  </g:token>
  <g:token name="QNameForPragma" if="xquery core">
    <g:ref name="QNameToken"/>
  </g:token>
  <g:token name="TagQName" if="xquery">
    <g:ref name="QNameToken"/>
  </g:token>
  <g:token name="EndTagQName" if="xquery">
    <g:ref name="QNameToken"/>
  </g:token>
  <g:token name="NCNameTok" exposition-name="NCName" delimiter-type="nondelimiting" inline="false" value-type="string" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml-names/#NT-NCName" xgc-id="xml-version">
    <g:ref name="Nmstart"/>
    <g:zeroOrMore name="NCNameTail">
      <g:ref name="Nmchar"/>
    </g:zeroOrMore>
  </g:token>
  <g:token name="NCNameColonStar" value-type="string" inline="true">
    <g:ref name="NCNameTok"/>
    <g:string>:</g:string>
    <g:string>*</g:string>
  </g:token>
  <g:token name="StarColonNCName" value-type="string" if="xpath xquery core" inline="true">
    <g:string>*</g:string>
    <g:string>:</g:string>
    <g:ref name="NCNameTok"/>
  </g:token>
  <g:token name="S" inline="false" if="xquery core" is-xml="yes" xgc-id="xml-version" xhref="http://www.w3.org/TR/REC-xml#NT-S" delimiter-type="delimiting">
    <g:oneOrMore name="SignificantWhitespace">
      <g:ref name="WhitespaceChar"/>
    </g:oneOrMore>
  </g:token>
  <g:token name="SForPragma" alias-for="S" if="xquery core"/>
  <g:token name="SForPI" alias-for="S" if="xquery core"/>
  <g:token name="Char" inline="false" delimiter-type="hide" value-type="string" is-xml="yes" xgc-id="xml-version" xhref="http://www.w3.org/TR/REC-xml#NT-Char">
    <g:charClass>
      <g:charCode value="0009"/>
      <g:charCode value="000D"/>
      <g:charCode value="000A"/>
      <!-- This isn't quite right, but JavaCC doesn't understand surrogates. -->
      <g:charCodeRange minValue="0020" maxValue="FFFD"/>
    </g:charClass>
  </g:token>
  <g:token name="Digits" delimiter-type="hide" inline="false" is-local-to-terminal-symbol="yes">
    <g:oneOrMore name="DigitsString">
      <g:charClass>
        <g:charRange minChar="0" maxChar="9"/>
      </g:charClass>
    </g:oneOrMore>
  </g:token>
  <g:token name="CommentContents" special="yes" inline="false" if="xquery xpath" is-local-to-terminal-symbol="yes">
    <g:oneOrMore name="CommentContentBody" subtract-reg-expr="(Char* ('(:' | ':)') Char*)">
      <g:ref name="CommentContent"/>
    </g:oneOrMore>
  </g:token>
  <!-- It would be nice to not take character content runs one character
       at a time.  However, it seems difficult to say, "all these characters
       but these three", at least in JavaCC. -->
  <g:token name="WhitespaceChar" inline="false" visible="false">
    <g:charClass>
      <!-- NOTE: From XML 1.1: -->
      <!-- To simplify the tasks of applications, the XML processor MUST behave as if it normalized  -->
      <!-- all line breaks in external parsed entities (including the document entity) on input,  -->
      <!-- before parsing, by translating all of the following to a single #xA character: -->
      <!-- 1. the two-character sequence #xD #xA -->
      <!-- 2. the two-character sequence #xD #x85 -->
      <!-- 3. the single character #x85 -->
      <!-- 4. the single character #x2028 -->
      <!-- 5. any #xD character that is not immediately followed by #xA or #x85. -->
      <g:charCode value="0009"/>
      <g:charCode value="000D"/>
      <g:charCode value="000A"/>
      <!-- char xml:space="preserve"> </g:char -->
      <!-- SGML mode in EMacs doesn't like xml:space, so
                             we avoid it for now. -->
      <g:charCode value="0020"/>
    </g:charClass>
  </g:token>
  <g:token name="Letter" inline="false" is-macro="yes" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml#NT-Letter" xgc-id="xml-version" visible="false">
    <g:choice name="LetterChars">
      <g:ref name="BaseChar"/>
      <g:ref name="Ideographic"/>
    </g:choice>
  </g:token>
  <g:token name="BaseChar" inline="false" is-macro="yes" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml#NT-BaseChar" xgc-id="xml-version" visible="false">
    <g:charClass>
      <g:charCodeRange minValue="0041" maxValue="005a"/>
      <g:charCodeRange minValue="0061" maxValue="007a"/>
      <g:charCodeRange minValue="00c0" maxValue="00d6"/>
      <g:charCodeRange minValue="00d8" maxValue="00f6"/>
      <g:charCodeRange minValue="00f8" maxValue="00ff"/>
      <g:charCodeRange minValue="0100" maxValue="0131"/>
      <g:charCodeRange minValue="0134" maxValue="013e"/>
      <g:charCodeRange minValue="0141" maxValue="0148"/>
      <g:charCodeRange minValue="014a" maxValue="017e"/>
      <g:charCodeRange minValue="0180" maxValue="01c3"/>
      <g:charCodeRange minValue="01cd" maxValue="01f0"/>
      <g:charCodeRange minValue="01f4" maxValue="01f5"/>
      <g:charCodeRange minValue="01fa" maxValue="0217"/>
      <g:charCodeRange minValue="0250" maxValue="02a8"/>
      <g:charCodeRange minValue="02bb" maxValue="02c1"/>
      <g:charCode value="0386"/>
      <g:charCodeRange minValue="0388" maxValue="038a"/>
      <g:charCode value="038c"/>
      <g:charCodeRange minValue="038e" maxValue="03a1"/>
      <g:charCodeRange minValue="03a3" maxValue="03ce"/>
      <g:charCodeRange minValue="03d0" maxValue="03d6"/>
      <g:charCode value="03da"/>
      <g:charCode value="03dc"/>
      <g:charCode value="03de"/>
      <g:charCode value="03e0"/>
      <g:charCodeRange minValue="03e2" maxValue="03f3"/>
      <g:charCodeRange minValue="0401" maxValue="040c"/>
      <g:charCodeRange minValue="040e" maxValue="044f"/>
      <g:charCodeRange minValue="0451" maxValue="045c"/>
      <g:charCodeRange minValue="045e" maxValue="0481"/>
      <g:charCodeRange minValue="0490" maxValue="04c4"/>
      <g:charCodeRange minValue="04c7" maxValue="04c8"/>
      <g:charCodeRange minValue="04cb" maxValue="04cc"/>
      <g:charCodeRange minValue="04d0" maxValue="04eb"/>
      <g:charCodeRange minValue="04ee" maxValue="04f5"/>
      <g:charCodeRange minValue="04f8" maxValue="04f9"/>
      <g:charCodeRange minValue="0531" maxValue="0556"/>
      <g:charCode value="0559"/>
      <g:charCodeRange minValue="0561" maxValue="0586"/>
      <g:charCodeRange minValue="05d0" maxValue="05ea"/>
      <g:charCodeRange minValue="05f0" maxValue="05f2"/>
      <g:charCodeRange minValue="0621" maxValue="063a"/>
      <g:charCodeRange minValue="0641" maxValue="064a"/>
      <g:charCodeRange minValue="0671" maxValue="06b7"/>
      <g:charCodeRange minValue="06ba" maxValue="06be"/>
      <g:charCodeRange minValue="06c0" maxValue="06ce"/>
      <g:charCodeRange minValue="06d0" maxValue="06d3"/>
      <g:charCode value="06d5"/>
      <g:charCodeRange minValue="06e5" maxValue="06e6"/>
      <g:charCodeRange minValue="0905" maxValue="0939"/>
      <g:charCode value="093d"/>
      <g:charCodeRange minValue="0958" maxValue="0961"/>
      <g:charCodeRange minValue="0985" maxValue="098c"/>
      <g:charCodeRange minValue="098f" maxValue="0990"/>
      <g:charCodeRange minValue="0993" maxValue="09a8"/>
      <g:charCodeRange minValue="09aa" maxValue="09b0"/>
      <g:charCode value="09b2"/>
      <g:charCodeRange minValue="09b6" maxValue="09b9"/>
      <g:charCodeRange minValue="09dc" maxValue="09dd"/>
      <g:charCodeRange minValue="09df" maxValue="09e1"/>
      <g:charCodeRange minValue="09f0" maxValue="09f1"/>
      <g:charCodeRange minValue="0a05" maxValue="0a0a"/>
      <g:charCodeRange minValue="0a0f" maxValue="0a10"/>
      <g:charCodeRange minValue="0a13" maxValue="0a28"/>
      <g:charCodeRange minValue="0a2a" maxValue="0a30"/>
      <g:charCodeRange minValue="0a32" maxValue="0a33"/>
      <g:charCodeRange minValue="0a35" maxValue="0a36"/>
      <g:charCodeRange minValue="0a38" maxValue="0a39"/>
      <g:charCodeRange minValue="0a59" maxValue="0a5c"/>
      <g:charCode value="0a5e"/>
      <g:charCodeRange minValue="0a72" maxValue="0a74"/>
      <g:charCodeRange minValue="0a85" maxValue="0a8b"/>
      <g:charCode value="0a8d"/>
      <g:charCodeRange minValue="0a8f" maxValue="0a91"/>
      <g:charCodeRange minValue="0a93" maxValue="0aa8"/>
      <g:charCodeRange minValue="0aaa" maxValue="0ab0"/>
      <g:charCodeRange minValue="0ab2" maxValue="0ab3"/>
      <g:charCodeRange minValue="0ab5" maxValue="0ab9"/>
      <g:charCode value="0abd"/>
      <g:charCode value="0ae0"/>
      <g:charCodeRange minValue="0b05" maxValue="0b0c"/>
      <g:charCodeRange minValue="0b0f" maxValue="0b10"/>
      <g:charCodeRange minValue="0b13" maxValue="0b28"/>
      <g:charCodeRange minValue="0b2a" maxValue="0b30"/>
      <g:charCodeRange minValue="0b32" maxValue="0b33"/>
      <g:charCodeRange minValue="0b36" maxValue="0b39"/>
      <g:charCode value="0b3d"/>
      <g:charCodeRange minValue="0b5c" maxValue="0b5d"/>
      <g:charCodeRange minValue="0b5f" maxValue="0b61"/>
      <g:charCodeRange minValue="0b85" maxValue="0b8a"/>
      <g:charCodeRange minValue="0b8e" maxValue="0b90"/>
      <g:charCodeRange minValue="0b92" maxValue="0b95"/>
      <g:charCodeRange minValue="0b99" maxValue="0b9a"/>
      <g:charCode value="0b9c"/>
      <g:charCodeRange minValue="0b9e" maxValue="0b9f"/>
      <g:charCodeRange minValue="0ba3" maxValue="0ba4"/>
      <g:charCodeRange minValue="0ba8" maxValue="0baa"/>
      <g:charCodeRange minValue="0bae" maxValue="0bb5"/>
      <g:charCodeRange minValue="0bb7" maxValue="0bb9"/>
      <g:charCodeRange minValue="0c05" maxValue="0c0c"/>
      <g:charCodeRange minValue="0c0e" maxValue="0c10"/>
      <g:charCodeRange minValue="0c12" maxValue="0c28"/>
      <g:charCodeRange minValue="0c2a" maxValue="0c33"/>
      <g:charCodeRange minValue="0c35" maxValue="0c39"/>
      <g:charCodeRange minValue="0c60" maxValue="0c61"/>
      <g:charCodeRange minValue="0c85" maxValue="0c8c"/>
      <g:charCodeRange minValue="0c8e" maxValue="0c90"/>
      <g:charCodeRange minValue="0c92" maxValue="0ca8"/>
      <g:charCodeRange minValue="0caa" maxValue="0cb3"/>
      <g:charCodeRange minValue="0cb5" maxValue="0cb9"/>
      <g:charCode value="0cde"/>
      <g:charCodeRange minValue="0ce0" maxValue="0ce1"/>
      <g:charCodeRange minValue="0d05" maxValue="0d0c"/>
      <g:charCodeRange minValue="0d0e" maxValue="0d10"/>
      <g:charCodeRange minValue="0d12" maxValue="0d28"/>
      <g:charCodeRange minValue="0d2a" maxValue="0d39"/>
      <g:charCodeRange minValue="0d60" maxValue="0d61"/>
      <g:charCodeRange minValue="0e01" maxValue="0e2e"/>
      <g:charCode value="0e30"/>
      <g:charCodeRange minValue="0e32" maxValue="0e33"/>
      <g:charCodeRange minValue="0e40" maxValue="0e45"/>
      <g:charCodeRange minValue="0e81" maxValue="0e82"/>
      <g:charCode value="0e84"/>
      <g:charCodeRange minValue="0e87" maxValue="0e88"/>
      <g:charCode value="0e8a"/>
      <g:charCode value="0e8d"/>
      <g:charCodeRange minValue="0e94" maxValue="0e97"/>
      <g:charCodeRange minValue="0e99" maxValue="0e9f"/>
      <g:charCodeRange minValue="0ea1" maxValue="0ea3"/>
      <g:charCode value="0ea5"/>
      <g:charCode value="0ea7"/>
      <g:charCodeRange minValue="0eaa" maxValue="0eab"/>
      <g:charCodeRange minValue="0ead" maxValue="0eae"/>
      <g:charCode value="0eb0"/>
      <g:charCodeRange minValue="0eb2" maxValue="0eb3"/>
      <g:charCode value="0ebd"/>
      <g:charCodeRange minValue="0ec0" maxValue="0ec4"/>
      <g:charCodeRange minValue="0f40" maxValue="0f47"/>
      <g:charCodeRange minValue="0f49" maxValue="0f69"/>
      <g:charCodeRange minValue="10a0" maxValue="10c5"/>
      <g:charCodeRange minValue="10d0" maxValue="10f6"/>
      <g:charCode value="1100"/>
      <g:charCodeRange minValue="1102" maxValue="1103"/>
      <g:charCodeRange minValue="1105" maxValue="1107"/>
      <g:charCode value="1109"/>
      <g:charCodeRange minValue="110b" maxValue="110c"/>
      <g:charCodeRange minValue="110e" maxValue="1112"/>
      <g:charCode value="113c"/>
      <g:charCode value="113e"/>
      <g:charCode value="1140"/>
      <g:charCode value="114c"/>
      <g:charCode value="114e"/>
      <g:charCode value="1150"/>
      <g:charCodeRange minValue="1154" maxValue="1155"/>
      <g:charCode value="1159"/>
      <g:charCodeRange minValue="115f" maxValue="1161"/>
      <g:charCode value="1163"/>
      <g:charCode value="1165"/>
      <g:charCode value="1167"/>
      <g:charCode value="1169"/>
      <g:charCodeRange minValue="116d" maxValue="116e"/>
      <g:charCodeRange minValue="1172" maxValue="1173"/>
      <g:charCode value="1175"/>
      <g:charCode value="119e"/>
      <g:charCode value="11a8"/>
      <g:charCode value="11ab"/>
      <g:charCodeRange minValue="11ae" maxValue="11af"/>
      <g:charCodeRange minValue="11b7" maxValue="11b8"/>
      <g:charCode value="11ba"/>
      <g:charCodeRange minValue="11bc" maxValue="11c2"/>
      <g:charCode value="11eb"/>
      <g:charCode value="11f0"/>
      <g:charCode value="11f9"/>
      <g:charCodeRange minValue="1e00" maxValue="1e9b"/>
      <g:charCodeRange minValue="1ea0" maxValue="1ef9"/>
      <g:charCodeRange minValue="1f00" maxValue="1f15"/>
      <g:charCodeRange minValue="1f18" maxValue="1f1d"/>
      <g:charCodeRange minValue="1f20" maxValue="1f45"/>
      <g:charCodeRange minValue="1f48" maxValue="1f4d"/>
      <g:charCodeRange minValue="1f50" maxValue="1f57"/>
      <g:charCode value="1f59"/>
      <g:charCode value="1f5b"/>
      <g:charCode value="1f5d"/>
      <g:charCodeRange minValue="1f5f" maxValue="1f7d"/>
      <g:charCodeRange minValue="1f80" maxValue="1fb4"/>
      <g:charCodeRange minValue="1fb6" maxValue="1fbc"/>
      <g:charCode value="1fbe"/>
      <g:charCodeRange minValue="1fc2" maxValue="1fc4"/>
      <g:charCodeRange minValue="1fc6" maxValue="1fcc"/>
      <g:charCodeRange minValue="1fd0" maxValue="1fd3"/>
      <g:charCodeRange minValue="1fd6" maxValue="1fdb"/>
      <g:charCodeRange minValue="1fe0" maxValue="1fec"/>
      <g:charCodeRange minValue="1ff2" maxValue="1ff4"/>
      <g:charCodeRange minValue="1ff6" maxValue="1ffc"/>
      <g:charCode value="2126"/>
      <g:charCodeRange minValue="212a" maxValue="212b"/>
      <g:charCode value="212e"/>
      <g:charCodeRange minValue="2180" maxValue="2182"/>
      <g:charCodeRange minValue="3041" maxValue="3094"/>
      <g:charCodeRange minValue="30a1" maxValue="30fa"/>
      <g:charCodeRange minValue="3105" maxValue="312c"/>
      <g:charCodeRange minValue="ac00" maxValue="d7a3"/>
    </g:charClass>
  </g:token>
  <g:token name="Ideographic" inline="false" is-macro="yes" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml#NT-Ideographic" xgc-id="xml-version" visible="false">
    <g:charClass>
      <g:charCodeRange minValue="4e00" maxValue="9fa5"/>
      <g:charCode value="3007"/>
      <g:charCodeRange minValue="3021" maxValue="3029"/>
    </g:charClass>
  </g:token>
  <g:token name="CombiningChar" inline="false" is-macro="yes" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml#NT-CombiningChar" xgc-id="xml-version" visible="false">
    <g:charClass>
      <g:charCodeRange minValue="0300" maxValue="0345"/>
      <g:charCodeRange minValue="0360" maxValue="0361"/>
      <g:charCodeRange minValue="0483" maxValue="0486"/>
      <g:charCodeRange minValue="0591" maxValue="05a1"/>
      <g:charCodeRange minValue="05a3" maxValue="05b9"/>
      <g:charCodeRange minValue="05bb" maxValue="05bd"/>
      <g:charCode value="05bf"/>
      <g:charCodeRange minValue="05c1" maxValue="05c2"/>
      <g:charCode value="05c4"/>
      <g:charCodeRange minValue="064b" maxValue="0652"/>
      <g:charCode value="0670"/>
      <g:charCodeRange minValue="06d6" maxValue="06dc"/>
      <g:charCodeRange minValue="06dd" maxValue="06df"/>
      <g:charCodeRange minValue="06e0" maxValue="06e4"/>
      <g:charCodeRange minValue="06e7" maxValue="06e8"/>
      <g:charCodeRange minValue="06ea" maxValue="06ed"/>
      <g:charCodeRange minValue="0901" maxValue="0903"/>
      <g:charCode value="093c"/>
      <g:charCodeRange minValue="093e" maxValue="094c"/>
      <g:charCode value="094d"/>
      <g:charCodeRange minValue="0951" maxValue="0954"/>
      <g:charCodeRange minValue="0962" maxValue="0963"/>
      <g:charCodeRange minValue="0981" maxValue="0983"/>
      <g:charCode value="09bc"/>
      <g:charCode value="09be"/>
      <g:charCode value="09bf"/>
      <g:charCodeRange minValue="09c0" maxValue="09c4"/>
      <g:charCodeRange minValue="09c7" maxValue="09c8"/>
      <g:charCodeRange minValue="09cb" maxValue="09cd"/>
      <g:charCode value="09d7"/>
      <g:charCodeRange minValue="09e2" maxValue="09e3"/>
      <g:charCode value="0a02"/>
      <g:charCode value="0a3c"/>
      <g:charCode value="0a3e"/>
      <g:charCode value="0a3f"/>
      <g:charCodeRange minValue="0a40" maxValue="0a42"/>
      <g:charCodeRange minValue="0a47" maxValue="0a48"/>
      <g:charCodeRange minValue="0a4b" maxValue="0a4d"/>
      <g:charCodeRange minValue="0a70" maxValue="0a71"/>
      <g:charCodeRange minValue="0a81" maxValue="0a83"/>
      <g:charCode value="0abc"/>
      <g:charCodeRange minValue="0abe" maxValue="0ac5"/>
      <g:charCodeRange minValue="0ac7" maxValue="0ac9"/>
      <g:charCodeRange minValue="0acb" maxValue="0acd"/>
      <g:charCodeRange minValue="0b01" maxValue="0b03"/>
      <g:charCode value="0b3c"/>
      <g:charCodeRange minValue="0b3e" maxValue="0b43"/>
      <g:charCodeRange minValue="0b47" maxValue="0b48"/>
      <g:charCodeRange minValue="0b4b" maxValue="0b4d"/>
      <g:charCodeRange minValue="0b56" maxValue="0b57"/>
      <g:charCodeRange minValue="0b82" maxValue="0b83"/>
      <g:charCodeRange minValue="0bbe" maxValue="0bc2"/>
      <g:charCodeRange minValue="0bc6" maxValue="0bc8"/>
      <g:charCodeRange minValue="0bca" maxValue="0bcd"/>
      <g:charCode value="0bd7"/>
      <g:charCodeRange minValue="0c01" maxValue="0c03"/>
      <g:charCodeRange minValue="0c3e" maxValue="0c44"/>
      <g:charCodeRange minValue="0c46" maxValue="0c48"/>
      <g:charCodeRange minValue="0c4a" maxValue="0c4d"/>
      <g:charCodeRange minValue="0c55" maxValue="0c56"/>
      <g:charCodeRange minValue="0c82" maxValue="0c83"/>
      <g:charCodeRange minValue="0cbe" maxValue="0cc4"/>
      <g:charCodeRange minValue="0cc6" maxValue="0cc8"/>
      <g:charCodeRange minValue="0cca" maxValue="0ccd"/>
      <g:charCodeRange minValue="0cd5" maxValue="0cd6"/>
      <g:charCodeRange minValue="0d02" maxValue="0d03"/>
      <g:charCodeRange minValue="0d3e" maxValue="0d43"/>
      <g:charCodeRange minValue="0d46" maxValue="0d48"/>
      <g:charCodeRange minValue="0d4a" maxValue="0d4d"/>
      <g:charCode value="0d57"/>
      <g:charCode value="0e31"/>
      <g:charCodeRange minValue="0e34" maxValue="0e3a"/>
      <g:charCodeRange minValue="0e47" maxValue="0e4e"/>
      <g:charCode value="0eb1"/>
      <g:charCodeRange minValue="0eb4" maxValue="0eb9"/>
      <g:charCodeRange minValue="0ebb" maxValue="0ebc"/>
      <g:charCodeRange minValue="0ec8" maxValue="0ecd"/>
      <g:charCodeRange minValue="0f18" maxValue="0f19"/>
      <g:charCode value="0f35"/>
      <g:charCode value="0f37"/>
      <g:charCode value="0f39"/>
      <g:charCode value="0f3e"/>
      <g:charCode value="0f3f"/>
      <g:charCodeRange minValue="0f71" maxValue="0f84"/>
      <g:charCodeRange minValue="0f86" maxValue="0f8b"/>
      <g:charCodeRange minValue="0f90" maxValue="0f95"/>
      <g:charCode value="0f97"/>
      <g:charCodeRange minValue="0f99" maxValue="0fad"/>
      <g:charCodeRange minValue="0fb1" maxValue="0fb7"/>
      <g:charCode value="0fb9"/>
      <g:charCodeRange minValue="20d0" maxValue="20dc"/>
      <g:charCode value="20e1"/>
      <g:charCodeRange minValue="302a" maxValue="302f"/>
      <g:charCode value="3099"/>
      <g:charCode value="309a"/>
    </g:charClass>
  </g:token>
  <g:token name="Digit" inline="false" is-macro="yes" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml#NT-Digit" visible="false">
    <g:charClass>
      <g:charCodeRange minValue="0030" maxValue="0039"/>
      <g:charCodeRange minValue="0660" maxValue="0669"/>
      <g:charCodeRange minValue="06f0" maxValue="06f9"/>
      <g:charCodeRange minValue="0966" maxValue="096f"/>
      <g:charCodeRange minValue="09e6" maxValue="09ef"/>
      <g:charCodeRange minValue="0a66" maxValue="0a6f"/>
      <g:charCodeRange minValue="0ae6" maxValue="0aef"/>
      <g:charCodeRange minValue="0b66" maxValue="0b6f"/>
      <g:charCodeRange minValue="0be7" maxValue="0bef"/>
      <g:charCodeRange minValue="0c66" maxValue="0c6f"/>
      <g:charCodeRange minValue="0ce6" maxValue="0cef"/>
      <g:charCodeRange minValue="0d66" maxValue="0d6f"/>
      <g:charCodeRange minValue="0e50" maxValue="0e59"/>
      <g:charCodeRange minValue="0ed0" maxValue="0ed9"/>
      <g:charCodeRange minValue="0f20" maxValue="0f29"/>
    </g:charClass>
  </g:token>
  <g:token name="Extender" inline="false" is-macro="yes" is-xml="yes" xhref="http://www.w3.org/TR/REC-xml#NT-Extender" xgc-id="xml-version" visible="false">
    <g:charClass>
      <g:charCode value="00b7"/>
      <g:charCode value="02d0"/>
      <g:charCode value="02d1"/>
      <g:charCode value="0387"/>
      <g:charCode value="0640"/>
      <g:charCode value="0e46"/>
      <g:charCode value="0ec6"/>
      <g:charCode value="3005"/>
      <g:charCodeRange minValue="3031" maxValue="3035"/>
      <g:charCodeRange minValue="309d" maxValue="309e"/>
      <g:charCodeRange minValue="30fc" maxValue="30fe"/>
    </g:charClass>
  </g:token>
  <!-- g:token name="NotOperatorKeyword" show="no">
    <g:oneOrMore name="NotOperatorKeywordSequence">
      <g:charClass>
        <g:charRange minChar="0" maxChar="9"/>
        <g:charRange minChar="a" maxChar="z"/>
        <g:charRange minChar="A" maxChar="Z"/>
      </g:charClass>
    </g:oneOrMore>
  </g:token -->

  <g:token name="NotNumber" show="no">
    <g:choice name="DoubleStringNotNumber">
      <g:sequence>
        <g:string>.</g:string>
        <g:ref name="Digits"/>
      </g:sequence>
      <g:sequence>
        <g:ref name="Digits"/>
        <g:optional name="DoubleOptionFractionPartNotNumber">
          <g:string>.</g:string>
          <g:zeroOrMore name="DoubleFractionPartNotNumber">
            <g:charClass>
              <g:charRange minChar="0" maxChar="9"/>
            </g:charClass>
          </g:zeroOrMore>
        </g:optional>
      </g:sequence>
    </g:choice>
    <g:optional name="NotNumberOptionalFractionPart">
      <g:charClass>
        <g:char>e</g:char>
        <g:char>E</g:char>
      </g:charClass>
      <g:optional name="DoubleNegOrPosNotNumber">
        <g:charClass>
          <g:char>+</g:char>
          <g:char>-</g:char>
        </g:charClass>
      </g:optional>
      <g:ref name="Digits"/>
    </g:optional>
    <g:charClass>
      <g:charRange minChar="a" maxChar="z"/>
      <g:charRange minChar="A" maxChar="Z"/>
    </g:charClass>
    <g:zeroOrMore name="NotNumberTail">
      <g:charClass>
        <g:charRange minChar="0" maxChar="9"/>
        <g:charRange minChar="a" maxChar="z"/>
        <g:charRange minChar="A" maxChar="Z"/>
      </g:charClass>
    </g:zeroOrMore>
  </g:token>
  <!-- ================================================
       These states define the lex-time disambiguations of tokens.  The are
       probably non-normative.
  ================================================ -->
  <g:state-list>
    <g:state name="ANY" show="no">
      <g:description>This state is for very general patterns that can be
                recognized in any state, but are not recognized as significant
                patterns by themselves in the grammar. </g:description>
      <g:transition>
        <g:description>No state change.</g:description>
        <g:tref name="WhitespaceChar"/>
        <g:tref name="Nmstart"/>
        <g:tref name="NCNameTok"/>
        <g:tref name="Nmchar"/>
        <g:tref name="Prefix"/>
        <g:tref name="LocalPart"/>
        <g:tref name="Digits"/>
        <g:tref name="Letter"/>
        <g:tref name="BaseChar"/>
        <g:tref name="Ideographic"/>
        <g:tref name="CombiningChar"/>
        <g:tref name="Digit"/>
        <g:tref name="Extender"/>
        <g:tref name="HexDigits"/>
        <g:tref name="Comment"/>
        <g:tref name="CommentContents" if="xquery xpath"/>
		<g:tref name="EscapeQuot" if="xpath"/>
		<g:tref name="EscapeApos" if="xpath"/>
		<!-- g:tref name="CommentContent"/>
        <g:tref name="CommentStart"/>
        <g:tref name="CommentEnd"/ -->
        <!-- g:tref name="SForExt"/ -->
      </g:transition>
    </g:state>
    <g:state name="DEFAULT">
      <g:description>XXX</g:description>
      <g:transition next-state="XML_COMMENT" action="pushState(DEFAULT)" if="xquery core">
        <g:tref name="XmlCommentStart"/>
      </g:transition>
      <g:transition next-state="EXPR_COMMENT" action="pushState">
        <g:tref name="CommentStart"/>
      </g:transition>
      <g:transition next-state="PROCESSING_INSTRUCTION" action="pushState(DEFAULT)" if="xquery core">
        <g:tref name="ProcessingInstructionStart"/>
      </g:transition>
      <g:transition next-state="CDATA_SECTION" action="pushState(DEFAULT)" if="xquery core">
        <g:tref name="CdataSectionStart"/>
      </g:transition>
      <g:transition next-state="START_TAG" action="pushState(DEFAULT)" if="xquery core">
        <g:tref name="LessThanOpOrTagO"/>
      </g:transition>
      <g:transition next-state="DEFAULT" action="pushState(DEFAULT)" if="xpath">
        <g:tref name="LessThanOpOrTagO"/>
      </g:transition>
      <g:transition next-state="PRAGMA"  if="xquery core">
        <g:tref name="PragmaOpen"/>
      </g:transition>
      <g:transition action="popState">
        <g:tref name="Rbrace"/>
      </g:transition>
	  <g:transition next-state="DEFAULT" action="pushState(DEFAULT)">
        <g:tref name="LbraceExprEnclosure"/>
      </g:transition>

      <g:transition>
        <g:tref name="Slash"/>
        <g:tref name="SlashSlash"/>
        <g:tref name="IntegerLiteral"/>
        <g:tref name="DecimalLiteral"/>
        <g:tref name="DoubleLiteral" if="xpath xquery core"/>
        <g:tref name="URILiteral"/>
        <g:tref name="StringLiteral"/>
        <!-- g:tref name="NotOccurrenceIndicator"/ -->

        <g:tref name="QNameToken"/>
        <g:tref name="NCNameColonStar"/>
        <g:tref name="StarColonNCName"/>
        <g:tref name="S" if="xquery core"/>
        <!-- g:tref name="NotOperatorKeyword"/ -->
        <g:tref name="NotNumber"/>
        <g:tref name="Char"/>

        <g:tref name="CharRef" if="xquery"/>
        <g:tref name="PredefinedEntityRef" if="xquery"/>

        <g:tref name="Minus"/>
        <g:tref name="Plus"/>
		<g:tref name="External"/>

		<g:tref name="Ascending" if="xquery core"/>
		<g:tref name="Descending" if="xquery core"/>
		<g:tref name="Greatest" if="xquery core"/>
		<g:tref name="Least" if="xquery core fulltext"/>

      </g:transition>
	</g:state>
    <g:state name="START_TAG" if="xquery core">
      <g:description>This state allows attributes in the native XML syntax,
                and marks the beginning of an element construction. Element
                constructors also push the current state, popping it at the
                conclusion of an end tag. In the START_TAG state, the string "&gt;" is
                recognized as a token which is associated with the transition to
                the original state. </g:description>
      <g:transition action="popState">
        <g:tref name="EmptyTagClose"/>
      </g:transition>
      <g:transition next-state="ELEMENT_CONTENT">
        <g:tref name="StartTagClose"/>
      </g:transition>
      <g:transition next-state="QUOT_ATTRIBUTE_CONTENT">
        <g:tref name="OpenQuot"/>
      </g:transition>
      <g:transition next-state="APOS_ATTRIBUTE_CONTENT">
        <g:tref name="OpenApos"/>
      </g:transition>
      <g:transition next-state="START_TAG">
        <g:tref name="ValueIndicator"/>
      </g:transition>
      <g:transition>
        <g:description>No state change.</g:description>
        <g:tref name="S"/>
        <g:tref name="TagQName"/>
      </g:transition>
    </g:state>

    <g:state name="ELEMENT_CONTENT" if="xquery core">
      <g:description>This state allows XML-like content, without these
                characters being misinterpreted as expressions. The character "{"
                marks a transition to the OPERAND state, i.e. the start of an
                embedded expression, and the "}" character pops back to the
                ELEMENT_CONTENT state. To allow curly braces to be used as
                character content, a double left or right curly brace is
                interpreted as a single curly brace character. The string "&lt;/"
                is interpreted as the beginning of an end tag, which is associated
                with a transition to the END_TAG state.</g:description>
      <g:transition next-state="END_TAG">
        <g:tref name="EndTagOpen"/>
      </g:transition>
      <g:transition next-state="DEFAULT" action="pushState">
        <g:description>Transition to an Element Value
                    Template.</g:description>
        <g:tref name="Lbrace"/>
		<g:tref name="RbraceErrorInContent"/>
      </g:transition>
      <g:transition next-state="XML_COMMENT" action="pushState">
        <g:tref name="XmlCommentStartForElementContent"/>
      </g:transition>
      <g:transition next-state="PROCESSING_INSTRUCTION" action="pushState">
        <g:tref name="ProcessingInstructionStartForElementContent"/>
      </g:transition>
      <g:transition next-state="CDATA_SECTION" action="pushState">
        <g:tref name="CdataSectionStartForElementContent"/>
      </g:transition>
      <g:transition next-state="START_TAG" action="pushState">
        <g:tref name="StartTagOpen"/>
      </g:transition>
      <g:transition next-state="ELEMENT_CONTENT">
        <g:tref name="ElementContentChar"/>
      </g:transition>
      <g:transition>
        <g:description>No state change.</g:description>
        <g:tref name="PredefinedEntityRef" if="xquery"/>
        <g:tref name="CharRef" if="xquery core"/>
        <g:tref name="LCurlyBraceEscape" if="xquery"/>
        <g:tref name="RCurlyBraceEscape" if="xquery"/>
        <g:tref name="Amp"/>
      </g:transition>
    </g:state>
    <g:state name="END_TAG" if="xquery core">
      <g:description>When the end tag is terminated, the state is popped to
                the state that was pushed at the start of the corresponding start
                tag.</g:description>
      <g:transition action="popState">
        <g:tref name="EndTagClose"/>
      </g:transition>
      <g:transition>
        <g:description>No state change.</g:description>
        <g:tref name="S"/>
        <g:tref name="EndTagQName"/>
      </g:transition>
    </g:state>
    <g:state name="XML_COMMENT" if="xquery core">
      <g:description>The "&lt;--" token marks the beginning of an XML
                Comment, and the "--&gt;" token marks the end. This allows no special
                interpretation of other characters in this state.</g:description>
      <g:transition action="popState">
        <g:tref name="XmlCommentEnd"/>
      </g:transition>
      <g:transition next-state="XML_COMMENT">
        <g:tref name="CommentContentChar"/>
        <g:tref name="CommentContentCharDash"/>
        <g:tref name="XMLCommentDoubleDashError"/>
      </g:transition>
    </g:state>
    <g:state name="EXPR_COMMENT">
      <g:description>The "(:" token marks the beginning of an expression
                Comment, and the ":)" token marks the end. This allows no special
                interpretation of other characters in this state.</g:description>
      <g:transition action="popState">
        <g:tref name="CommentEnd"/>
      </g:transition>
      <g:transition next-state="EXPR_COMMENT" action="pushState">
        <g:tref name="CommentStart"/>
      </g:transition>
      <g:transition>
        <g:description>No state change.</g:description>
        <g:tref name="CommentContent"/>
      </g:transition>
    </g:state>
    <g:state name="PROCESSING_INSTRUCTION" if="xquery core">
      <g:description>In this state, only patterns that are legal in a
                processing instruction name are recognized.</g:description>
      <g:transition next-state="PROCESSING_INSTRUCTION_CONTENT">
        <g:tref name="SForPI"/>
      </g:transition>
      <g:transition action="popState">
        <g:tref name="ProcessingInstructionEnd"/>
      </g:transition>
      <g:transition next-state="PROCESSING_INSTRUCTION">
        <g:tref name="PITargetError"/>
        <g:tref name="PITarget"/>
      </g:transition>
    </g:state>
    <g:state name="PROCESSING_INSTRUCTION_CONTENT" if="xquery core">
      <g:description>In this state, only characters are that are legal in
                processing instruction content are recognized.</g:description>
      <g:transition action="popState">
        <g:tref name="ProcessingInstructionEnd"/>
      </g:transition>
      <g:transition next-state="PROCESSING_INSTRUCTION_CONTENT">
        <g:tref name="PIContentChar"/>
      </g:transition>
    </g:state>
    <g:state name="CDATA_SECTION" if="xquery core">
      <g:description>In this state, only lexemes that are legal in a CDATA
                section are recognized.</g:description>
      <g:transition action="popState">
        <g:tref name="CdataSectionEnd"/>
      </g:transition>
      <g:transition next-state="CDATA_SECTION">
        <g:tref name="CDataSectionChar"/>
      </g:transition>
    </g:state>
    <g:state name="QUOT_ATTRIBUTE_CONTENT"  if="xquery core">
      <g:description>This state allows content legal for attributes. The
                character "{" marks a transition to the OPERAND state, i.e. the
                start of an embedded expression, and the "}" character pops back to
                the original state. To allow curly braces to be used as character
                content, a double left or right curly brace is interpreted as a
                single curly brace character. This state is the same as
                APOS_ATTRIBUTE_CONTENT, except that apostrophes are allowed without
                escaping, and an unescaped quote marks the end of the
                state.</g:description>
      <g:transition next-state="START_TAG">
        <g:tref name="CloseQuot"/>
      </g:transition>
      <g:transition next-state="DEFAULT" action="pushState">
        <g:description>Transition to an Attribute Value
                    Template.</g:description>
        <g:tref name="Lbrace"/>
		<g:tref name="RbraceErrorInContent"/>
		<g:tref name="AttrLTCharError"/>
      </g:transition>
      <g:transition next-state="QUOT_ATTRIBUTE_CONTENT">
        <g:tref name="EscapeQuot"/>
        <g:tref name="QuotAttrContentChar"/>
      </g:transition>
      <g:transition>
        <g:description>No state change.</g:description>
        <g:tref name="Amp"/>
        <g:tref name="PredefinedEntityRef" if="xquery"/>
        <g:tref name="CharRef" if="xquery core"/>
        <g:tref name="LCurlyBraceEscape" if="xquery"/>
        <g:tref name="RCurlyBraceEscape" if="xquery"/>
      </g:transition>
    </g:state>
    <!-- ================== -->
    <g:state name="APOS_ATTRIBUTE_CONTENT" if="xquery core">
      <g:description>This state is the same as QUOT_ATTRIBUTE_CONTENT, except
                that quotes are allowed, and an unescaped apostrophe marks the end
                of the state.</g:description>
      <g:transition next-state="START_TAG">
        <g:tref name="CloseApos"/>
      </g:transition>
      <g:transition next-state="DEFAULT" action="pushState">
        <g:description>Transition to an Attribute Value
                    Template.</g:description>
        <g:tref name="Lbrace"/>
		<g:tref name="RbraceErrorInContent"/>
		<g:tref name="AttrLTCharError"/>
      </g:transition>
      <g:transition next-state="APOS_ATTRIBUTE_CONTENT">
        <g:tref name="EscapeApos"/>
        <g:tref name="AposAttrContentChar"/>
      </g:transition>
      <g:transition>
        <g:description>No state change.</g:description>
        <g:tref name="Amp"/>
        <g:tref name="PredefinedEntityRef" if="xquery"/>
        <g:tref name="CharRef" if="xquery core"/>
        <g:tref name="LCurlyBraceEscape" if="xquery"/>
        <g:tref name="RCurlyBraceEscape" if="xquery"/>
      </g:transition>
    </g:state>
    <g:state name="PRAGMACONTENTS" if="xquery core">
      <g:description>This state recognizes characters in pragma content, and transits out of this
                     state when a '#)' pattern is recognized.</g:description>
      <g:transition next-state="DEFAULT">
        <g:tref name="PragmaClose"/>
      </g:transition>
      <g:transition>
        <g:tref name="ExtensionContentChar"/>
      </g:transition>
    </g:state>
    <g:state name="PRAGMACONTENTSSPACEDIVIDER" if="xquery core">
      <g:description>This state recognizes the space(s) required to preceed pragma contents.  If you don't have
		this, and try to recognize S in PRAGMACONTENTS, then ExtensionContentChar will be recognized first,
		and the pragma production won't work properly.</g:description>
      <g:transition next-state="DEFAULT">
        <g:tref name="PragmaClose"/>
      </g:transition>
      <g:transition next-state="PRAGMACONTENTS">
        <g:tref name="SForPragma"/>
      </g:transition>
    </g:state>
    <g:state name="PRAGMA" if="xquery core">
      <g:description>This state is entered in a a pragma expression, and recognizes a
                     QName that transits to a PRAGMACONTENTS state rather than a OPERATOR state.</g:description>
      <g:transition next-state="PRAGMACONTENTSSPACEDIVIDER">
        <g:tref name="QNameForPragma"/>
      </g:transition>
    </g:state>

  </g:state-list>

</g:grammar>
