OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

relax-ng message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Subject: Prohibiting duplicate attributes.



Murata-san suggested to me that restricting duplicate attributes (see
the issue #21) is a good thing in several ways.


His proposal is to use the following function to detect an error:

NameClass possibleNames( Pattern p ) {
    switch( p ) {
    case <group> p1 p2 </group>:
    case <interleave> p1 p2 </interleave>:
        nc1 = possibleNames(p1)
        nc2 = possibleNames(p2)
        if( intersection of nc1 and nc2 is non-empty )
            reject this pattern.
        return <choice> nc1 nc2 </choice>;
        
    case <choice> p1 p2 </choice>:
        return <choice> possibleNames(p1) possibleNames(p2) </choice>;
        
    case <attribute> nc p </attribute>:
        return nc;
        
    case <oneOrMore> p </oneOrMore>:
        return possibleNames(p);
    
    case <element> nc p </element>:
    case <empty/>:
    case <notAllowed/>:
    case <data/>:
    case <value/>:
        return <not><anyName/></not>;
}


For example,

<group>
    <attribute name="foo"/>
    <attribute name="foo"/>
</group>

is an error.

<group>
    <attribute name="foo"/>
    <attribute>
        <anyName/>
        ...
    </attribute>
</group>

is also an error.

Pick a real-world example. RELAX NG pattern for RELAX NG passes this
test. XHTML m12n by TREX passes this test. Any grammar written in RELAX
Core will pass this test.

Still one can argue that this restriction prohibits several useful
techniques.



But I believe that this restriction gives several good things that
compensate the loss in the expressiveness.

First, it allows us to construct an automaton statically. I think M-san
will explain it much better than I can do, but if my understanding is
correct, it makes it easier to perform various arithmetic operations
over a pattern. This is an important weapon to make RELAX NG work well
with things like XQuery.


Second, it makes the "pattern matching" easier. "Pattern matching" can
be considered as '(' ')' of regular expression. In the regexp world, you
can test a string "abbbba" with a regexp "a(b+)a" and you can "capture"
the text that matched "b+" part, which is "bbbb" in this case.

In the pattern matching of RELAX NG, the pattern matching algorithm
capture a hedge (or a forest, or whatever) that matched the particular
sub-pattern, which is important for data-binding.



--
Kohsuke KAWAGUCHI                          +1 650 786 0721
Sun Microsystems                   kohsuke.kawaguchi@sun.com



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Powered by eList eXpress LLC