Class Translet.State<R>

java.lang.Object
eu.bandm.tscore.base.Translet.State<R>
Enclosing class:
Translet

public static class Translet.State<R> extends Object
Central data type for parser operation. Combines input situation, currently applied Translet.Parser, delivered Result, and the preceding state, thus forming a kind of parse tree in post order notation:
                                _______/ ----------- Parser(SEQU)
       ________________________/  ______/                 ^
     Parser                  Parser                       |
       ^                      ^                           |
       |                      |.parser                    |
   +------------+  .pre     +------------+   .pre    +------------+              
   | State      | <----     | State      |  <-----   | State      | 
   +------------+           +------------+           +------------+              
                                |.s |.pos
                                v   v
                            "toConsume"
  
State objects are added (a) when input characters are consumed, (b) when functions are applied for further result generation, or (c) when a storage action must be memorized for later execution.

".s" is constant and always simply copied, to be accessible by the terminal symbol parsing functions; ".pos" is advancing and reflects the situation AFTER ".parser" has consumed.

Parsing is executed in a breadth-first search, so that finally different successful parsing trees can coexist. All STORING operations are not yet performed but done ex-parte-post, after one of these solutions has been selected.

  • Field Details

    • parser

      final Translet.Parser<R> parser
      The translet parser which has consumed to produce this state.
    • pre

      @Opt final @Opt Translet.State<?> pre
      The preceding state. Only == null for the very first state.
    • s

      final String s
      The input data on which all parsers operate.
    • pos

      final int pos
      The position after parsing.
    • depth

      final int depth
      FIXME ????
    • result

      @Opt final R result
    • p_atEnd

      public static final Predicate<Translet.State> p_atEnd
  • Method Details

    • initState

      public static Translet.State<Object> initState(String s, int pos)
      Create an initial state with only the input data, no parser or result yet.
    • succ

      public <N, M extends N> Translet.State<N> succ(Translet.Parser<N> parser, M result)
      Return a new State, which is successor of "this", and in which "parser" has delivered "result", but no input has been consumed.
    • succ

      public <N, M extends N> Translet.State<N> succ(Translet.Parser<N> parser, int pos, M result)
      Return a new State, which is successor of "this", and in which "parser" has delivered "result" and consumed input up to "pos".
    • executeStoring

      Step back through the chain of parser states and execute all store operation. This is delegated to Translet.Parser.executeStoring(Translet.State,Event,Location,MessageReceiver). Only the instances of some dedicated parser classes really execute storing.
      Parameters:
      e - the event which is used as key for all the data maps
      loc - the location of the whole expression, used in all error messages generated by storing.
      msg - drain of error messages.
    • atEnd

      public boolean atEnd()
      Return whether parsing has reached the end of the input string.
    • consumed

      public String consumed()
      Returns the character input consumed DIRECTLY by the parser of this state, i.e. iff it is a terminal symbol. Both ".pos" and ".pre.pos" must be considered.
    • lookingAt

      public String lookingAt()
      Return the current rest of the input string.
    • simpleString

      public String simpleString()
      Deliver printable representation only of this state.
    • toString

      public String toString()
      Deliver printable representation of the whole chain of states ending here.
      Overrides:
      toString in class Object