Re: Scope of comments

On 01/02/2022 16:49, John Lumley wrote:
>
> 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">
>     .......
>
> 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.
>
And the comments do also nest in the XML tree:

    {# jl:opt rule} ParamList: {#jl:opt ruleStart} Param, ( -',',
    {#jl:opt inBracket {#jl:nest Nested}} Param )*.

becomes:

    *<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>#jl:nest Nested</comment> </comment>*
                   <nonterminal name='Param'/>
                </alt>
             </alts>
          </repeat0>
       </alt>
    </rule>

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

Received on Tuesday, 1 February 2022 17:01:28 UTC