Class Expression<D,T,A>

java.lang.Object
eu.bandm.tools.ramus.runtime2.AbstractExpression<D,T,A>
eu.bandm.tools.ramus.runtime2.Expression<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 Expression<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> Expression<D,T,Content<D,T>> content(Parser<D,T> syntax)
    • content

      @SafeVarargs public static <D, T> Expression<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> Expression<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> Expression<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> Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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 Expression<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> Expression<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> Expression<D,T,A> constant(T type, A value)
      Match the given syntax with a constant semantic interpretation.
    • constant

      public static <D, T, A> Expression<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> Expression<D,T,A> constantEpsilon(A value)
      Match no input with a constant semantic interpretation.
    • choice

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

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

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

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

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

      public <B, C> Expression<D,T,C> andThenCombining(Expression<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> Expression<D,T,Map.Entry<A,B>> mapsTo(Expression<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> Expression<D,T,B> andThenDependent(Expression<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> Expression<D,T,A> fix(Function<Expression<D,T,A>,Expression<D,T,A>> loop)
      Make a recursive expression.
    • unit

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

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

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

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

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

      public static <D, T, A> Expression<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 Expression<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 Expression<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 Expression<D,T,A> guard(Predicate<? super A> condition, Function<? super A,List<SimpleMessage<D>>> error)
    • process

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

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

      public static <D, T, A> Expression<D,T,A> leftAssoc(Expression.OperatorFactory<D,T,A> operator, Expression<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> Expression<D,T,A> leftAssoc(Expression<D,T,A> headOperand, Expression.OperatorFactory<D,T,A> operator, Expression<D,T,A> tailOperand, T... operatorTypes)
    • rightAssoc

      public static <D, T, A> Expression<D,T,A> rightAssoc(Expression.OperatorFactory<D,T,A> operator, Expression<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> Expression<D,T,A> nonAssoc(Expression.OperatorFactory<D,T,A> operator, Expression<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> Expression<D,T,A> withOtherTokenSource(LookaheadTokenMultiplexer<K,D,T,L> multi, K newKey)