Class Reading<D,T,A>

java.lang.Object
eu.bandm.tools.ramus.runtime2.AbstractExpression<D,T,A>
eu.bandm.tools.ramus.runtime2.Reading<D,T,A>
Type Parameters:
D - the type of document identifiers
T - the type of token types
A - the type of parsing results

public class Reading<D,T,A> extends AbstractExpression<D,T,A>
Constructive pairs of syntax and semantic interpretation.
  • Constructor Details

  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • content

      public static <D, T> Reading<D,T,Content<D,T>> content(Parser<D,T> syntax)
    • content

      @SafeVarargs public static <D, T> Reading<D,T,Content<D,T>> content(T... types)
      Match a token of any of the given token types and interpret as its content.
      Type Parameters:
      D - the type of document identifiers
      T - the type of token types
    • type

      @SafeVarargs public static <D, T> Reading<D,T,T> type(T... types)
      Match a token of any of the given token types and interpret as its type.
      Type Parameters:
      D - the type of document identifiers
      T - the type of token types
    • text

      @SafeVarargs public static <D, T> Reading<D,T,String> text(T... types)
      Match a token of any of the given token types and interpret as its text.
      Type Parameters:
      D - the type of document identifiers
      T - the type of token types
    • map

      public <B> Reading<D,T,B> map(Function<? super A,? extends B> fun)
      Match the same syntax as this expression, and apply a function to the result of semantic interpretation.
    • prepend

      public Reading<D,T,A> prepend(Parser<D,T> prefix)
      Match the syntax of this token with a prefix, with the same semantic interpretation. The prefix must be present, but does not contribute to interpretation.
    • prepend

      public Reading<D,T,A> prepend(T prefix)
      Match the syntax of this token with a prefix, with the same semantic interpretation. The prefix must be present, but does not contribute to interpretation.
    • append

      public Reading<D,T,A> append(Parser<D,T> suffix)
      Match the syntax of this token with a suffix, with the same semantic interpretation. The suffix must be present, but does not contribute to interpretation.
    • append

      public Reading<D,T,A> append(T suffix)
      Match the syntax of this token with a suffix, with the same semantic interpretation. The suffix must be present, but does not contribute to interpretation.
    • prepend

      @SafeVarargs public final Reading<D,T,A> prepend(T... suffix)
      Match the syntax of this token with a prefix, with the same semantic interpretation. The prefix must be present, but does not contribute to interpretation.
    • append

      @SafeVarargs public final Reading<D,T,A> append(T... prefix)
      Match the syntax of this token with a suffix, with the same semantic interpretation. The suffix must be present, but does not contribute to interpretation.
    • wrap

      public Reading<D,T,A> wrap(Parser<D,T> prefix, Parser<D,T> suffix)
      Match the syntax of this token with a prefix and a suffix, with the same semantic interpretation. The prefix and suffix must be present, but do not contribute to interpretation.
    • wrap

      public Reading<D,T,A> wrap(T prefix, T suffix)
      Match the syntax of this token with a prefix and a suffix, with the same semantic interpretation. The prefix and suffix must be present, but do not contribute to interpretation.
    • orElse

      public Reading<D,T,A> orElse(A defaultValue, Parser.Pragma... pragmas)
      Match the syntax of this token with the same interpretation, or otherwise match no input with the given default interpretation.
    • orElseGet

      public Reading<D,T,A> orElseGet(Supplier<? extends A> defaultValue, Parser.Pragma... pragmas)
      Match the syntax of this token with the same interpretation, or otherwise match no input with the given default interpretation.
    • optional

      public Reading<D,T,Optional<A>> optional(T defaultType)
      Match the syntax of this token with the same interpretation, or otherwise match no input.

      Whether input has been matched or not is reflected in the Optional interpretation result.

    • optional

      public Reading<D,T,Optional<A>> optional(Parser.Pragma... pragmas)
      Match the syntax of this token with the same interpretation, or otherwise match no input.

      Whether input has been matched or not is reflected in the Optional interpretation result.

    • star

      public Reading<D,T,List<A>> star(Parser.Pragma... pragmas)
      Match zero or more repetitions of this expression.

      The interpretation results are collected in a List.

    • star

      public Reading<D,T,List<A>> star(Parser<D,T> sep, Parser.Pragma... pragmas)
      Match zero or more repetitions of this expression with intervening separator syntax.

      The interpretation results are collected in a List.

    • star

      public Reading<D,T,List<A>> star(T sep, Parser.Pragma... pragmas)
      Match zero or more repetitions of this expression with intervening separator syntax.

      The interpretation results are collected in a List.

    • plus

      public Reading<D,T,List<A>> plus(Parser.Pragma... pragmas)
      Match one or more repetitions of this expression.

      The interpretation results are collected in a non-empty List.

    • plus

      public Reading<D,T,List<A>> plus(Parser<D,T> sep, Parser.Pragma... pragmas)
      Match one or more repetitions of this expression with intervening separator syntax.

      The interpretation results are collected in a non-empty List.

    • plus

      public Reading<D,T,List<A>> plus(T sep, Parser.Pragma... pragmas)
      Match one or more repetitions of this expression with intervening separator syntax.

      The interpretation results are collected in a non-empty List.

    • constant

      public static <D, T, A> Reading<D,T,A> constant(Parser<D,T> syntax, A value)
      Match the given syntax with a constant semantic interpretation.
    • constant

      public static <D, T, A> Reading<D,T,A> constant(T type, A value)
      Match the given syntax with a constant semantic interpretation.
    • constant

      public static <D, T, A> Reading<D,T,A> constant(T type, String text, A value)
      Match the given syntax with a constant semantic interpretation.
    • constantEpsilon

      public static <D, T, A> Reading<D,T,A> constantEpsilon(A value)
      Match no input with a constant semantic interpretation.
    • choice

      @SafeVarargs public static <D, T, A> Reading<D,T,A> choice(Reading<D,T,? extends A>... alts)
    • orElse

      public Reading<D,T,A> orElse(Reading<D,T,A> other)
    • lookup

      public static <D, T, A> Reading<D,T,A> lookup(Class<A> type, Map<T,? extends A> model)
    • lookup

      public static <D, T, A> Reading<D,T,A> lookup(Map<T,? extends A> model)
    • lookahead

      public static <D, T, A> Reading<D,T,A> lookahead(Map<T,Reading<D,T,? extends A>> map)
    • andThenCombining

      public <B, C> Reading<D,T,C> andThenCombining(Reading<D,T,B> other, BiFunction<? super A,? super B,? extends C> pair)
      Match the syntax of this expression followed by that of another, combining the semantic interpretations with a function.
    • mapsTo

      public <B> Reading<D,T,Map.Entry<A,B>> mapsTo(Reading<D,T,B> other)
      Match the syntax of this expression followed by that of another, combining the semantic interpretations as a Map.Entry.
    • andThenDependent

      public <B> Reading<D,T,B> andThenDependent(Reading<D,T,Function<? super A,? extends B>> other)
      Match the syntax of this expression followed by that of another, combining the semantic interpretations.
    • fix

      public static <D, T, A> Reading<D,T,A> fix(Function<Reading<D,T,A>,Reading<D,T,A>> loop)
      Make a recursive expression.
    • unit

      public static <D, T> Reading<D,T,Void> unit(Parser<D,T> syntax)
      Match the given syntax with no semantic interpretation.
    • unit

      @SafeVarargs public static <D, T> Reading<D,T,Void> unit(T... types)
      Match the given syntax with no semantic interpretation.
    • unit

      public static <D, T> Reading<D,T,Void> unit()
      Match no input with no semantic interpretation.
    • counit

      public static <D, T, A> Reading<D,T,A> counit(A value)
    • ifThenElse

      public static <D, T, A> Reading<D,T,A> ifThenElse(T type, Reading<D,T,? extends A> thenBranch, Reading<D,T,? extends A> elseBranch)
      Choose between two expression depending on the type of the next token.
    • access

      public static <D, T, A> Reading<D,T,A> access(Class<A> type, Object key)
      Retrieve the value assigned to a given key as the semantic interpretation.

      No input tokens are matched.

      Type Parameters:
      D - the type of document identifiers
      T - the type of token types
      A - the type of parsing results
      Parameters:
      type - the expected type of the value
      key - the key
      See Also:
    • assigning

      public Reading<D,T,A> assigning(Object key)
      Match the same syntax as this expression, and assign the semantic interpretation to a given key.
      Parameters:
      key - the key
      See Also:
    • withScope

      public Reading<D,T,A> withScope(Map<Object,? extends Data> initializers)
      Match the same syntax as this expression, but perform semantic interpretation in a local scope.

      All assignments to keys performed by the this expression are undone afterwards.

      Parameters:
      initializers - a map of initial local values for some keys
      See Also:
    • guard

      public Reading<D,T,A> guard(Predicate<? super A> condition, Function<? super A,List<SimpleMessage<D>>> error)
    • process

      public Reading.Result<D,T,A> process(Supplier<? extends Token<D,T>> in)
    • process

      public Reading.Result<D,T,A> process(Parser.Input<D,T> in)
    • leftAssoc

      public static <D, T, A> Reading<D,T,A> leftAssoc(Reading.OperatorFactory<D,T,A> operator, Reading<D,T,A> operand, T... operatorTypes)
      Tactic for left-associative operators.

      The resulting expression will match inputs of the form "e1 op1 ... opn-1 en", and interpret them as an AST of the form opn-1(... op1(e1, e2) ..., en).

      It is assumed that all operands ei conform to the same syntax and interpretation, and that operators are distinguished by token type.

      Type Parameters:
      D - the type of document identifiers
      T - the type of token types
      A - the type of parsing results
      Parameters:
      operator - a function to construct binary AST nodes for operators
      operand - the expression for operands
      operatorTypes - an array containing the token types that denote operators
      See Also:
    • leftAssoc

      public static <D, T, A> Reading<D,T,A> leftAssoc(Reading<D,T,A> headOperand, Reading.OperatorFactory<D,T,A> operator, Reading<D,T,A> tailOperand, T... operatorTypes)
    • rightAssoc

      public static <D, T, A> Reading<D,T,A> rightAssoc(Reading.OperatorFactory<D,T,A> operator, Reading<D,T,A> operand, T... operatorTypes)
      Tactic for right-associative operators.

      The resulting expression will match inputs of the form "e1 op1 ... opn-1 en", and interpret them as an AST of the form op1(e1, ... opn-1(en-1, en)...).

      It is assumed that all operands ei conform to the same syntax and interpretation, and that operators are distinguished by token type.

      Type Parameters:
      D - the type of document identifiers
      T - the type of token types
      A - the type of parsing results
      Parameters:
      operator - a function to construct binary AST nodes for operators
      operand - the expression for operands
      operatorTypes - an array containing the token types that denote operators
      See Also:
    • nonAssoc

      public static <D, T, A> Reading<D,T,A> nonAssoc(Reading.OperatorFactory<D,T,A> operator, Reading<D,T,A> operand, T... operatorTypes)
      Tactic for non-associative operators.

      The resulting expression will match inputs of the form "e1 op e2", and interpret them as an AST of the form op(e1, e2).

      It is assumed that all operands ei conform to the same syntax and interpretation, and that operators are distinguished by token type.

      Type Parameters:
      D - the type of document identifiers
      T - the type of token types
      A - the type of parsing results
      Parameters:
      operator - a function to construct binary AST nodes for operators
      operand - the expression for operands
      operatorTypes - an array containing the token types that denote operators
      See Also:
    • withOtherTokenSource

      public <K, L> Reading<D,T,A> withOtherTokenSource(LookaheadTokenMultiplexer<K,D,T,L> multi, K newKey)