PhoenixmlDb.XQuery
XQueryAstBuilder
Converts an ANTLR parse tree into the XQuery AST node types.
#XQueryAstBuilder
Namespace: PhoenixmlDb.XQuery.Parser
Converts an ANTLR parse tree into the XQuery AST node types.
#Properties
| Name | Description |
|---|---|
AllowNamespaceAxis
|
When true, accepts the namespace:: axis (XPath 3.1 / XSLT 3.0 retain it). XQuery raises XQST0134 when this is false (default).
|
AllowRawAmpersand
|
When true, a raw & in a string literal is a literal ampersand and the literal's text is taken verbatim (no entity/character-reference decoding). XPath — used by XSLT — has no entity references, so the & was already decoded by the XML parser upstream. Default false keeps strict XQuery entity decoding.
|
#Methods
#BuildAtomicType(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.AtomicOrUnionTypeContext,Boolean,Nullable<ValueTuple<String,String>>@)
Parameters:
-
ctx— The atomic-or-union type parse-tree node. -
schemaType— Receives the namespace URI and local name of a schema-defined type, or null when the name resolved to a built-in. -
allowSchemaDefinedTypes— When true, a prefix bound to a NON-XSD namespace yields a schema-defined type name inschemaTypeinstead of raising XPST0051. Only cast/castable pass true: everywhere else (instance of, sequence types, map key types) an unrecognised type must still be an error, because returning AnyAtomicType there would silently match anything.
#BuildAttrValueFromParts(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.DirAttributeContext)
Builds an expression for an attribute value that may contain enclosed expressions. Combines literal text parts and {expr} into fn:concat or returns a single part.
#BuildMapEntry(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.MapConstructorEntryContext)
Builds a map entry from the parse tree, handling colon disambiguation. Per XQuery 3.1 §A.2: NCName:NCName, NCName:*, *:NCName without intervening whitespace are QName/wildcard colons, not map entry separators. The grammar parses as exprSingle (COLON exprSingle)+ to collect all parts; this method finds the correct separator colon and merges key parts as needed.
#BuildRecordDecl(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.RecordDeclContext)
Builds
declare record NAME (fields)
: registers the type name and synthesizes the constructor function the declaration implies.
The constructor is emitted as an ORDINARY function declaration whose body is a map constructor. That reuses the existing machinery wholesale — parameter binding, arity checking, and in particular XPath 4.0 keyword arguments, which is how the constructor is actually called:
f:generator(initialized := true(), state := map{})
. Inventing a separate constructor concept would have needed all of that again.
#BuildRelativePathExpression(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.RelativePathExprContext,Boolean,PhoenixmlDb.XQuery.Ast.SourceLocation,Boolean)
Builds a path expression from a relative path, properly handling postfix expression steps (parenthesized expressions, function calls, etc.) at any position. When a postfix step appears in the middle of a path (e.g., A/(expr)/B), it is converted to a SimpleMapExpression mapping operation.
#CanStartRelativePathExpr(Int32)
Returns true if the given token type could be the first token of a RelativePathExpr. This includes names, wildcards, axis abbreviations, literals, and constructors.
#CheckLeadingLoneSlash(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.RootedPathContext)
XQuery 3.1 §3.3.5 leading-lone-slash constraint: when "/" appears as a complete path expression (not followed by a RelativePathExpr in the grammar), the token immediately following must NOT be one that could begin a RelativePathExpr. If it could, the expression is ambiguous and must raise XPST0003.
#ExtractLeadingNameTest(PhoenixmlDb.XQuery.Ast.XQueryExpression)
Extracts the leading name test from an expression (for QName merging). Returns the path, step, and name test, or nulls if not extractable.
#ExtractTrailingNameTest(PhoenixmlDb.XQuery.Ast.XQueryExpression)
Extracts the trailing name test from an expression (for QName merging). Returns the path, step, and name test, or nulls if not extractable.
#GetCharAt(Antlr4.Runtime.ICharStream,Int32)
Gets a character from the character stream at a specific index. Returns -1 if the index is out of bounds.
#GetSerializationParamName(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.OptionDeclContext)
Checks whether the given option declaration is a serialization output declaration. Returns the local name of the serialization parameter, or null if not a serialization option.
#HasPrivateAnnotation(Collections.Generic.IEnumerable<PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.AnnotationContext>)
Returns true if any annotation in the list is
%private
.
#IsNameChar(Int32)
Returns true if the character is an XML NameChar (letters, digits, hyphens, underscores, etc.).
#IsNameStartChar(Int32)
Returns true if the character is an XML NameStartChar.
#IsNcNameToken(Int32)
Returns true if the token type is an NCName or a keyword that can be used as an NCName.
#IsQNameOrWildcardColon(Antlr4.Runtime.IToken)
Checks if a COLON token is part of a QName or wildcard (not a map separator). Per XQuery 3.1 §A.2: the colon is a QName/wildcard colon if it has no whitespace on either side and is flanked by NCName/* tokens.
#IsQNameOrWildcardColonByChars(Antlr4.Runtime.IToken)
Fallback character-based check for QName/wildcard colons when token indices are not available.
#IsValidNCName(String)
Validates that a string is a valid NCName (XML name without colons).
#IsValidXmlChar(Int64)
Tests a code point against the XML 1.0
Char
production (
#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
).
#NormalizeAnyUri(String)
Normalizes an xs:anyURI value by collapsing whitespace (per XML Schema anyURI facets): replace sequences of whitespace characters with a single space, then trim.
#NormalizeWhitespace(String)
Normalizes whitespace in a BracedURILiteral per the XPath/XQuery 3.0 spec: strip leading/trailing whitespace and collapse internal runs of whitespace (space, tab, CR, LF) into a single space character.
#ParseQNameFromToken(String)
Parses a QName from a raw lexer token text like "prefix:local" or "local".
#PrefixLeadingFunctionCall(PhoenixmlDb.XQuery.Ast.XQueryExpression,String)
Merges two expressions connected by a QName/wildcard colon. E.g., merges path ending with NameTest("a") + path starting with NameTest("b") into a path with NameTest(prefix="a", local="b").
Reattaches a namespace
to the unprefixed function call at the START of
, descending through cast/castable/treat/instance-of wrappers and preserving them. Used to repair a prefixed function call that ANTLR split across a colon in a map-entry value. Returns
null
if the leading operand is not an unprefixed function call (so the caller falls back to name-test QName merging).
#ProcessDecimalFormatDecls(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.PrologContext,Collections.Generic.List<PhoenixmlDb.XQuery.Ast.XQueryExpression>)
Parses every `declare decimal-format ...` declaration in the prolog and appends matching DecimalFormatDeclarationExpression entries to
. Shared by main-module and library-module prolog processing so library modules can export module-private decimal formats (re-keyed to EQName during static analysis).
#RecordTypeKey(PhoenixmlDb.Core.QName)
Key for
: the name as written.
#ResolveUnknownAtomicType(PhoenixmlDb.Core.QName,String)
Handle unknown type names in atomic/union type context. Raises XPST0081 for unknown namespace prefixes, XPST0051 for unknown type names.
#SetTokenStream(Antlr4.Runtime.CommonTokenStream)
Sets the token stream for lookahead checks.
#StripDigitSeparators(String)
Strips XPath 4.0 digit separators from a numeric literal's text. The grammar guarantees they only appear between digits, so removing them cannot change the value.
#UnquoteAttrString(String)
Unquotes an attribute value string with XML 1.0 §3.3.3 attribute value normalization: literal whitespace characters (#xD, #xA, #x9) are replaced with #x20 (space) BEFORE decoding entity/character references, so etc. are preserved as their referenced characters.
#UnquoteStringLiteral(String)
Unquotes a plain string literal, honouring XPath vs XQuery entity semantics. In XPath mode (
) the literal text is taken verbatim: XPath has no entity or character references, and any
&
was already decoded by the XML parser upstream, so a bare
&
is a literal ampersand. In strict XQuery mode entities are decoded.
#ValidateAnnotations(Collections.Generic.IEnumerable<PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.AnnotationContext>)
Validates annotations against reserved namespaces per XQST0045. Annotations in no namespace are also disallowed (unless they are %public or %private).
#ValidateKindTestPrefix(String,String)
Validates that a prefix used in element()/attribute() kind tests is declared. Raises XPST0081 if the prefix is not bound.
#ValidateKindTestTypeName(PhoenixmlDb.Core.QName,String)
Validates that a type name used in element()/attribute() kind tests refers to a known type. Raises XPST0008 if the type is not recognized.
#ValidateVisibilityAnnotations(Collections.Generic.IEnumerable<PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.AnnotationContext>,String)
Validates that %public and %private annotations are not conflicting or duplicated. Raises XQST0106 for functions, XQST0116 for variables.
#VisitEnclosedExprSafe(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.EnclosedExprContext)
Safely visits an enclosed expression, returning EmptySequence for empty { }.
#WrapAttrEnclosedExpr(PhoenixmlDb.XQuery.Ast.XQueryExpression)
Wraps an enclosed expression inside an attribute value with string-join(data(expr), ' ') so that sequences are space-separated per XQuery §3.7.1.3 attribute content rules.
#Fields
| Name | Description |
|---|---|
KnownSchemaTypes
|
Known XML Schema type names (in the xs namespace). Used for XPST0008 validation of type names in element()/attribute() kind tests. |
KnownSerializationParams
|
Known serialization parameter names that may be set via declare option output:name "value". Per XQuery 3.1 spec section 2.2.4, use-character-maps is excluded (XQST0109).
|
ReservedAnnotationNamespaces
|
Reserved namespaces for XQST0045 annotation checks. |
SerializationNamespace
|
The W3C serialization parameters namespace URI. |
_baseUri
|
The declared base-uri from the prolog, used to resolve relative URIs (e.g. collation). |
_declaredRecordTypes
|
Names declared by declare record NAME (...). XPath 4.0 named record types.
|
_defaultCollation
|
The declared default collation URI from the prolog. |
_defaultElementNamespace
|
The declared default element/type namespace URI from the prolog (null = not set, "" = empty). |
_defaultEmptyOrder
|
The declared default empty order from the prolog (declare default order empty greatest/least). |
_directElemPrefixes
|
Prefixes declared via xmlns:* in direct element constructors, mapped to namespace URIs. |
_moduleImportPrefixes
|
Prefixes bound by import module. A type named with one of these that is not otherwise known is taken to be a record type the imported module declares.
|
_prologNamespaces
|
Prefix→namespace URI map from prolog namespace declarations, for resolving annotation names. |
_tokenStream
|
Token stream for lookahead checks (e.g. leading-lone-slash constraint). |