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.
|
MaxParseDepth
|
Recursion bound for the sub-parses XQueryAstBuilder.ReparseExprSingle runs. |
TypeNamespaceResolver
|
Resolves a prefix of a type name that the expression itself does not bind, from the static context of the host language. Null, or a null result, leaves the prefix unbound (XPST0081). |
#Methods
#AddSchemaImport(Collections.Generic.List<PhoenixmlDb.XQuery.Ast.XQueryExpression>,PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.SchemaImportContext,Antlr4.Runtime.ParserRuleContext)
Adds a schema import.
import schema default element namespace "uri"
also makes "uri" the default element/type namespace (XQuery 3.1 §4.11), exactly as
declare default element namespace
does. It was recorded on the AST node and applied nowhere, so
<abf/>
after it was built in no namespace: every schema-validated constructor in such a module then failed (fn-load-xquery-module-051..).
#BuildAtomicType(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.AtomicOrUnionTypeContext,Boolean,Nullable<ValueTuple<String,String>>@,Boolean)
Parameters:
-
ctx— The atomic-or-union type parse-tree node. -
allowListTypes— True only in a cast/castable target position, where XQuery 3.0 permits the built-in list types xs:IDREFS/NMTOKENS/ENTITIES. As a SequenceType they remain XPST0051. -
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
.
#HostDefaultTypeNamespace(String)
For a type name with no prefix in an expression of a host language: the default namespace for elements and types that the host gives (empty for none), where the name is a type of that namespace and not a built-in one. Null where the name is a built-in type, or the expression is not a host language's.
#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]
).
#IsVisibilityAnnotation(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.AnnotationContext,String)
Whether
is the standard %public or %private: unprefixed, prefixed with a prefix bound to the XQuery namespace, or written Q{http://www.w3.org/2012/xquery}. Only the bare spelling was recognised, so `%private %xq:public` was not seen as the conflict it is (XQST0106/XQST0116; QT3 modules-pub-priv-30/34) and was rejected as an unknown annotation in a reserved namespace instead (XQST0045).
#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).
#ReadBuildSetters(PhoenixmlDb.XQuery.Parser.Grammar.XQueryParser.PrologContext)
Reads the prolog setters that shape how later expressions are BUILT (default order empty, boundary-space) before any of them is. Both module kinds visited their variable and function declarations first, so a function's `order by` took the default empty order and its constructors the strip policy whatever the prolog said (QT3 fn-load-xquery-module-042-046).
#RecordTypeKey(PhoenixmlDb.Core.QName)
Key for
: the name as written.
#ReparseExprSingle(Antlr4.Runtime.IToken,Antlr4.Runtime.IToken)
Parses the source text from
to
as one ExprSingle and builds it with this builder, so it sees the same prolog and namespace state. Everything outside the span is blanked rather than cut, which keeps every line and column where it was. Null when the span is not a single expression.
#RequireAdjacent(Antlr4.Runtime.IToken[])
NCName:* and *:NCName are single tokens in the XPath grammar ("ws: explicit"): no whitespace or comment may separate their parts. The grammar builds them from separate tokens, which skip hidden whitespace and comments, so `* :ncname` and `*(:c:):ncname` parsed and then failed at run time for want of a context item (QT3 K2-Axes-5..16).
#ResolveSchemaDeclarationNamespace(PhoenixmlDb.Core.QName,Boolean)
The namespace of the declaration a schema-element() or schema-attribute() test names. Only a Q{uri}name carried one before, so schema-element(p:name) looked the declaration up in no namespace and failed XPST0008 for every prefixed name. An unprefixed element name takes the default element namespace; an unprefixed attribute name is in no namespace.
#ResolveTypeNamespace(PhoenixmlDb.Core.QName)
The namespace URI of a type name: EQName, xs/xsd, or a prefix bound in scope.
#ResolveUnknownAtomicType(PhoenixmlDb.Core.QName,String,Boolean)
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). |
_boundarySpacePreserve
|
The module's declared boundary-space policy (true = preserve), or null when it declares none. |
_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). |