[xsd-users] regular expressions in 3.0 vs 3.1.

Boris Kolpackov boris at codesynthesis.com
Fri Apr 11 06:13:42 EDT 2008


Hi Shiva,

Balasubramanyam, Shivakumar <sbalasub at qualcomm.com> writes:

> --include-regex "Z\\..*/common/Zdistribution/Z"
>
> This used to replace #include "../../common/File.h" to #include
> "distribution/File.h"

There was a bug in the include regex handling code in that it allowed
matching/replacing sub-strings. This bug allowed expressions like above
to work. Here is the alternative that should work in 3.1.0 and earlier
versions:

--include-regex 'Z.*/common/(.*)Zdistribution/$1Z'

That is, you need to match the whole include path.


> We need "../../types/core.h" replaced by "types/core.h"
>          "../../types/http.h" replaced by "types/http.h"

--include-regex 'Z.*/types/(.*)Ztypes/$1Z'


> XSD now supports -guard-prefix, which is useful.
>
> But I have noticed that if this option is not provided, it use the $pwd
> + something for the file guard.
>
> I am not sure why this was done when -guard-prefix option provides the
> user the flexibility. I would like the default behavior for 3.0 release.

In earlier versions the include guard was derived from the schema name
alone. This caused problems for grammars that have several schema files
with the same name but residing in different directories, for example:

foo/a.xsd
bar/a.xsd

The really bad part about this is that a user can spend a lot of time
trying to figure out what's wrong. The generated code simply stops
compiling without any useful clues to the cause.

In 3.1.0 we've extended the guard name with the directory part of the
schema being compiled. Thus if you invoke XSD like so:

$ xsd cxx-tree a.xsd

You will get A_HXX as a guard. But if you do it like this:

$ xsd cxx-tree foo/a.xsd
$ xsd cxx-tree bar/a.xsd

Then you get FOO_A_HXX and BAR_A_HXX as guards. One negative consequence
of this change, which I believe you are observing, is that if you compile
your schema with an absolute path, then you will get all the leading
directories in the guard. We, however, decided that this is a lesser
of the two evils.

To get the original behaviors (or close to it), you can specify the
--guard-prefix options which overrides the directory part of the guard.
For example, you can do:

$ xsd cxx-tree --guard-prefix "guard" /long/path/to/a.xsd

And get GUARD_A_HXX as a guard.

Boris




More information about the xsd-users mailing list