Scope of comments

One of the issues I raised was how would 'specially marked' comments 
scope in the parsed XML for a grammar? I've just run a very small test, 
using my 'annotated' XPath.ixml which starts:

    XPath: s?, Expr, s?.

    {# jl:opt rule} ParamList: {#jl:opt ruleStart} Param, ( -',',
    {#jl:opt inBracket} Param )*.
    Param: -'$', EQName, TypeDeclaration?.

    ....

If we pass this through Steven's processor against the grammar for IXML 
we get:

    <ixml ixml:state="ambiguous" xmlns:ixml="http://invisiblexml.org/NS">
        <rule name='XPath'>
           <alt>
              <option>
                 <nonterminal name='s'/>
              </option>
              <nonterminal name='Expr'/>
              <option>
                 <nonterminal name='s'/>
              </option>
           </alt>
        </rule>
        /*<comment># jl:opt rule</comment>*/
        <rule name='ParamList'>
           /*<comment>#jl:opt ruleStart</comment>*/
           <alt>
              <nonterminal name='Param'/>
              <repeat0>
                 <alts>
                    <alt>
                       <literal tmark='-' sstring=','/>
                       */<comment>#jl:opt inBracket</comment>/*
                       <nonterminal name='Param'/>
                    </alt>
                 </alts>
              </repeat0>
           </alt>
        </rule>
        <rule name='Param'>
         .....

so it seems that within a rule the comments scope within the tree, in 
appropriate sibling position. For those before a rule start, the comment 
is, unsurprisingly, in the preceding-sibling::*[1] position. I think 
anyone who's using this for preprocessing via a rule-rewriting operation 
through the XML representation could live with this small additional 
complexity.

-- 
*John Lumley* MA PhD CEng FIEE
john@saxonica.com

Received on Tuesday, 1 February 2022 16:50:00 UTC