Class ConditionalParse<T>

java.lang.Object
nz.org.riskscape.dsl.ConditionalParse<T>
Type Parameters:
T - the type of thing returned by a parsing operation

public class ConditionalParse<T> extends Object

Used to represent a parsing operation that's conditional on a sequence of token possibilities.

This type is used by Lexer.tryThese(ConditionalParse...) to help parses model a list of precedence ordered lookahead rules that give the basis of a grammar.

  • Constructor Details

  • Method Details

    • parseIf

      public static <T> ConditionalParse<T> parseIf(String name, List<Set<? extends TokenType>> nextTokens, Supplier<T> callback)

      Construct a ConditionalParse that matches a sequence of possible tokens.

      Given the list of sets {S1, S2, S3}, then the returned ConditionalParse object would apply to a sequence of tokens where the next three tokens types are first in S1, second in S2 and then thirdly from S3. If this list was [{a, b}, {c}, {d, e}], then it would apply to [a, c, d], [b, c, d], [a, c, e] and [b, c, e].

      Parameters:
      name - debug identifier for the parsing step
      nextTokens - the sequence of possible token types to match.
      callback - a function to call that returns the results of parsing - it's assumed that the lexer is provided by the function's enclosing scope.
    • parseIfOneOf

      public static <T> ConditionalParse<T> parseIfOneOf(String name, Set<? extends TokenType> nextTokens, Supplier<T> callback)

      Convenience version of parseIf(String, List, Supplier) with a singleton list.

    • parseIfIs

      public static <T> ConditionalParse<T> parseIfIs(String name, TokenType nextToken, Supplier<T> callback)

      Convenience version of parseIf where the next token has to be exactly the given token.

    • parseIfIs

      public static <T> ConditionalParse<T> parseIfIs(String name, List<? extends TokenType> nextTokens, Supplier<T> callback)

      Convenience version of parseIf where the next sequence of tokens needs to match the sequence of token types in nextTokens

    • getName

      public String getName()

      Debugging name for this part of the grammar

    • getNextTokens

      public List<Set<? extends TokenType>> getNextTokens()

      The sequence of tokens to be matched

    • getParse

      public Supplier<T> getParse()

      A callback that gives the results of parsing.

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object