Skip to content

Introduce two-pass processing for direct attribute parsing#2627

Open
GuntherRademacher wants to merge 4 commits intoBaseXdb:mainfrom
GuntherRademacher:xmlns-parsing
Open

Introduce two-pass processing for direct attribute parsing#2627
GuntherRademacher wants to merge 4 commits intoBaseXdb:mainfrom
GuntherRademacher:xmlns-parsing

Conversation

@GuntherRademacher
Copy link
Member

@GuntherRademacher GuntherRademacher commented Mar 25, 2026

This PR introduces a two-pass strategy for processing attribute lists in direct element constructors.

In the first pass, only xmlns attributes are processed, updating the namespace context. In the second pass, all remaining attributes are parsed. This ensures that namespace declarations are available to embedded expressions, even if those expressions precede the corresponding xmlns attributes.

An alternative approach based on deferred QName resolution (via QNmResolver) was considered. While this works for static function names (which are resolved after parsing), it does not extend well to:

  • variable names, especially scoped local variables
  • type names, which would require additional indirection similar to named record types

The two-pass strategy avoids these issues entirely and allows QName resolution to occur immediately. As a result, QNmResolver is no longer needed and has been removed.

The main challenge is skipping attribute values during the first or second pass without triggering parsing side effects. Direct attribute values can contain complex nested constructs, including enclosed expressions, literals, comments, direct constructors, pragmas, and templates. Reusing existing parsing code for skipping is not feasible due to its side effects. Instead, skipping is implemented using a parser generated from a simplified grammar derived from the XQuery 4.0 specification.

There are 4 commits in this PR:

  • 332fe2b: introduce two-pass processing with REx-based attribute value scanning
  • f4cc284: remove QNmResolver and switch to immediate QName resolution
  • 8665f67: add regression tests
  • aa0b72a: disallow whitespace in wildcards

This change fixes the following QT4 test cases:

  • K2-Axes-9
  • K2-Axes-10
  • union-type-009
  • union-type-010
  • Constr-namespace-30
  • K2-DirectConElemNamespace-8
  • K2-DirectConElemNamespace-14
  • K2-DirectConElemNamespace-19
  • K2-DirectConElemNamespace-20
  • K2-DirectConElemNamespace-21
  • K2-DirectConElemNamespace-22
  • K2-DirectConElemNamespace-29
  • K2-DirectConElemNamespace-30
  • K2-DirectConElemNamespace-31
  • K2-DirectConElemNamespace-32
  • K2-DirectConElemNamespace-33
  • function-decl-40-035
  • function-decl-40-036
  • K2-NamespaceProlog-13
  • try-catch-err-code-variable-13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant