Chapter 2. Running CoffeePot
CoffeePot can be run directly from the jar file with a command like:
java -jar coffeepot-.jar options
It may be more convenient, however, to write a small batch file or shell script to run it with an explicit classpath, Chapter 7, Configuration.
In the examples that follow, we assume that “coffeepot” will run
CoffeePot. Depending on how you’ve installed it, you may have to
substitute java -jar /path/to/coffeepot.jar or some other variation.
2.1. The command line
Typical usage is:
(For a quick recap of all the possible options, run
CoffeePot with the --help option.)
Where:
--grammar:file-
Specifies the input grammar. If unspecified, the Invisible XML specification grammar is used. The grammar specified may be an Invisible XML grammar in either the text or XML formats.
--input:file-
Specifies the input file. If unspecified, the remaining command line arguments are taken as the input, separated by single spaces.
If the input file is just a single hyphen,
-, CoffeePot will read from standard input. --output:file-
Specifies the output location, defaults to standard output.
--parse:number-
Selects a specific parse. If the parse was ambiguous, use this option to inspect alternate parses. (If the parse wasn’t ambiguous, there’s only one.) You can also use
--parse-countto display more than one parse. --pretty-print-
Specifies that XML output should be formatted with line breaks and indentation. Note: the built-in pretty printer is a little bit crude, especially in the face of mixed content.
2.1.1. Command line arguments
CoffeePot has many options. The complete list is:
--accept:integer-
This option places a limit on the degree of ambiguity allowed in the parse. If the parse has more than the specified number of parses, an error is raised. Setting the value to
1requires unambiguous parses, a value of10allows up to at most ten parses, etc. The valuefiniteallows any finite number of parses. The (default) valueinfiniteallows any number of parses. --analyze-ambiguity:boolean-
Applies Anders Møller’s ambiguity analyzer to the grammar. This can help to identify where ambiguity occurs and what inputs will trigger it. The analyzer operates on the transformed grammar.
Note that the analyzer can be quite slow if the grammar uses Unicode character classes. This is especially true if it uses classes that contain a large number of characters such as
[L]or[LC]. --axe:value-
Choose an “axe” to use when selecting trees from the forest. The default axe,
sequential, gives sequential results for ambiguous parses. Therandomaxe gives random results for ambiguous parses. Thepriorityaxe uses priority pragmas. Thexpathaxe uses XPath expressions. --bnf:boolean-
Checks if the grammar is a “plain BNF” grammar. This doesn’t change the parser, it simply reports if the grammar is BNF. (Why? Well, if you’re interested in exploring a tool like the ambiguity analyzer, the results can be easier to understand if the input grammar hasn’t been transformed in any way. This option let’s you check if that’s the case.)
--choose:value-
Use the XPath expression to select among ambiguous alternatives. See Choosing among alternatives.
--config:existing-file-
Load a specific configuration file. If no configuration file is specified, CoffeePot tries to load
.nineml.propertiesin the current directory and the user’s home directory. If neither exist, it also looks fornineml.propertieson the classpath. --debug:boolean-
The
--debugoption enables some additional logging messages. If debugging is enabled and CoffeePot terminates because an exception was raised, the stack trace will be printed. --describe-ambiguity-with:value-
Selects how ambiguity will be described. Implies
--describe-ambiguity.The options are
text,xml, andapi-xml. See Describing ambiguity. --describe-ambiguity:boolean-
Requests a desription of where in the parse forest ambiguity arose. This option only applies to ambiguous parses. See also Describing ambiguity.
--disable-pragma:value-
Disables the specified pragma.
--earley-
Use the Earley parser.
--enable-pragma:value-
Enables the specified pragma.
--encoding:encoding-
Use encoding-name when parsing the input. This must be an encoding name recognized by Java. See also
--grammar-encoding. --export:filename-
This option saves a compiled version of the input grammar. The compiled form saves the processor from having to interpret the input grammar and can be much faster.
--forest:filename-
Output an XML representation of the structure of the parse forest. This is intended as the input to visualization processes, like the graph output.
--function-library:existing-file-
Load a function library to select among ambiguous alternatives. See Choosing among alternatives.
--gll-
Use the GLL parser.
--grammar-encoding:encoding-
Use encoding-name when parsing the input grammar. This must be an encoding name recognized by Java. See also
--encoding. --grammar:existing-file-
Specifies the input grammar. If unspecified, the Invisible XML specification grammar is used. The grammar specified may be an Invisible XML grammar in either the text or XML formats, or in the proprietary “compiled grammar” format.
--graph-format:value-
Specifies the graph file format. This must be a format recognized by GraphViz. If no format is provided, the default is taken from the extension of the
--graphfile. (This option has no effect if--graphis not specified.) --graph-option:value-
Passes the specified
$optionwithvalueto the stylesheet that generates the SVG. See Diagrams. --graph:filename-
Output a diagram of the parse forest to the file. This option will only work if GraphViz has been configured. See also
--graph-format. --help:value-
Prints a summary of the command line syntax. If a value is specified, it must be the name of an option, for example
--help:mark-ambiguities. --ignore-same-serializations:boolean-
Attempts to ignore ambiguity that’s not observable in the serialized results. Will report an unambiguous parse if it determines that all ambiguous parses produce the same serialization. Only a subset of all the possible ways that ambiguity might produce the same serialization are recognized.
--input:existing-file-
Specifies the input file. If the input file is just a single hyphen,
-, CoffeePot will read from standard input.If unspecified, the other command line arguments that don’t begin with a hyphen are taken as the input, separated by single spaces. If the argument
--appears on the command line, everything after it is taken as input without regard to leading hyphens. --input-newline:boolean-
Ensure that the input ends with at least one newline. (If the provided input doesn’t end with a newline, the processor will add one.)
--log:value-
Sets the log level, one of
silent,error,warning,info,debug, ortrace. It can also set logging at finer granularities by specifying a list of logger:level pairs, for example:CoffeePot:trace,CoffeeGrinder:info,CoffeeFilter:warning. --mark-ambiguities:boolean-
Enables marking ambiguities in the output. This option will cause additional attributes to be added to the result trees marking where ambiguous choices were made. (This only works for vertical ambiguities on nonterminals that aren’t suppressed.)
--modular:value-
Selects the flavor of modularity, see Modularity.
--no-output:boolean-
Suppress output of the parse tree.
--normalize:boolean-
Normalize line endings in the input file. This option will translate all occurrences of carriage return (
#D), carriage return followed immediately by a line feed (#D#A), next line (#85), and line separator (#2028) into a single line feed (#A). Multiple line endings are not combined. In other words,#85#2028becomes#A#A, not#A. --omit-csv-headers:boolean-
When generating CSV output, the nonterminal names are used as column headers by default. This option causes them to be omitted.
--output:filename-
Specifies the output location. If no output option is provided, output goes to standard output.
--format:value-
Requests a specific format type. Available types are
xml, the default,jsonorjson-data,json-treeorjson-text, orcsv. (jsonandjson-dataare synonyms, as arejson-textandjson-tree.)The
json-dataformat is only possible for result trees that contain no mixed content.The
csvformat is only possible for result trees that have a specific “shape”. The grand-children of the root element must all be atomic values and no mixed content is allowed. --parse-count:integer-
For an ambiguous parse, you can specify a parse count greater than one to get several of the possible parses. Specify the value
allto get all of the parses.It is not an error if you get multiple parses that have the same XML structure, this simply indicates that the ambiguity was in some part of the result that wasn’t serialized.
No attempt is made to enumerate the infinitely many possible parses that arise if the resulting parse forest contains a loop. Consequently, it’s possible to get an “infinitely ambiguous” result that has only a single parse.
--parse:integer-
Selects a specific parse. If the parse was ambiguous, use this option to inspect alternate parses. (If the parse wasn’t ambiguous, there’s only one.) You can also use
--parse-countto display more than one parse. --pedantic:boolean-
By default, CoffeePot accepts certain grammar extensions, such as pragmas. With this option, only grammars strictly conforming to the Invisible XML specification may be used.
--pretty-print:boolean-
Specifies that XML output should be formatted with line breaks and indentation. The built-in pretty printer is a little bit crude, especially in the face of mixed content.
--priority-style:value-
There are two styles for managing priorities:
maxandsum. If the style ismax(the default), the priority of a node in the graph is the same as the highest priority among its descendants. If the style issum, the priority of a node in the graph is the sum of the priorities of its descendants. In either case, if a node has an explicity priority, that priority takes precedence. Whenmaxis used, any node without a priority is treated as if it had the default priority. --progress-bar:boolean-
Allows you to specify that the progress bar should be displayed during parsing.
ⓘNoteVersions of CoffeePot prior to 3.4.0 also allowed the values “on”, “off” and “tty”. Those are no longer available.
--provenance:boolean-
If provenance is requested, a comment is generated at the top of XML outputs that identifies the version of NineML used and details about the input and the grammar. (This only applies to XML outputs as neither JSON nor CSV have a standard mechanism for comments.)
--record-end:value-
Specifies that the input should be parsed as a set of records delimited by the regular expression provided at the end of each record. (Implies
--records.) --record-start:value-
Specifies that the input should be parsed as a set of records delimited by the regular expression provided at the start of each record. (Implies
--records.) --records:boolean-
Specifies that the input should be parsed as a set of records. If neither
--record-startor--record-endis provided, the default separator is a single newline, “\n”. --repeat:integer-
Repeat the parse the specified number of times. This option only really exists for performance testing. If both
--repeatand--timeare specified, a summary of total parse time over all repeats will be printed. --separate-files:boolean-
If
--parse-countis used to request more than one parse (in an ambiguous grammar), CoffeePot puts them all in a single document by default.If the
--separate-filesoption is used and the--outputoption specifies a filename, they will be output in separate, sequentially numbered files. For example, if parse count is 3 and the output filename is “parse.xml”, CoffeePot will createparse_1.xml,parse_2.xml, andparse_3.xmlfor the three parses. --show-chart:boolean-
Show the state chart used by the parser. (This option only applies when the Earley parser is used.)
--show-grammar:boolean-
CoffeePot transforms your input grammar into a simpler, BNF grammar. If this option is specified, the grammar used by the parser will be printed on standard output.
--show-marks:boolean-
Include marks in the output. These are added as
ixml:markattributes on the elements. --show-options:boolean-
Show (and log) the parse options specified in the configuration.
--start-symbol:value-
Invisible XML treats the first rule in the grammar as the start symbol. This option allows you to specify a different start symbol. Note that this is not conformant behavior.
--strict-ambiguity:boolean-
When priorities or other mechanisms are used to select a parse from an ambiguous forest, if those mechanisms successfully choose a unique parse, the result will not be marked as ambiguous. Using the
--strict-ambiguityflag will always mark ambiguous parses as ambiguous, even if only a single parse could be selected according to the mechanisms applied. --suppress:value-
Suppress
ixml:statevalues. Theambiguousandprefixstates can be suppressed. --time-records:boolean-
When using record-oriented input, this option enables output of timings for each record.
--time:boolean-
If enabled, CoffeePot will report information about how long various phases of parsing took.
--trailing-newline:boolean-
If enabled, an additional newline will be added to the output if one is not already present.
--trim:boolean-
If specified, leading and trailing whitespace is removed from the input before parsing.
--unbuffered:boolean-
If this option is enabled, multiple parses will be output as soon as they’re available. The resulting output will not have a wrapper to assure well-formedness.
--valid:boolean-
If this option is enabled, CoffeePot will treat failure to successfully parse the input as a fatal error rather than returning an error document. Note that this is not conformant behavior.
--version:boolean-
Display the CoffeePot version number.
2.2. In build tools
The HOWTO repository contains examples of using CoffeePot in build tools such as Gradle.