### RelaxNG Dead end - modularity and duplicate includes

Posted:

**Fri Sep 14, 2007 2:36 am**I'm trying to build a modular grammar for a trivial language built around a type system - which shouldn't be a problem in RelaxNG. Indeed it wasn't a problem at all, until I started to plug modules together. Then I get errors like...

"multiple definitions of start without "combine" attribute"

The reason for this is that several of the modules themselves depend on the same file. This is of course common in any pluggable modular language (as opposed to a language in which all dialects are organised in a strict hierarchy). E.g. a new dialect may combine an arbitrary subset of other dialects and extend them.

I've created a worked example of this limitation in which the basic language defines statements, expressions and a print statement for expressions. Modules extending this basic language include new constructs which need to be added to the definition of statement or the definition of expression- a trivial sort of example for a grammar I would think. However, it seems to have uncovered an insoluble problem in the way RelaxNG handles includes.

Two sub-dialects extend the basic language to include the statements and number expressions of arithmetic on the one hand, and statements and boolean expressions of logic on the other hand. Of course, each of these needs to refer to (include) the basic language grammar, where expression and statement are defined, and add new choices for what a statement or expression might be. This is all fine so far.

Finally, I attempt to use both arithmetic and logic together by including them both. At this point, there are two includes of the basic grammar - one in the arithmetic definitions, and another in the logic definitions.

It turns out that basic.rng then conflicts with itself - since it tries to redefine all the elements which were already defined in the earlier include of the same file. There's no equivalent to the PHP 'include_once'. In other words, only include it if it's not already included.

My question: What's the proper way to approach this kind of composition. I'm missing something major here.

The worked example can be downloaded from...

http://cefn.com/blog/files/modularity.zip

"multiple definitions of start without "combine" attribute"

The reason for this is that several of the modules themselves depend on the same file. This is of course common in any pluggable modular language (as opposed to a language in which all dialects are organised in a strict hierarchy). E.g. a new dialect may combine an arbitrary subset of other dialects and extend them.

I've created a worked example of this limitation in which the basic language defines statements, expressions and a print statement for expressions. Modules extending this basic language include new constructs which need to be added to the definition of statement or the definition of expression- a trivial sort of example for a grammar I would think. However, it seems to have uncovered an insoluble problem in the way RelaxNG handles includes.

Two sub-dialects extend the basic language to include the statements and number expressions of arithmetic on the one hand, and statements and boolean expressions of logic on the other hand. Of course, each of these needs to refer to (include) the basic language grammar, where expression and statement are defined, and add new choices for what a statement or expression might be. This is all fine so far.

Finally, I attempt to use both arithmetic and logic together by including them both. At this point, there are two includes of the basic grammar - one in the arithmetic definitions, and another in the logic definitions.

It turns out that basic.rng then conflicts with itself - since it tries to redefine all the elements which were already defined in the earlier include of the same file. There's no equivalent to the PHP 'include_once'. In other words, only include it if it's not already included.

My question: What's the proper way to approach this kind of composition. I'm missing something major here.

The worked example can be downloaded from...

http://cefn.com/blog/files/modularity.zip