[relaxng-user] trang: translating comments between compact and xml

James Clark jjc at jclark.com
Sat Dec 6 04:36:22 ICT 2003


On Wed, 2003-11-26 at 03:36, David Tolpin wrote:
> Hi,
> 
> trang translates
> 
> element 
> ( a # case a
> | b # case b
> )
> { empty }
> 
> into
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <element xmlns="http://relaxng.org/ns/structure/1.0">
>   <choice>
>     <name>a</name>
>     <!-- case a -->
>     <name>b</name>
>   </choice>
>   <!-- case b -->
>   <empty/>
> </element>
> 
> moving the second comment past the end of the name class.  I realize that translation
> of comments is not normative;  however, since the comments are translated by trang,
> is there a list of patterns where comments do not stay in place during translation?

On input, trang associates comments with the next following object (i.e.
pattern, name-class, grammar component, annotation).  On output, it
reverses this.  The next object following the "case b" comment is the
empty pattern.  So on output, the comment will end up before <empty/>
element.

This means that the style of commenting in the compact syntax where you
put the comment on the same line after the thing it applies doesn't
translate well. Perhaps trang could notice when there's no newline
between an object and a comment and then associate the comment with the
preceding object and flag that in its internal representation, but I
think it would be hard to make it always do what a human who actually
understood the comment would do.

James




More information about the relaxng-user mailing list