public final class Grappa extends Object
Modifier and Type | Method and Description |
---|---|
static <P extends BaseParser<V>,V> |
createParser(Class<P> parserClass,
Object... constructorArgs)
Creates a parser object whose rule creation methods can then be used
with one of the
ParseRunner implementations. |
static <P extends BaseParser<V>,V> |
getByteCode(Class<P> parserClass)
Generate the byte code of a transformed parser class
|
public static <P extends BaseParser<V>,V> P createParser(@Nonnull Class<P> parserClass, Object... constructorArgs)
Creates a parser object whose rule creation methods can then be used
with one of the ParseRunner
implementations.
Since parboiled needs to extend your parser with certain extra logic
(e.g. to prevent infinite recursions in recursive rule definitions) you
cannot create your parser object yourself, but have to go through this
method. Also your parser class has to be derived from BaseParser
.
If you want to use a non-default constructor you can provide its
arguments to this method. Make sure your non-default constructor does not
use primitive type parameters (like "int") but rather their boxed
counterparts (like "Integer"), otherwise the constructor will not be
found.
Performing the rule analysis and extending the parser class is an expensive process (time-wise) and can take up to several hundred milliseconds for large grammars. However, this cost is only incurred once per parser class and class loader. Subsequent calls to this method are therefore fast once the initial extension has been performed.
parserClass
- the type of the parser to createconstructorArgs
- optional arguments to the parser class constructorpublic static <P extends BaseParser<V>,V> byte[] getByteCode(Class<P> parserClass)
When you create a parser using createParser(Class, Object...)
, Parboiled generates a new class which
is the one you actually use for parsing. This method allows to get the
byte code of such a generated class in a byte array.
P
- class of the parserV
- see BaseParser
parserClass
- the parser classRuntimeException
- byte code generation failureParserTransformer.getByteCode(Class)