public class GrammarDefinition extends Object
To create a new grammar definition subclass GrammarDefinition. For every production call
def(String, Parser) giving the parsers a name. The start production
should be named 'start'.
To refer to other productions use ref(String). To redefine or attach
actions to productions use redef(String, Function), redef(String, org.petitparser.parser.Parser) and action(String, Function).
To build the resulting grammar call build(), or wrap it in the class
GrammarParser.
| Constructor | Description |
|---|---|
GrammarDefinition() |
| Modifier and Type | Method | Description |
|---|---|---|
protected <S,T> void |
action(String name,
Function<S,T> function) |
Attaches an action
function to an existing production name. |
Parser |
build() |
Builds a parser starting from the production
"start". |
Parser |
build(String name) |
Builds a parser starting from the provided production
name. |
protected void |
def(String name,
Parser parser) |
Defines a production with a
name and a parser. |
protected void |
redef(String name,
Function<Parser,Parser> function) |
Redefines an existing production with a
name and a function producing a new
parser. |
protected void |
redef(String name,
Parser parser) |
Redefines an existing production with a
name and a new parser. |
protected Parser |
ref(String name) |
Returns a reference to the production with the given
name. |
protected final Parser ref(String name)
name.protected final void def(String name, Parser parser)
name and a parser.protected final void redef(String name, Parser parser)
name and a new parser.protected final void redef(String name, Function<Parser,Parser> function)
name and a function producing a new
parser. Only call this method during initialization.protected final <S,T> void action(String name, Function<S,T> function)
function to an existing production name. Only call this
method during initialization.public Parser build()
"start".Copyright © 2018 PetitParser. All rights reserved.