Re: Pragmas

Steven Pemberton <steven.pemberton@cwi.nl> writes:
> To try and put pragmas to bed, I'd like to propose a Processing Instruction style of solution.

I don’t think that’s sufficient. One of the key differences between iXML and XML is that the XML serialization of XML is, uh, explicit. The XML serialization of iXML is determined by the parse.

The strategy you describe doesn’t satisfy the requirement that I’ve articulated repeatedly that it must be possible to associate a pragma with a rule or a terminal or an nonterminal. Consider this grammar:

S = A .
{c1}
A = {c2} a, {c3} "b", c {c4} .
a = "a" .
c = "c" .

The XML serialization of that grammar leaves the comments scattered about in unhelpful ways:

<ixml>
   <rule name='S'>
      <alt>
         <nonterminal name='A'/>
      </alt>
   </rule>
   <comment>c1</comment>
   <rule name='A'>
      <comment>c2</comment>
      <alt>
         <nonterminal name='a'/>
         <comment>c3</comment>
         <literal string='b'/>
         <nonterminal name='c'>
            <comment>c4</comment>
         </nonterminal>
      </alt>
   </rule>
   <rule name='a'>
      <alt>
         <literal string='a'/>
      </alt>
   </rule>
   <rule name='c'>
      <alt>
         <literal string='c'/>
      </alt>
   </rule>
</ixml>

Using the grammar of the pragmas proposal from Balisage, we get much better association of pragmas with elements in the XML. This grammar:

S = A .
{[p1]}
A = {[p2]} a, {[p3]} "b", c {[p4]} .
a = "a" .
c = "c" .

serializes into this XML:

<ixml>
   <rule name='S'>
      <alt>
         <nonterminal name='A'/>
      </alt>
   </rule>
   <rule name='A'>
      <pragma pname='p1'/>
      <alt>
         <nonterminal name='a'>
            <pragma pname='p2'/>
         </nonterminal>
         <literal string='b'>
            <pragma pname='p3'/>
         </literal>
         <nonterminal name='c'/>
      </alt>
      <pragma pname='p4'/>
   </rule>
   <rule name='a'>
      <alt>
         <literal string='a'/>
      </alt>
   </rule>
   <rule name='c'>
      <alt>
         <literal string='c'/>
      </alt>
   </rule>
</ixml>

                                        Be seeing you,
                                          norm

--
Norm Tovey-Walsh
Saxonica

Received on Tuesday, 7 January 2025 13:53:22 UTC