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

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 6, Choosing among alternatives.

disablePragmas, string

Pragmas to disable. The string may be a comma-separated list of pragma names, or the string #all to disable all pragmas.

enablePragmas, string

Pragmas to enable. The string may be a comma-separated list of pragma names, or the string #all to enable all pragmas.

By default, all pragmas are enabled. If both the disablePragmas and enablePragmas options are supplied, they will be processed in that order. (If you want to enable only a single pragma, you can disable them all, then enable the one you want.)

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

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.

5.2Invisible XML parser options

The following parser options are recognized:

allowMultipleDefinitions, boolean

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

allowUndefinedSymbols, boolean

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

allowUnproductiveSymbols, boolean

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

allowUnreachableSymbols, boolean

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

ignoreTrailingWhitespace, boolean

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

parser, string

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

showBnfNonterminals, boolean

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

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.

strictAmbiguity, boolean

If true, the parser will mark a result ambiguous even if a user-defined function was used to select alternatives. By default, if a user-defined function was called, the choice is considered unambiguous.

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.

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