public static class Translet.PermutationParser<R,A,B,C,D,E,F,G,H> extends Translet.ProductParser<R,A,B,C,D,E,F,G,H>
Translet.ProductParser
which accepts all permutations of sub-parsers.
As with product parsers in general, after all sub-parsers have been evaluated
to their results,
a function object or a constructor can be applied to these to construct the result.
The field separator
gives optionally a non-terminal which must
appear between all inputs consumed by sub-parsers which are not empty.
The treatment of empty (="epsilon") results must be special to prevent explosion of redundant solutions, and is described in detail in Lepper,Trancón "Translets", Bad Honnef 2018, pgs.113-130.
Modifier and Type | Field and Description |
---|---|
protected Multimap<Translet.Parser<?>,Translet.State<?>> |
parser2state
Maps all sub-parsers to all states the created during all parsing apptempts.
|
arity, cons, constructors, f, p0, p1, p2, p3, p4, p5, p6, p7, separator, subParsers
Constructor and Description |
---|
PermutationParser(int arity,
@Opt Object f,
@Opt Class<R> cons,
Translet.Parser<A> p0,
Translet.Parser<B> p1,
Translet.Parser<C> p2,
Translet.Parser<D> p3,
Translet.Parser<E> p4,
Translet.Parser<F> p5,
Translet.Parser<G> p6,
Translet.Parser<H> p7)
This constructor is called by the static factory methods and should
normally not be called directly.
|
Modifier and Type | Method and Description |
---|---|
protected Object[] |
args(Translet.State<?> s)
Collects results of sub-parsers out of the selected parse tree "s"
and stores them in one array for constructor application by reflection.
|
protected <R> R |
findResult_p(Translet.State<?> s,
Translet.Parser<R> p)
Aux function for casting only: find the result of the application of
parser "p" in the (successful) parse tree ending in state "s".
|
protected Translet.Parser<?> |
makerestperm(BitSet tested,
int tested1)
Construct a new permutation parser from all sub-parsers not yet tested.
|
Format |
name(boolean full,
Map<Translet.Recursive,String> names)
Returns a user-readable text representation.
|
static BitSet |
or(BitSet a,
BitSet b)
Auxiliary function to create a new Java bitset which is the or-ing of the two args.
|
static BitSet |
or(BitSet a,
int b)
Auxiliary function to create a new Java bitset which is the or-ing of the two args.
|
Set<Translet.State<R>> |
parseOneState(Translet.State<?> inState,
Set<Translet.Alternative> alternatives)
Calculate a set of possible successor states by applying this parser
to the incoming state and append all altenatives found underways to
the parameter "alternatives".
|
protected Set<? extends Translet.State<?>> |
test2(Translet.State<?> oneState,
BitSet tested,
BitSet toEpsilon,
Set<Translet.Alternative> alternatives)
Tests all permutations by breadth first search: first testing all sub-parsers
once, and then calling this function recursively for all states resulting
from these calls.
|
String |
unparse(Object key)
Reverse the parsing process (as far as possible) and deliver a
string representation which when parsed delivered the parse result.
|
applyConstructor, name_0, withSeparator, withSeparator
executeStoring, isTerminal, mparse, name, parseEpsilon, stripOpt, toString, toString, wrapResult
protected Multimap<Translet.Parser<?>,Translet.State<?>> parser2state
public PermutationParser(int arity, @Opt @Opt Object f, @Opt @Opt Class<R> cons, Translet.Parser<A> p0, Translet.Parser<B> p1, Translet.Parser<C> p2, Translet.Parser<D> p3, Translet.Parser<E> p4, Translet.Parser<F> p5, Translet.Parser<G> p6, Translet.Parser<H> p7)
Translet.na
if not required.
Either a function can given by "f" or a class by "cons".
If neither, the results are discarded.public String unparse(Object key)
Translet.Parser
unparse
in class Translet.Parser<R>
public static BitSet or(BitSet a, BitSet b)
public static BitSet or(BitSet a, int b)
protected Translet.Parser<?> makerestperm(BitSet tested, int tested1)
tested
- set of the indexes of already tested sub-parsers.tested1
- index of another tested sub-parserprotected Set<? extends Translet.State<?>> test2(Translet.State<?> oneState, BitSet tested, BitSet toEpsilon, Set<Translet.Alternative> alternatives)
oneState
- the state from which these tests starttested
- already used and not to be parsed againtoEpsilon
- epsilon case already done, no further empty match is acceptablealternative
- the usual output parameter (result set) for non-successful alternativesprotected Object[] args(Translet.State<?> s)
s
- the last state in the successful parsing tree which shall be evaluatedprotected <R> R findResult_p(Translet.State<?> s, Translet.Parser<R> p)
Translet.findResult(State,Set)
public Set<Translet.State<R>> parseOneState(Translet.State<?> inState, Set<Translet.Alternative> alternatives)
Translet.Parser
parseOneState
in class Translet.Parser<R>
public Format name(boolean full, Map<Translet.Recursive,String> names)
Translet.Parser
name
in class Translet.Parser<R>
full
- whether storage constructs do appear in the rendering.names
- a map for managing the renderings of recursive calls