Package eu.bandm.tscore.base
Class Translet.ProductParser<R,A,B,C,D,E,F,G,H>
java.lang.Object
eu.bandm.tscore.base.Translet.Parser<R>
eu.bandm.tscore.base.Translet.ProductParser<R,A,B,C,D,E,F,G,H>
- Direct Known Subclasses:
Translet.PermutationParser
,Translet.SequParser
- Enclosing class:
- Translet
Common superclass for Parsers which produce a product type as their result.
Its subclasses realize sequences and permutations.
Currently maximally eight(8) sub-parsers are supported.
Either a function can be provided for packing the sub-results into one result,
or a
Class
object, from which a constructor is retrieved
by reflection.
// ????? FIXME The first method is type safe, the second is just "try and error".
A function may return any value, including null. All are taken as success.
To reject acceptance, the function must throw any exception, e.g. via a
MessageThrower
.
If neither function nor constructor is given, one new state will come out,
showing successful parsing, but its "result" field will be set to "null".
(In this case the storing of the results is
left to storage operators contained in the sub-expressions.)-
Field Summary
Modifier and TypeFieldDescriptionprotected final int
Arity of the tuple type, intended to be in the range 2 to 8.Constructor to pack the sub-results into one result.protected final List<Constructor<R>>
List of all constructors found for the result type R by reflection.Function to pack the sub-results into one result.protected final Translet.Parser<A>
Parser of the 0th subresult.protected final Translet.Parser<B>
Parser of the 1st subresult.protected final Translet.Parser<C>
Parser of the 2nd subresult.protected final Translet.Parser<D>
Parser of the 3rd subresult.protected final Translet.Parser<E>
Parser of the 4th subresult.protected final Translet.Parser<F>
Parser of the 5th subresult.protected final Translet.Parser<G>
Parser of the 6th subresult.protected final Translet.Parser<H>
Parser of the 7th subresult.(package private) @Opt Translet.Parser<?>
A separator which must be appear between two (non-epsilon) applications of two sub-parsers.protected final Translet.Parser<?>[]
List of all sub-parsers, needed for name generation and parser loops. -
Constructor Summary
ModifierConstructorDescriptionprotected
ProductParser
(int arity, @Opt Object f, @Opt Class<R> cons, Translet.Parser<A> p0, @Opt Translet.Parser<B> p1, @Opt Translet.Parser<C> p2, @Opt Translet.Parser<D> p3, @Opt Translet.Parser<E> p4, @Opt Translet.Parser<F> p5, @Opt Translet.Parser<G> p6, @Opt Translet.Parser<H> p7) Only constructor, called by the sub-classes. -
Method Summary
Modifier and TypeMethodDescriptionprotected R
applyConstructor
(Object[] args) Tries to apply the constructors collected inconstructors
, one after the other, until the first succeeds.protected Format
name_0
(boolean full, Map<Translet.Recursive, String> names, String myConstructor) Construct the part of the names which is common for all subclasses.withSeparator
(Translet.Parser<?> sep) Set the separator which must appear between two non-epsilon-consuming applications of the sub-parsers.withSeparator
(String sep) Set the separator which must appear between two non-epsilon-consuming applications of the sub-parsers.Methods inherited from class eu.bandm.tscore.base.Translet.Parser
executeStoring, isTerminal, mparse, name, name, parseEpsilon, parseOneState, stripOpt, toString, toString, unparse
-
Field Details
-
arity
protected final int arityArity of the tuple type, intended to be in the range 2 to 8. (Currently the case 1 is also possible for just applying the function. -
f
Function to pack the sub-results into one result. Has no Java type, because it can be of type "Function<A,R>" or "BiFunction<A,B,R>" or "Function3<A,B,C,R>" etc. -
cons
Constructor to pack the sub-results into one result. Called by reflection. -
p0
Parser of the 0th subresult. -
p1
Parser of the 1st subresult. Can be ==NA if not applicable. -
p2
Parser of the 2nd subresult. Can be ==NA if not applicable. -
p3
Parser of the 3rd subresult. Can be ==NA if not applicable. -
p4
Parser of the 4th subresult. Can be ==NA if not applicable. -
p5
Parser of the 5th subresult. Can be ==NA if not applicable. -
p6
Parser of the 6th subresult. Can be ==NA if not applicable. -
p7
Parser of the 7th subresult. Can be ==NA if not applicable. -
constructors
List of all constructors found for the result type R by reflection. -
subParsers
List of all sub-parsers, needed for name generation and parser loops. -
separator
A separator which must be appear between two (non-epsilon) applications of two sub-parsers.
-
-
Constructor Details
-
ProductParser
protected ProductParser(int arity, @Opt @Opt Object f, @Opt @Opt Class<R> cons, Translet.Parser<A> p0, @Opt @Opt Translet.Parser<B> p1, @Opt @Opt Translet.Parser<C> p2, @Opt @Opt Translet.Parser<D> p3, @Opt @Opt Translet.Parser<E> p4, @Opt @Opt Translet.Parser<F> p5, @Opt @Opt Translet.Parser<G> p6, @Opt @Opt Translet.Parser<H> p7) Only constructor, called by the sub-classes. The "arity" value, the arity of "f" and the parsers must be in sync. All parsers must be !=null and set toTranslet.na
if not required. Either a function can given by "f" or a class by "cons". If neither, the results are discarded.
-
-
Method Details
-
withSeparator
Set the separator which must appear between two non-epsilon-consuming applications of the sub-parsers. FIXME separator NOT YET PARSED -
withSeparator
Set the separator which must appear between two non-epsilon-consuming applications of the sub-parsers. FIXME separator NOT YET PARSED -
applyConstructor
Tries to apply the constructors collected inconstructors
, one after the other, until the first succeeds.- Throws:
IllegalArgumentException
- iff no success.
-
name_0
Construct the part of the names which is common for all subclasses.- Parameters:
full
- whether to show all technical details of the parser expressionnames
- for displaying recursive referencesmyConstructor
- the name of the parse constructor to display
-