Chapter 2Parser options

2.1ParserOptions

The org.nineml.coffeegrinder.parser.ParserOptions class.

Parser options are extended by other members of the NineML family to provide additional options. This class 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.

2.1.1Constructor summary

Public constructors for the org.nineml.coffeegrinder.parser.ParserOptions class.

public ParserOptions()

Create parser options.

The initial logger will be a DefaultLogger initialized with readSystemProperties().

public ParserOptions(Logger logger)

Create parser options with an explicit logger.

public ParserOptions(ParserOptions copy)

Create parser options by copying an existing set of options.

Note that the logger and monitor are not copied, so the created options share the same logger and progress monitor as the options copied.

2.1.2Method summary

Public methods on the org.nineml.coffeegrinder.parser.ParserOptions class.

public Logger getLogger()

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()

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()

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()

Get the parser type.

The parser type will be “Earley” or “GLL”.

public boolean getPrefixParsing()

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 String getPriorityStyle()

Get the priority style.

Priorities can be computed on one of two styles: max or sum.

  • 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()

Get the progress monitor.

If a progress monitor is present, it will be called before, during, and after the parse.

public boolean getReturnChart()

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 void setLogger(Logger logger)
throws NullPointerException if the logger is null.

Set the logger.

public void setMarkAmbiguities(boolean mark)

Shall ambiguities be marked?

public void setNormalizeLineEndings(boolean normalize)

Enable normalizing line endings?

See getNormalizeLineEndings().

public void setParserType(String parserType)
throws IllegalArgumentException if the parser type is not recognized

Set the parser type.

You must specify “Earley” or “GLL”.

public void setPrefixParsing(boolean prefixParsing)

Enable prefix parsing?

public void setPriorityStyle(String style)
throws IllegalArgumentException if the style is unrecognized.

Set the priority style.

The style can be max or sum.

public void setProgressMonitor(ProgressMonitor monitor)

Set the progress monitor.

Setting the monitor to null disables monitoring.

public void setReturnChart(boolean returnChart)

Set the return chart property.

See getReturnChart().

2.2DefaultLogger

The org.nineml.logging.DefaultLogger class.

This class extends org.nineml.logging.Logger.

2.2.1Constructor summary

Public constructors for the org.nineml.logging.DefaultLogger class.

public DefaultLogger()

2.2.2Method summary

Public methods on the org.nineml.logging.DefaultLogger class.

public void clearLogLevels()
Inherited from org.nineml.logging.Logger

Clear the log levels.

This method removes all configured log levels. All subsequent logging (until more levels are set) will be based entirely on the default log level.

public void debug(String category String format Object[] params)

Issue a debug message.

public void error(String category String format Object[] params)

Issue an error message.

public int getDefaultLogLevel()
Inherited from org.nineml.logging.Logger

Get the default log level

public Set<String> getLogCategories()
Inherited from org.nineml.logging.Logger

Get all of the configured log level categories

public int getLogLevel(String category)
Inherited from org.nineml.logging.Logger
throws NullPointerException if the category is null

Get the log level for a particular category.

Category names are not case sensitive.

public void info(String category String format Object[] params)

Issue an informational message.

public void readSystemProperties()
Inherited from org.nineml.logging.Logger

Set the log levels by reading system properties.

The properties are:

  • defaultLogLevelProperty

    Must be an integer specifying the initial default log level or one of the strings “silent”, “error”, “warning”, “info”, “debug”, or “trace”. Absent this property, the default level is 5, or “error”.

  • logLevelsProperty

    This property specifies a mapping between log categories and the log level for each category. The format of the property is a list of comma or space separated values of the form “category:level”. The category “*” sets the default log level.

public void setDefaultLogLevel(int level)
Inherited from org.nineml.logging.Logger

Set the default log level.

If the level is less than zero, it will be set to 0 (silent).

public void setDefaultLogLevel(String level)
Inherited from org.nineml.logging.Logger
throws NullPointerException if the level is null.

Set the default log level.

The level must be “silent”, “error”, “warning”, “info”, “debug”, or “trace”. If an invalid value is specified, “error” is used.

public void setLogLevel(String category int level)
Inherited from org.nineml.logging.Logger
throws NullPointerException if the category is null.

Set the log level for a particular category.

public void setLogLevel(String category String level)
Inherited from org.nineml.logging.Logger
throws NullPointerException if the category or level is null.

Set the log level for a particular category.

The level must be “silent”, “error”, “warning”, “info”, “debug”, or “trace”. If an invalid value is specified, “error” is used.

public void setLogLevels(String config)
Inherited from org.nineml.logging.Logger

Set the log levels for a set of categories.

The config specifies a mapping between log categories and the log level for each category. The format of the string is a list of comma or space separated values of the form “category:level”.

The level must be an integer or one of “silent”, “error”, “warning”, “info”, “debug”, or “trace”. If an invalid value is specified, “error” is used. The category “*” sets the default log level.

public void trace(String category String format Object[] params)

Issue a trace message.

public void warn(String category String format Object[] params)

Issue a warning message.