public final class Config extends Object
Options can be configured in the grammar description
using pairs of key-value descriptions. The set of
supported keys is described in the enumeration Config.Keys.
Configuration instances can then be built from such a list
of key-value bindings
(see ofOptions(Relevance, List, Reporter)).
Each option can be relevant to either solely lexer generation or parser generation, or to both.
For better declarative support, a configuration instance can also be built using a builder class with chained methods for each configurable option.
Finally, a DEFAULT configuration is available.
ofOptions(Relevance, List, Reporter)| Modifier and Type | Class and Description |
|---|---|
static class |
Config.Builder
A builder class for configurations,
which allows setting all options using method chaining.
|
static class |
Config.Keys
Enumeration of the keys for configurable options.
|
static class |
Config.Relevance
Enumeration representing the relevance of a
configuration: it can be usable only within a lexer
description, a parser description, or both.
|
| Modifier and Type | Field and Description |
|---|---|
String |
classAnnotations
Annotations which must be added to the generated
parser or lexer class
|
static Config |
DEFAULT
The default configuration for grammar generation
|
boolean |
positions
Whether the parser should keep positions for
non-terminal symbols as well as terminal symbols
|
String |
tokenAnnotations
Annotations which must be added to the generated
token class in a generated parser
|
| Constructor and Description |
|---|
Config(EnumMap<Config.Keys,Object> options)
Builds a configuration from the given options.
|
| Modifier and Type | Method and Description |
|---|---|
static Config |
ofGrammar(Grammar grammar,
@Nullable Reporter reporter)
|
static Config |
ofLexer(Lexer lexer,
@Nullable Reporter reporter)
|
static Config |
ofOptions(Config.Relevance relevance,
List<Option> options,
@Nullable Reporter reporter)
This method never fails to build a valid configuration, but
can report unexpected things such as illegal keys or values
through the reporter.
|
static Config |
ofPGrammar(PGrammar grammar,
@Nullable Reporter reporter)
|
static Config.Builder |
start() |
public final boolean positions
public final String classAnnotations
public final String tokenAnnotations
public static final Config DEFAULT
public Config(EnumMap<Config.Keys,Object> options)
options,
those that are unspecified will take on default values.options - ClassCastException - if some options are
associated to incompatible value typespublic static Config ofOptions(Config.Relevance relevance, List<Option> options, @Nullable Reporter reporter)
relevance - context where the configuration should be relevantoptions - reporter - can be null if no reporting is requiredoptionspublic static Config ofPGrammar(PGrammar grammar, @Nullable Reporter reporter)
grammar - reporter - grammarpublic static Config ofGrammar(Grammar grammar, @Nullable Reporter reporter)
grammar - reporter - grammarpublic static Config ofLexer(Lexer lexer, @Nullable Reporter reporter)
lexer - reporter - lexerpublic static Config.Builder start()