Chapter 3. Parser options
3.1. ParserOptions
The org.nineml.coffeefilter.ParserOptions
class.
This class extends org.nineml.coffeegrinder.parser.ParserOptions
.
This object is extended by other members of the NineML family to provide additional options. It started out as a collection of public fields, but changed to a more traditional collection of getters and setters when it began to develop options that were not entirely independent.
3.1.1. Constructor summary
Public constructors for the org.nineml.coffeefilter.ParserOptions
class.
public ParserOptions()
Create the parser options.
The initial logger will be a DefaultLogger initialized with readSystemProperties().
public ParserOptions(Logger logger)
Create the parser options with an explicit logger.
public ParserOptions(ParserOptions copy)
Create a new set of options from an existing set.
3.1.2. Method summary
Public methods on the org.nineml.coffeefilter.ParserOptions
class.
public void disablePragma(String pragma)
Disable the specified pragma.
The user can selectively ignore pragmas in a grammar. This method specifies that a particular pragma should be disabled. The token “#all” disables all pragmas.
public void enablePragma(String pragma)
Disable the specified pragma.
The user can selectively ignore pragmas in a grammar. This method specifies that a particular pragma should be enabled. The token “#all” enables all pragmas.
public void exposeState(String state)
Expose a state.
The Invisible XML processor adds state values to the root element to report conditions such as ambiguity or a prefix parse. These states can be suppressed.
public
boolean
getAllowMultipleDefinitions()Allow multiple definitions?
A grammar with multiply defined symbols isn’t a problem for the underlying Earley parser, but it is forbidden by Invisible XML.
public
boolean
getAllowUndefinedSymbols()Allow undefined symbols?
A grammar with undefined symbols isn’t necessarily unusable. But Invisible XML forbids them.
public
boolean
getAllowUnproductiveSymbols()Allow unproductive symbols?
An unproductive symbol is one which can never produce output in a valid parse.
public
boolean
getAllowUnreachableSymbols()Allow unreachable symbols?
A grammar with unreachable symbols isn’t forbidden by Invisible XML, but might still be an error.
public
boolean
getAssertValidXmlCharacters()Raise an exception if invalid XML characters are used in text or attribute values that are serialized.
public
boolean
getAssertValidXmlNames()Raise an exception if invalid XML names are used in nonterminals that are serialized.
public
String
getGraphviz()Where’s the GraphViz ‘dot’ command?
public
boolean
getIgnoreBOM()If a UTF-8 input stream begins with a byte order mark (BOM), ignore it.
public
boolean
getIgnoreTrailingWhitespace()Ignore trailing whitespace?
If a parse fails where it would have succeeded if trailing whitespace was removed from the input, report success.
public
Logger
getLogger()- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Get the parser logger.
The logger controls what messages are displayed, and how. This component is also used by higher-level components such as CoffeeFilter, CoffeePot, and CoffeeSacks.
public
boolean
getMarkAmbiguities()- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Are ambiguities marked?
CoffeeGrinder doesn’t use this option, but it’s defined here so that it will be passed to CoffeeFilter. If ambiguities are to be marked, additional markup (attributes or processing instructions) are included in the forests returned in order to indicate where ambiguous choices were made).
public
boolean
getNormalizeLineEndings()- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Normalize line endings?
If line endings are normalized, all occurrences of #D, #D#A, #85, and #2028 in the input string are replaced with a single #A. This only applies to sequences of characters in the input.
public
String
getParserType()- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Get the parser type.
The parser type will be “Earley” or “GLL”.
public
boolean
getPedantic()Enforce strict compliance to the Invisible XML specification.
In pedantic mode, the processor won’t allow grammar extensions, like pragmas, that are not yet officially incorporated into the specification.
public
boolean
getPrefixParsing()- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Is prefix parsing enabled?
If an Earley parse fails, but some prefix of the input was successfully parsed, make that available for continuing the parse. This is optional mostly because it requires internally buffering some of the input tokens, but probably no more than a few.
public
boolean
getPrettyPrint()Attempt to pretty print the result?
If the result is pretty printed, extra newlines and spaces for indentation will be added to the result.
public
String
getPriorityStyle()- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Get the priority style.
Priorities can be computed on one of two styles:
max
orsum
.If the priority style is
max
, the priority of any given node is the highest priority value in the subgraph rooted at that node.If the priority style is
sum
, the priority of any given node is the sum of the priorities of the nodes in the subgraph below it.
The default is
max
.public
ProgressMonitor
getProgressMonitor()- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Get the progress monitor.
If a progress monitor is present, it will be called before, during, and after the parse.
public
boolean
getReturnChart()- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Return the Earley chart even for a successful parse?
If this option is enabled, the chart will be returned even for a successful parse. (If the parse fails, the chart is always returned.)
The chart can only be returned if the Earley parser is used. The GLL parser doesn’t manage the parse with state charts in the same way.
public
RuleRewriter
getRuleRewriter()public
boolean
getShowBnfNonterminals()public
boolean
getShowChart()Show the Earley chart in error results?
public
boolean
getShowMarks()public
String
getStartSymbol()Where should parsing start?
Invisible XML defines the start symbol as the symbol defined by the first rule in the grammar. In practice, the parser can start with any symbol in the grammar. This option returns the start symbol, if one was specified, or null. If null is returned, the parser will use the default start symbol. An exception will be raised if the symbol named is not defined in the grammar.
public
boolean
getStrictAmbiguity()If a grammar contains priority pragmas that uniquely determine the outcome of every potentially ambiguous choice, report that the grammar is ambiguous anyway.
public
boolean
getTrailingNewlineOnOutput()Make sure the output ends with a newline?
If this option is true, a newline will be added to the end of the output.
public
boolean
isSuppressedState(String state)Is the specified state suppressed?
The Invisible XML processor adds state values to the root element to report conditions such as ambiguity or a prefix parse. These states can be suppressed.
public
boolean
pragmaDisabled(String pragma)Is the specified pragma disabled?
The user can selectively disable pragmas in a grammar. This method determines whether the specified pragma is disabled.
public void setAllowMultipleDefinitions(boolean allow)
Set the getAllowMultipleDefinitions() property.
public void setAllowUndefinedSymbols(boolean allow)
Set the getAllowUndefinedSymbols() property.
Allowing undefined symbols implies getAllowUnproductiveSymbols() and getAllowUndefinedSymbols(). An undefined symbol is always part of an unproductive rule and avoiding errors for undefined rules often introduces undefined symbols.
public void setAllowUnproductiveSymbols(boolean allow)
Set the getAllowUnproductiveSymbols() property.
public void setAllowUnreachableSymbols(boolean allow)
Set the getAllowUnreachableSymbols() property.
public void setAssertValidXmlCharacters(boolean valid)
Set the getAssertValidXmlCharacters() property.
public void setAssertValidXmlNames(boolean valid)
Set the getAssertValidXmlNames() property.
public void setGraphviz(String dot)
Set the getGraphviz() property.
Setting the path to
null
disables SVG output.public void setIgnoreBOM(boolean ignore)
Set the getIgnoreBOM() property.
public void setIgnoreTrailingWhitespace(boolean ignore)
Set the getIgnoreTrailingWhitespace() property.
public void setLogger(Logger logger)
- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
- throws
NullPointerException
if the logger is null. Set the logger.
public void setMarkAmbiguities(boolean mark)
- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Shall ambiguities be marked?
public void setNormalizeLineEndings(boolean normalize)
- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Enable normalizing line endings?
public void setParserType(String parserType)
- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
- throws
IllegalArgumentException
if the parser type is not recognized Set the parser type.
You must specify “Earley” or “GLL”.
public void setPedantic(boolean pedantic)
Set the getPedantic() property.
In pedantic mode, the processor won’t allow grammar extensions, like pragmas, that are not yet officially incorporated into the specification. Enabling pedantic mode also resets the allowed grammar hygiene rules to their defaults.
public void setPrefixParsing(boolean prefixParsing)
- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Enable prefix parsing?
public void setPrettyPrint(boolean prettPrint)
Set the getPrettyPrint() property.
public void setPriorityStyle(String style)
- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
- throws
IllegalArgumentException
if the style is unrecognized. Set the priority style.
The style can be
max
orsum
.public void setProgressMonitor(ProgressMonitor monitor)
- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Set the progress monitor.
Setting the monitor to
null
disables monitoring.public void setReturnChart(boolean returnChart)
- Inherited from
org.nineml.coffeegrinder.parser.ParserOptions
Set the return chart property.
See getReturnChart().
public void setRuleRewriter(RuleRewriter rewriter)
public void setShowBnfNonterminals(boolean show)
public void setShowChart(boolean show)
Set the getShowChart() property.
public void setShowMarks(boolean show)
public void setStartSymbol(String name)
Set the getStartSymbol() property.
This option allows you to specify what the “seed” symbol should be for parsing. This will result in nonconformant parser behavior if the symbol specified isn’t the symbol defined by the first rule in the grammar.
public void setStrictAmbiguity(boolean strict)
Set the getStrictAmbiguity() property.
public void setTrailingNewlineOnOutput(boolean newline)
Set the getTrailingNewlineOnOutput() property.
public void suppressState(String state)
Suppress a state.
The Invisible XML processor adds state values to the root element to report conditions such as ambiguity or a prefix parse. These states can be suppressed.