Relax NG schema composition as a model for ixml grammar composition

I have an action related to grammar composition:

    ACTION 2023-01-10-h: Michael to review RELAX NG rules and report back.

There are three ways that RelaxNG allows grammars to be combined; each
of them could (mutatis mutandis) be implemented by an ixml processor.
For simplicity, I'll talk about the XML elements of the XML syntax of
Relax NG, but of course there are compact-syntax equivalents for each
of these as well.

I omit features of RelaxNG that have no analogues in ixml, such as
rules relating to the presence or absence of a `grammar` element in
the resource pointed to.

* Encapsulated inclusion

One grammar I ('inner') may be embedded in another grammar O
('outer').  This occurs when O contains an `externalRef` to I, or when
I is just a `grammar` element occurring within `O`.

In this case:

  - The start symbol(s) of I may be referred to in O.
  - All other names in I are local to I and cannot be referred to from
    O.
  - Rules within I can refer to names defined in O using `parentRef`.

* Non-encapsulated inclusion

One grammar B (for 'base') may be included in another grammar C
('caller' or 'customization').  This occurs when C has an 'include'
referring to B.

All names in B are visible in C.  

(My source doesn't say explicitly that no names from C are visible in
B, but it's clear that if B uses names not defined in B, it's not a
conforming grammar.)

* Non-encapsulated inclusion with redefinitions

Within the `include` element in C, names defined in B may be
redefined.  All names of B and C are in scope, so the redefinition in
C of a name in B may refer to any name in B or C.

The redefinition in C may specify that it overrides the definition in
B, or that it should be combined with the definition in B using either
a choice operator (|) or the interleave operator (&).  (Oddly, the
sequence operator is not allowed, so there is no simple way to add one
thing to an existing sequential list.)


I think each of these forms of composition is helpful in some
circumstances, so I would like our grammar-composition facilities to
support all three of these forms of composition.  I don't have time to
offer concrete use cases here, but I suspect it would be a useful
exercise.

-- 
C. M. Sperberg-McQueen
Black Mesa Technologies LLC
http://blackmesatech.com

Received on Tuesday, 13 June 2023 03:03:26 UTC