Previous Up Next

Chapter 16  Using Gom

16.1  Command line tool

People interested in using Gom as a standalone tool can use the Gom command line interface.

gom [options] filename [... filename]

Options:

--config <file> | -X Defines an alternate XML configuration file
--debug | -vv Display debugging info
--destdir <dir> | -d Specify where to place generated files
--generator <type> | -g Select Generator. Possible value: "shared"
--help | -h Show this help
--import <path> | -I Path for include
--inlineplus Make inlining active
--intermediate | -i Generate intermediate files
--intermediateName <intermediateName> | -iname specify the prefix of intermediate files
--multithread | -mt Generate code compatible with multi-threading
--optimize | -O Optimize generated code
--optimize2 | -O2 Optimize generated code
--package <packageName> | -p Specify package name (optional)
--strategies-mapping | -sm Generate tom mapping for strategies
--termgraph | -tg Extend the signature for term-graphs
--termpointer | -tp Extend the signature for term pointers
--verbose | -v Display compilation information
--verbosedebug | -vvv Display even more debugging info
--version | -V Print version
--wall | -W Print warning

16.2  Ant task

Gom can also be used within ant, and has its own ant tasks.

To use the Gom ant task, you have to first declare it the same way as the Tom ant task.

<taskdef name="gom"
         classname="tom.gom.tools.ant.GomTask"
         classpathref="tom.classpath"/>

Once the task is defined, you can use them to compile a Gom file.

The Gom ant task has to be able to find a configuration file for Gom. It can either use the tom.home property to find its configuration file, or use the value of the config attribute. Since the tom.home property is also used when Gom has to process hooks, it is a good practice to always define the tom.home property to the installation path of the Tom system.

The default configuration file for Gom is included in the Tom distribution as Gom.xml.

<gom config="${gom.configfile}"
     srcdir="${src.dir}"
     package="example"
     destdir="${gen.dir}">
  <include name="**/*.gom"/>
</gom>

Like in Tom example, in this Gom ant task we want to compile all Gom source files in {src.dir} and to configure the compiler to create a package called example in {gen.dir} for the generated code, just as we do for Gom in command line.

The Gom task takes the following arguments:

AttributeDescriptionRequired
configLocation of the Gom configuration file.No
destdirLocation of the generated files.No
optionsCustom options to pass to the Gom compiler.No
packagePackage for the generated Java files.No
srcdirLocation of the Gom filesYes, unless nested <src> elements are present

The set of .gom files to compile is specified with a nested include element.

16.3  Gom Antlr adaptor

GomAntlrAdaptor is a tool that takes a Gom signature and generates an adaptor for a given Antlr grammar file. This way, Gom constructors can be directly used in the rewrite rule mechanism offered by Antlr (version 3). See examples/parser the see an example that shows how to combine Tom, Gom and Antlr.

16.3.1  Command line tool

gomantlradaptor [options] filename [... filename]

Options:

--config <file> | -X Defines an alternate XML configuration file
--debug | -vv Display debugging info
--destdir <dir> | -d Specify where to place generated files
--grammar <grammarName> | -g Antlr grammar name
--help | -h Show this help
--import <path> | -I Path for include
--intermediate | -i Generate intermediate files
--intermediateName <intermediateName> | -iname specify the prefix of intermediate files
--package <packageName> | -p Specify package name (optional)
--termgraph | -tg Extend the signature for term-graphs
--termpointer | -tp Extend the signature for term pointers
--verbose | -v Display compilation information
--verbosedebug | -vvv Display even more debugging info
--version | -V Print version
--wall | -W Print warning

16.3.2  Ant task

The GomAntlrAdaptor task takes the following arguments:

AttributeDescriptionRequired
configLocation of the GomAntlrAdaptor configuration file.No
destdirLocation of the generated files.No
grammarName of the grammar.Yes
optionsCustom options to pass to the Gom compiler.No
packagePackage for the generated Java files.No
srcdirLocation of the GomAntlrAdaptor filesYes, unless nested <src> elements are present

Previous Up Next