Question

Suppose I have two these rules:

JFalse = element JFalse {
   attribute label { xs:string }?,
   attribute jump { xs:string }?,
   attribute offset { xs:integer }?
}

JGt = element JGt {
   attribute label { xs:string }?,
   attribute jump { xs:string }?,
   attribute offset { xs:integer }?
}

(quite a lot more in actuality)

What I'd like to do is obviously something like:

JFalseOrJGt = element (JFalse | JGt) {
   attribute label { xs:string }?,
   attribute jump { xs:string }?,
   attribute offset { xs:integer }?
}

(but the above is not valid). Can I do it in some other way, that will result in a more "compressed" grammar rules?

Was it helpful?

Solution

This is one option:

JFalse = element JFalse { jFalseGt }

JGt = element JGt { jFalseGt }

jFalseGt = 
   attribute label { xs:string }?,
   attribute jump { xs:string }?,
   attribute offset { xs:integer }?

OTHER TIPS

The syntax element (JFalse | JGt) is actually the correct syntax for declaring an element which can have either of the two names. When converting from the compact syntax to the XML syntax, trang converts it to:

<element> <choice> <name>JFalse</name> <name>JGt</name> </choice> [...]

which is exactly what you are asking for.

There is a bug in your code but it is unrelated to naming elements. The problem is that all of your xs:... types cannot be resolved. You have two choices: either you add datatypes xs = "http://www.w3.org/2001/XMLSchema-datatypes" at the start of your file to declare the xs prefix, or you edit each type to use the xsd prefix instead of xs. The xsd prefix is declared by default.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top