PhoenixmlDb.XQuery
XQueryLexerAdapter
An adapter that wraps to manage lexer mode transitions for XQuery direct element constructors.
#XQueryLexerAdapter
Namespace: PhoenixmlDb.XQuery.Parser
An
adapter that wraps
to manage lexer mode transitions for XQuery direct element constructors.
ANTLR4 lexer rules each support a single mode action (pushMode, popMode, or mode). XQuery direct element constructors require multi-step mode transitions that cannot be expressed in a single lexer action. This adapter intercepts tokens from the lexer and performs the additional mode stack manipulations needed for correct parsing:
-
LESS_THANfollowed by a name-start character pushesSTART_TAGmode. -
RBRACEwhile inside element content pops back fromDEFAULT_MODEtoELEM_CONTENT. -
END_TAG_CLOSEpops bothEND_TAG(done by the lexer) andELEM_CONTENT(done here).
#Methods
#IsNameStartChar(Int32)
Returns
true
if the character code point is an XML NameStartChar.
#IsNumericLiteral(Int32)
Returns
true
if the token type is a numeric literal (integer, decimal, or double).
#IsOperatorPosition(Int32)
Returns
true
if the last token type indicates we are in an "operator position" where
<
must be a comparison operator, not a direct element constructor. After these tokens,
<
cannot start an element constructor per XQuery grammar.
#StartsWithNameStartChar(Antlr4.Runtime.IToken)
Returns
true
if the token's text begins with an XML NameStartChar — i.e. the token is an NCName or a keyword (such as
mod
/
div
/
idiv
/
eq
) that the lexer spells with letters. Such a token immediately abutting a numeric literal is the XPST0003 violation we want to reject.
#Fields
| Name | Description |
|---|---|
_attrValueDepth
|
Tracks attribute value enclosed expression depth so we know when RBRACE should pop back to ATTR_VALUE_DQ or ATTR_VALUE_SQ mode.
|
_deferredToken
|
When a LESS_THAN_SLASH token is split into LESS_THAN + SLASH, this holds the deferred SLASH token to be returned on the next call. |
_elemDepth
|
Tracks element nesting depth so we know when RBRACE should pop back to ELEM_CONTENT vs. being a normal brace in default mode.
|
_enclosedBraceDepth
|
Tracks nested brace depth within enclosed expressions so that inner {} (maps, computed constructors) don't prematurely pop out of element content.
|
_lastTokenType
|
The type of the last non-whitespace token — used to disambiguate < between comparison operator and direct element constructor start. |
_previousToken
|
The most recently emitted token. Used to detect a numeric literal immediately followed — with no intervening whitespace or comment — by a name (NCName or an operator keyword such as mod/div/idiv), which the XPath/XQuery grammar forbids (XPST0003). ANTLR discards whitespace, so 10mod 3 would otherwise lex identically to 10 mod 3; this token-adjacency check restores the spec-required separation.
|
_stringConstructorDepth
|
Tracks string constructor interpolation depth so we know when RBRACE should pop back to STRING_CONSTRUCTOR mode vs. being a normal brace in default mode.
|