Class ConditionalParse<T>
- Type Parameters:
T- the type of thing returned by a parsing operation
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleangetName()Debugging name for this part of the grammarThe sequence of tokens to be matchedgetParse()A callback that gives the results of parsing.inthashCode()static <T> ConditionalParse<T>Construct aConditionalParsethat matches a sequence of possible tokens.static <T> ConditionalParse<T>Convenience version of parseIf where the next sequence of tokens needs to match the sequence of token types innextTokensstatic <T> ConditionalParse<T>Convenience version of parseIf where the next token has to be exactly the given token.static <T> ConditionalParse<T>parseIfOneOf(String name, Set<? extends TokenType> nextTokens, Supplier<T> callback) Convenience version ofparseIf(String, List, Supplier)with a singleton list.toString()
-
Constructor Details
-
ConditionalParse
Creates a new
ConditionalParseinstance.- Parameters:
name- Debugging name for this part of the grammarnextTokens- The sequence of tokens to be matchedparse- A callback that gives the results of parsing.
-
-
Method Details
-
parseIf
public static <T> ConditionalParse<T> parseIf(String name, List<Set<? extends TokenType>> nextTokens, Supplier<T> callback) Construct a
ConditionalParsethat matches a sequence of possible tokens.Given the list of sets
{S1, S2, S3}, then the returnedConditionalParseobject would apply to a sequence of tokens where the next three tokens types are first inS1, second inS2and then thirdly fromS3. 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 stepnextTokens- 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
Debugging name for this part of the grammar
-
getNextTokens
The sequence of tokens to be matched
-
getParse
A callback that gives the results of parsing.
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-