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

public abstract static class Translet.ProductParser<R,A,B,C,D,E,F,G,H> extends Translet.Parser<R>
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 Details

    • arity

      protected final int arity
      Arity 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

      @Opt protected final @Opt Object 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

      @Opt protected final @Opt Class<R> cons
      Constructor to pack the sub-results into one result. Called by reflection.
    • p0

      protected final Translet.Parser<A> p0
      Parser of the 0th subresult.
    • p1

      protected final Translet.Parser<B> p1
      Parser of the 1st subresult. Can be ==NA if not applicable.
    • p2

      protected final Translet.Parser<C> p2
      Parser of the 2nd subresult. Can be ==NA if not applicable.
    • p3

      protected final Translet.Parser<D> p3
      Parser of the 3rd subresult. Can be ==NA if not applicable.
    • p4

      protected final Translet.Parser<E> p4
      Parser of the 4th subresult. Can be ==NA if not applicable.
    • p5

      protected final Translet.Parser<F> p5
      Parser of the 5th subresult. Can be ==NA if not applicable.
    • p6

      protected final Translet.Parser<G> p6
      Parser of the 6th subresult. Can be ==NA if not applicable.
    • p7

      protected final Translet.Parser<H> p7
      Parser of the 7th subresult. Can be ==NA if not applicable.
    • constructors

      protected final List<Constructor<R>> constructors
      List of all constructors found for the result type R by reflection.
    • subParsers

      protected final Translet.Parser<?>[] subParsers
      List of all sub-parsers, needed for name generation and parser loops.
    • separator

      @Opt @Opt Translet.Parser<?> separator
      A separator which must be appear between two (non-epsilon) applications of two sub-parsers.
  • Constructor Details

  • Method Details

    • withSeparator

      public Translet.ProductParser<R,A,B,C,D,E,F,G,H> withSeparator(Translet.Parser<?> sep)
      Set the separator which must appear between two non-epsilon-consuming applications of the sub-parsers. FIXME separator NOT YET PARSED
    • withSeparator

      public Translet.ProductParser<R,A,B,C,D,E,F,G,H> withSeparator(String sep)
      Set the separator which must appear between two non-epsilon-consuming applications of the sub-parsers. FIXME separator NOT YET PARSED
    • applyConstructor

      protected R applyConstructor(Object[] args)
      Tries to apply the constructors collected in constructors, one after the other, until the first succeeds.
      Throws:
      IllegalArgumentException - iff no success.
    • name_0

      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.
      Parameters:
      full - whether to show all technical details of the parser expression
      names - for displaying recursive references
      myConstructor - the name of the parse constructor to display