[xsd-users] Suggestion

Boris Kolpackov boris at codesynthesis.com
Wed Mar 12 11:07:10 EDT 2008


Hi Ryan,

Prather, Ryan C SSgt USAF AFSPC SYAG/SED <Ryan.Prather at peterson.af.mil> writes:

> Mostly these would help with coders that have standards by which their
> offices require they code it.  If you were to provide some of these
> options it would make their jobs much easier.
>
> 	--max-line-length <integer> - the maximum length of a line of
> code.
> 	--always-use-brackets - this would always put "{" and "}" for
> conditional and iterative code segments
> 	--add-blank-line - this would add a blank space before and after
> the "{" and "}"
> 	--indent-interval <integer> - this is the multiplier by which
> the coder wishes to indent nested statements

Thanks for the suggestions. While I understand your requirements the
problem with handling it using command line options is that there
are as many different coding standards as there are organizations.
For example, you need blank lines before and after "{" and "}" while
someone else would want "{" to start on the same line as functions
signature, 'if', 'while', etc. While yet someone else would want it
to start on the same line except for functions. If we start supporting
each such requirement as a separate command line option, we will
quickly get hundreds of them.

There is an alternative approach which, while require a bit more
effort from your side, is also much more flexible: In XSD we don't
indent generated code manually with spaces, etc. Instead, the code
generators output roughly unformatted code which then goes through
an indenter whose job is to add newlines after ';', '{', '}', etc.,
as well as indent the code. The indenter basically does a hight-level
C++ parsing to recognize which construct is being parsed and how
to format it. The alternative solution to your problem would then
be for you to modify this C++ indenter in order to produce the code
formatted in accordance with your standards.

The C++ indenter code is in the
libbackend-elements/backend-elements/indentation/cxx.* files. You
can use it as a base to create your own. The indenters are set up
in xsd/cxx/tree/generator.cxx for C++/Tree and
xsd/cxx/parser/generator.cxx for C++/Parser. The only inconvenience
of this approach is that you will need to modify and build the XSD
compiler yourself.

Boris




More information about the xsd-users mailing list