← Prev in month ← Prev in thread

[relax-ng] Annotations in the non-XML syntax

From
James Clark <>
Date
2002-03-19T07:06:30+00:00
ID
006601c1cf13$ff1ec760$
Thread
[relax-ng] Annotations in the non-XML syntax
The aspect of the non-XML syntax that has caused me by far the most
difficulty is annotations.  I've finally come up with a design that I feel
reasonably happy with.  Attached is a description of the syntax using this
new design.  I've also implemented this, but the code isn't yet ready for
public consumption.

Some of the things I would commend to you about this new syntax are:

- The annotations applicable to a syntactic object appear in a consistent
position (immediately preceding the object)

- There is a nice similarity with C# where annotations also occur in square
brackets before an object

- All annotations expressible in the XML syntax are expressible in the
non-XML syntax (actually there's one case that isn't yet handled, which I
describe below)

- Annotation attributes are written the same wherever they occur

- Annotation elements are written the same wherever they occur

- Square brackets are used in two contexts, but the uses are harmonious: in
each case, the square brackets contain attributes followed by content

- Just as a sequence of definitions is allowed without any connector, so a
sequence of annotation elements is allowed at the definition level without
connectors

- Just as adjacent patterns or name classes in a group require a connector
(e.g. |), so annotation elements that are siblings of patterns or name
classes require a connector (>)

- The relationship between annotation attributes and annotation elements
that occur at the top-level outside square brackets is harmonious with the
relationship between those that occur within square brackets: annotation
attributes are followed by annotation elements without any intervening
connector and they will end of as attributes and initial children of the
same parent element

- The implementation doesn't to cope with parsing embedded XML

On the negative side, it's a bit harder to parse:

- In several cases, two tokens of lookahead are required: in several
contexts, when you see a name you have to lookahead to see whether there's a
following "[" in order to know how to proceed

- There's one case where an arbitrary amount of lookahead is required: in
order to determine whether a file contains a sequence of definitions or a
pattern, you may have to lookahead past an annotation in square brackets,
which can consist of arbitrarily many tokens (however, this is easily
implementable in JavaCC without hackery)

There's one kind of annotation that is possible in the XML syntax that can
still not be expressed in the non-XML syntax: annotations that attach to an
<except> element,
more specifically annotations that occur as attributes, initial child
elements or following siblings of <except> elements (in <data>, <nsName> or
<anyName>).

I'm not wedded to the choice of ">" as the connector for connecting patterns
and name-classes to following sibling annotation elements.  If you think
another character would be preferable, please say so.

James
← Prev in month ← Prev in thread