Package eu.bandm.tscore.base
Class Translet.PermutationParser<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>
eu.bandm.tscore.base.Translet.PermutationParser<R,A,B,C,D,E,F,G,H>
- Enclosing class:
Translet
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>
Variant of
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 Translet.ProductParser.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Multimap<Translet.Parser<?>, Translet.State<?>> Maps all sub-parsers to all states the created during all parsing apptempts.Fields inherited from class eu.bandm.tscore.base.Translet.ProductParser
arity, cons, constructors, f, p0, p1, p2, p3, p4, p5, p6, p7, separator, subParsers -
Constructor Summary
ConstructorsConstructorDescriptionPermutationParser(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. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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> RfindResult_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.name(boolean full, Map<Translet.Recursive, String> names) Returns a user-readable text representation.static BitSetAuxiliary function to create a new Java bitset which is the or-ing of the two args.static BitSetAuxiliary function to create a new Java bitset which is the or-ing of the two args.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.Reverse the parsing process (as far as possible) and deliver a string representation which when parsed delivered the parse result.Methods inherited from class eu.bandm.tscore.base.Translet.ProductParser
applyConstructor, name_0, withSeparator, withSeparatorMethods inherited from class eu.bandm.tscore.base.Translet.Parser
executeStoring, isTerminal, mparse, name, parseEpsilon, stripOpt, toString, toString
-
Field Details
-
parser2state
Maps all sub-parsers to all states the created during all parsing apptempts. The image sets will later be used to find the result of one particular sub-parser in one particular parsing tree.
-
-
Constructor Details
-
PermutationParser
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) This constructor is called by the static factory methods and should normally not be called directly. The "arity" value, the arity of "f" and the parsers must be in sync. All parsers must be !=null and set toTranslet.naif not required. Either a function can given by "f" or a class by "cons". If neither, the results are discarded.
-
-
Method Details
-
unparse
Description copied from class:Translet.ParserReverse the parsing process (as far as possible) and deliver a string representation which when parsed delivered the parse result.- Specified by:
unparsein classTranslet.Parser<R>
-
or
Auxiliary function to create a new Java bitset which is the or-ing of the two args. -
or
Auxiliary function to create a new Java bitset which is the or-ing of the two args. -
makerestperm
Construct a new permutation parser from all sub-parsers not yet tested. In the special case that only one(1) is left, this is returned immediately.- Parameters:
tested- set of the indexes of already tested sub-parsers.tested1- index of another tested sub-parser
-
test2
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. Epsilon results are treated specially and further narrowed.- Parameters:
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 acceptablealternatives- the usual output parameter (result set) for non-successful alternatives
-
args
Collects results of sub-parsers out of the selected parse tree "s" and stores them in one array for constructor application by reflection.- Parameters:
s- the last state in the successful parsing tree which shall be evaluated
-
findResult_p
Aux function for casting only: find the result of the application of parser "p" in the (successful) parse tree ending in state "s".- See Also:
-
parseOneState
public Set<Translet.State<R>> parseOneState(Translet.State<?> inState, Set<Translet.Alternative> alternatives) Description copied from class:Translet.ParserCalculate a set of possible successor states by applying this parser to the incoming state and append all altenatives found underways to the parameter "alternatives". This method is specific to and overridden by the subclasses of Parser.- Specified by:
parseOneStatein classTranslet.Parser<R>
-
name
Description copied from class:Translet.ParserReturns a user-readable text representation. This is in most cases, but not always, source text to construct the parser.- Specified by:
namein classTranslet.Parser<R>- Parameters:
full- whether storage constructs do appear in the rendering.names- a map for managing the renderings of recursive calls
-