Package org.apache.groovy.parser.antlr4
Class SemanticPredicates
java.lang.Object
org.apache.groovy.parser.antlr4.SemanticPredicates
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).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisFollowedBy(org.antlr.v4.runtime.CharStream cs, char... chars) Check whether the next character is one of the specified characters.static booleanisFollowedByJavaLetterInGString(org.antlr.v4.runtime.CharStream cs) Check whether the next character is a valid Java identifier part or a left curly brace (for GString expressions).static booleanisFollowedByWhiteSpaces(org.antlr.v4.runtime.CharStream cs) Check whether the next characters are only white spaces until the end of line or end of file.static booleanCheck whether following a method name of command expression.static booleanisIdentifierAssign(org.antlr.v4.runtime.TokenStream ts) truewhen the upcoming tokens arename '=' ..., i.e.static booleanisInvalidLocalVariableDeclaration(org.antlr.v4.runtime.TokenStream ts) Distinguish between local variable declaration and method call, e.g.static booleanisInvalidMethodDeclaration(org.antlr.v4.runtime.TokenStream ts) Distinguish between method declaration and method call/constructor declaration
-
Constructor Details
-
SemanticPredicates
public SemanticPredicates()
-
-
Method Details
-
isFollowedByWhiteSpaces
public static boolean isFollowedByWhiteSpaces(org.antlr.v4.runtime.CharStream cs) Check whether the next characters are only white spaces until the end of line or end of file. Matches Java regex\sminus the newlines the loop already stops at: space, tab, VT, FF. -
isFollowedBy
public static boolean isFollowedBy(org.antlr.v4.runtime.CharStream cs, char... chars) Check whether the next character is one of the specified characters. -
isFollowedByJavaLetterInGString
public static boolean isFollowedByJavaLetterInGString(org.antlr.v4.runtime.CharStream cs) Check whether the next character is a valid Java identifier part or a left curly brace (for GString expressions). -
isIdentifierAssign
public static boolean isIdentifierAssign(org.antlr.v4.runtime.TokenStream ts) truewhen the upcoming tokens arename '=' ..., i.e. a named annotation element-value pair rather than a single element value. Inside annotation parentheses newlines are already hidden, soLT(2)is the token after the name. -
isFollowingArgumentsOrClosure
Check whether following a method name of command expression. Method name should not end with "2: arguments" and "3: closure"- Parameters:
context- the preceding expression
-
isInvalidMethodDeclaration
public static boolean isInvalidMethodDeclaration(org.antlr.v4.runtime.TokenStream ts) Distinguish between method declaration and method call/constructor declaration -
isInvalidLocalVariableDeclaration
public static boolean isInvalidLocalVariableDeclaration(org.antlr.v4.runtime.TokenStream ts) Distinguish between local variable declaration and method call, e.g. `a b`
-