public class SemanticPredicates
extends Object
Semantic predicates for the lexer and parser.
Lexer helpers on this class run on the tokenisation hot path (GString
$, slashy strings, newline-as-separator). They use direct character
tests, not regular expressions. Parser helpers such as
isIdentifierAssign(TokenStream) are O(1) bitset lookups so
AdaptivePredict can skip exploring assignment as an annotation
element value (GROOVY-12398).
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static boolean |
isFollowedBy(CharStream cs, char chars)Check whether the next character is one of the specified characters. |
|
public static boolean |
isFollowedByJavaLetterInGString(CharStream cs)Check whether the next character is a valid Java identifier part or a left curly brace (for GString expressions). |
|
public static boolean |
isFollowedByWhiteSpaces(CharStream cs)Check whether the next characters are only white spaces until the end of line or end of file. |
|
public static boolean |
isFollowingArgumentsOrClosure(GroovyParser.ExpressionContext context)Check whether following a method name of command expression. |
|
public static boolean |
isIdentifierAssign(TokenStream ts)true when the upcoming tokens are name '=' ..., i.e. a named
annotation element-value pair rather than a single element value. |
|
public static boolean |
isInvalidLocalVariableDeclaration(TokenStream ts)Distinguish between local variable declaration and method call, e.g. |
|
public static boolean |
isInvalidMethodDeclaration(TokenStream ts)Distinguish between method declaration and method call/constructor declaration |
Check whether the next character is one of the specified characters.
Check whether the next character is a valid Java identifier part or a left curly brace (for GString expressions).
Check whether the next characters are only white spaces until the end of line or end of file.
Matches Java regex \s minus the newlines the loop already stops at: space, tab, VT, FF.
Check whether following a method name of command expression. Method name should not end with "2: arguments" and "3: closure"
context - the preceding expression true when the upcoming tokens are name '=' ..., i.e. a named
annotation element-value pair rather than a single element value. Inside
annotation parentheses newlines are already hidden, so LT(2) is the
token after the name.
Distinguish between local variable declaration and method call, e.g. `a b`
Distinguish between method declaration and method call/constructor declaration