Chapter 5Parser options

There are two kinds of parser options: parser construction options and Invisible XML parser options. For convenience, they’re both allowed in the same options map.

5.1Parser construction options

type, string

The input type. One of ixml (an invisible XML grammar), xml or vxml (a visible XML grammar), or cxml or compiled (a compiled XML grammar).

In most circumstances, you don’t need to specify the input type.

format, string

The output type. One of xml (an XML node; the default), json or json-data (a “data” map), or json-text (a “text” map).

choose-alternative, function

A function that will be called to choose between alternatives when the parse is ambiguous. The function must have one argument, a sequence of elements, and must return an xs:integer. See Chapter 7, Choosing among alternatives.

5.2Invisible XML parser options

The following parser options are recognized:

ignoreTrailingWhitespace, boolean

If true, trailing whitespace on the document input string is ignored.

suppressAmbiguousState, boolean

If a parse is ambiguous, Invisible XML mandates that an ixml:state attribute be added to the root element contining the value ambiguous. If this option is true, that state will be suppressed.

suppressPrefixState, boolean

If a parse consumes only a (proper) prefix of the input, Invisible XML mandates that an ixml:state attribute be added to the root element contining the value prefix. If this option is true, that state will be suppressed.

allowUndefinedSymbols, boolean

If true, the parser will attempt to use a grammar that contains undefined symbols.

allowUnreachableSymbols, boolean

If true, the parser will attempt to use a grammar that contains unreachable symbols.

allowUnproductiveSymbols, boolean

If true, the parser will attempt to use a grammar that contains unproductive symbols.

allowMultipleDefinitions, boolean

If true, the parser will attempt to use a grammar that contains multiple definitions for a given nonterminal.

allowMultipleDefinitions, boolean

If true, the parser will attempt to use a grammar that contains multiple definitions for a given nonterminal.

showMarks, boolean

If true, the parser will return all of the nonterminals in your grammar as elements, irrespective of their marks. The actual mark will be returned in an ixml:mark attribute.

showBnfNonterminals, boolean

If true, the parser will return all of the otherwise hidden nonterminals used in the parse.

parser, string

Selects the parser type, Earley for the Earley parser and GLL for the GLL parser. The Earley parser is the default.

The function will log errors (unrecognized options or values) and ignore the option.