On the subject of rewriting

Hello,

As I was looking at rewriting to ease implementation, I happened to
notice that the ixml grammar for ixml contains a few places where an
“alts” contains a single “alt”.

Is it safe to simplify that construction? For example, consider:

   <rule name='alt'>
      <alt>
         <repeat0>
            <nonterminal name='term'/>
            <sep>
               <alts>
                  <alt>
                     <literal tmark='-' dstring=','/>
                     <nonterminal name='s'/>
                  </alt>
               </alts>
            </sep>
         </repeat0>
      </alt>
   </rule>

It feels like that should be the same as:

   <rule name='alt'>
      <alt>
         <repeat0>
            <nonterminal name='term'/>
            <sep>
               <literal tmark='-' dstring=','/>
               <nonterminal name='s'/>
            </sep>
         </repeat0>
      </alt>
   </rule>

But I’ve been unable to prove that to myself in the general case. Is it
ever wrong to remove an “alts” that contains a single alternative?

                                        Be seeing you,
                                          norm

--
Norm Tovey-Walsh
Saxonica

Received on Thursday, 16 December 2021 13:12:14 UTC