public class GroovyRecognizer extends LLkParser
JSR-241 Groovy Recognizer. Run 'java Main [-showtree] directory-full-of-groovy-files' [The -showtree option pops up a Swing frame that shows the AST constructed from the parser.] Contributing authors: John Mitchell johnm
| Constructor and description |
|---|
protected GroovyRecognizer
(TokenBuffer tokenBuf, int k) |
GroovyRecognizer
(TokenBuffer tokenBuf) |
protected GroovyRecognizer
(TokenStream lexer, int k) |
GroovyRecognizer
(TokenStream lexer) |
GroovyRecognizer
(ParserSharedInputState state) |
| Type | Name and description |
|---|---|
void |
aCase() |
void |
addWarning(String warning, String solution) |
void |
additiveExpression(int lc_stmt) |
void |
andExpression(int lc_stmt) |
void |
annotation() |
void |
annotationArguments() |
void |
annotationBlock() |
void |
annotationDefinition(AST modifiers) |
void |
annotationField() |
void |
annotationIdent() |
void |
annotationMemberArrayValueInitializer() |
void |
annotationMemberValueInitializer() |
void |
annotationMemberValuePair() |
void |
annotationMemberValuePairs() |
void |
annotationsInternal() |
void |
annotationsOpt() |
void |
appendedBlock(AST callee)An appended block follows any expression. |
void |
argList() |
byte |
argument()A single argument in (...) or [...]. |
void |
argumentLabel()A label for an argument is of the form a:b, 'a':b, "a":b, (a):b, etc.. |
void |
argumentLabelStart()For lookahead only. |
void |
assignmentExpression(int lc_stmt) |
void |
assignmentLessExpression()In Java, "if", "while", and "for" statements can take random, non-braced statements as their bodies. |
void |
balancedBrackets()Fast lookahead across balanced brackets of all sorts. |
void |
balancedTokens()lookahead predicate for usage of generics in methods as parameter for the method. |
void |
blockBody(int prevToken) |
void |
branchStatement()In Groovy, return, break, continue, throw, and assert can be used in a parenthesized expression context. |
protected void |
buildTokenTypeASTClassMap() |
void |
builtInType() |
void |
builtInTypeArraySpec(boolean addImagNode) |
void |
builtInTypeSpec(boolean addImagNode) |
void |
caseSList() |
void |
casesGroup() |
void |
checkSuspiciousExpressionStatement(int prevToken)If two statements are separated by newline (not SEMI), the second had better not look like the latter half of an expression. |
void |
classBlock() |
void |
classDefinition(AST modifiers) |
void |
classField() |
void |
classOrInterfaceType(boolean addImagNode) |
void |
classTypeSpec(boolean addImagNode) |
Token |
cloneToken(Token t) |
void |
closableBlock()A sub-block of a block can be either open or closable. |
void |
closableBlockConstructorExpression()A list constructor is a argument list enclosed in square brackets, without labels. |
void |
closableBlockParam() |
void |
closableBlockParamsOpt(boolean addImplicit)Closure parameters are exactly like method parameters, except that they are not enclosed in parentheses, but rather are prepended to the front of a block, just after the brace. |
void |
closableBlockParamsStart() |
void |
closureList() |
void |
commandArgument() |
void |
commandArguments(AST head) |
void |
commandArgumentsGreedy(AST head) |
void |
compatibleBodyStatement() |
void |
compilationUnit() |
void |
compoundStatement()A list of zero or more formal parameters. |
void |
conditionalExpression(int lc_stmt) |
void |
constant() |
void |
constantNumber()Numeric constant. |
void |
constructorBody() |
void |
constructorDefinition(AST mods) |
void |
constructorStart()Used to look ahead for a constructor |
void |
controlExpressionList() |
AST |
create(int type, String txt, AST first)Create an AST node with the token type and text passed in, but with the same background information as another supplied Token (e.g. |
AST |
create(int type, String txt, Token first, Token last) |
AST |
create(int type, String txt, AST first, Token last) |
AST |
create(int type, String txt, AST first, AST last)Clones the token |
void |
declaration() |
void |
declarationStart() |
void |
declaratorBrackets(AST typ)After some type names, where zero or more empty bracket pairs are allowed. |
void |
dynamicMemberName() |
void |
enumBlock() |
void |
enumConstant() |
void |
enumConstantBlock() |
void |
enumConstantField() |
protected void |
enumConstantFieldInternal(AST mods, AST tp, AST t, Token first) |
void |
enumConstants()Comma-separated list of one or more enum constant definitions. |
void |
enumConstantsStart()Guard for enumConstants. |
void |
enumDefinition(AST modifiers) |
void |
equalityExpression(int lc_stmt) |
void |
exclusiveOrExpression(int lc_stmt) |
void |
explicitConstructorInvocation()Catch obvious constructor calls, but not the expr.super(...) calls |
void |
expression(int lc_stmt) |
void |
expressionStatement(int prevToken) |
void |
expressionStatementNoCheck() |
void |
finallyClause()A member name (x.y) or element name (x[y]) can serve as a command name, which may be followed by a list of arguments. |
void |
forCond() |
void |
forInClause() |
void |
forInit() |
void |
forIter() |
void |
forStatement() |
void |
genericMethod() |
void |
genericMethodStart() |
org.codehaus.groovy.antlr.parser.GroovyLexer |
getLexer() |
List |
getWarningList() |
void |
handler() |
void |
identifier() |
void |
identifierStar() |
void |
implementsClause() |
void |
implicitParameters()A block known to be a closure, but which omits its arguments, is given this placeholder. |
void |
importStatement() |
void |
inclusiveOrExpression(int lc_stmt) |
void |
indexPropertyArgs(AST indexee)If a dot is followed by a parenthesized or quoted expression, the member is computed dynamically, and the member selection is done only at runtime. |
void |
interfaceBlock() |
void |
interfaceDefinition(AST modifiers) |
void |
interfaceExtends() |
void |
interfaceField() |
void |
keywordPropertyNames() |
void |
listOfVariables(AST mods, AST t, Token first)Declaration of a variable. |
void |
listOrMapConstructorExpression() |
void |
logicalAndExpression(int lc_stmt) |
void |
logicalOrExpression(int lc_stmt) |
static GroovyRecognizer |
make(org.codehaus.groovy.antlr.parser.GroovyLexer lexer)This factory is the correct way to wire together a Groovy parser and lexer. |
static GroovyRecognizer |
make(InputStream in) |
static GroovyRecognizer |
make(Reader in) |
static GroovyRecognizer |
make(InputBuffer in) |
static GroovyRecognizer |
make(LexerSharedInputState in) |
void |
matchGenericTypeBracketsFailed(String problem, String solution) |
void |
methodCallArgs(AST callee)An expression may be followed by one or both of (...) and {...}. |
void |
modifier() |
void |
modifiers()A list of one or more modifier, annotation, or "def". |
void |
modifiersInternal() |
void |
modifiersOpt()Used only as a lookahead predicate for nested type declarations. |
void |
multicatch() |
void |
multicatch_types() |
void |
multipleAssignment(int lc_stmt) |
void |
multipleAssignmentDeclaration() |
void |
multipleAssignmentDeclarationStart() |
void |
multiplicativeExpression(int lc_stmt) |
void |
namePart()This is the grammar for what can follow a dot: x.a, x. |
void |
newArrayDeclarator() |
void |
newExpression()object instantiation. |
void |
nls()Zero or more insignificant newlines, all gobbled up and thrown away. |
void |
nlsWarn()Zero or more insignificant newlines, all gobbled up and thrown away, but a warning message is left for the user, if there was a newline. |
void |
openBlock()An open block is not allowed to have closure arguments. |
void |
openOrClosableBlock()A labeled statement, consisting of a vanilla identifier followed by a colon. |
void |
packageDefinition()A statement is an element of a block. |
void |
parameterDeclaration()A formal parameter for a method or closure. |
void |
parameterDeclarationList() |
void |
parameterModifiersOpt() |
void |
parenthesizedExpression() |
void |
pathChain(int lc_stmt, AST prefix) |
void |
pathElement(AST prefix) |
void |
pathElementStart() |
void |
pathExpression(int lc_stmt) |
void |
postfixExpression(int lc_stmt) |
void |
powerExpression(int lc_stmt) |
void |
powerExpressionNotPlusMinus(int lc_stmt) |
void |
primaryExpression() |
void |
qualifiedTypeName() |
void |
regexExpression(int lc_stmt) |
void |
relationalExpression(int lc_stmt) |
void |
requireFailed(String problem, String solution) |
void |
sep()A statement separator is either a semicolon or a significant newline. |
void |
setFilename(String f) |
void |
setSourceBuffer(SourceBuffer sourceBuffer) |
void |
shiftExpression(int lc_stmt) |
void |
singleDeclaration() |
void |
singleDeclarationNoInit()A declaration with one declarator and no initialization, like a parameterDeclaration. |
void |
singleVariable(AST mods, AST t)Used in cases where a declaration cannot have commas, or ends with the "in" operator instead of '='. |
void |
snippetUnit()A Groovy script or simple expression. |
void |
statement(int prevToken) |
void |
statementLabelPrefix()An expression statement can be any general expression. |
boolean |
strictContextExpression(boolean allowDeclaration)Things that can show up as expressions, but only in strict contexts like inside parentheses, argument lists, and list constructors. |
void |
stringConstructorExpression() |
void |
stringConstructorValuePart() |
void |
superClassClause() |
void |
suspiciousExpressionStatementStart()Lookahead for suspicious statement warnings and errors. |
void |
throwsClause()I've split out constructors separately; we could maybe integrate back into variableDefinitions later on if we maybe simplified 'def' to be a type declaration? |
void |
traceIn(String rname) |
void |
traceOut(String rname) |
void |
traitDefinition(AST modifiers) |
void |
tryBlock() |
void |
type() |
void |
typeArgument() |
void |
typeArgumentBounds() |
void |
typeArgumentSpec() |
void |
typeArguments() |
void |
typeArgumentsDiamond() |
protected void |
typeArgumentsOrParametersEnd() |
void |
typeDeclarationStart() |
protected void |
typeDefinitionInternal(AST mods) |
void |
typeNamePairs(AST mods, Token first) |
void |
typeParameter() |
void |
typeParameterBounds() |
void |
typeParameters() |
void |
typeSpec(boolean addImagNode) |
void |
unaryExpression(int lc_stmt) |
void |
unaryExpressionNotPlusMinus(int lc_stmt) |
void |
upperCaseIdent()An IDENT token whose spelling is required to start with an uppercase letter. |
void |
varInitializer()An assignment operator '=' followed by an expression. |
void |
variableDeclarator(AST mods, AST t, Token first) |
void |
variableDefinitions(AST mods, AST t) |
void |
variableName() |
void |
wildcardType() |
An appended block follows any expression. If the expression is not a method call, it is given an empty argument list.
A single argument in (...) or [...]. Corresponds to to a method or closure parameter. May be labeled. May be modified by the spread operator '*' ('*:' for keywords).
A label for an argument is of the form a:b, 'a':b, "a":b, (a):b, etc.. The labels in (a:b), ('a':b), and ("a":b) are in all ways equivalent, except that the quotes allow more spellings. Equivalent dynamically computed labels are (('a'):b) and ("${'a'}":b) but not ((a):b) or "$a":b, since the latter cases evaluate (a) as a normal identifier. Bottom line: If you want a truly variable label, use parens and say ((a):b).
For lookahead only. Fast approximate parse of an argumentLabel followed by a colon.
In Java, "if", "while", and "for" statements can take random, non-braced statements as their bodies. Support this practice, even though it isn't very Groovy.
Fast lookahead across balanced brackets of all sorts.
lookahead predicate for usage of generics in methods
as parameter for the method. Example:
static
In Groovy, return, break, continue, throw, and assert can be used in a parenthesized expression context. Example: println (x || (return)); println assert x, "won't print a false value!" If an optional expression is missing, its value is void (this coerces to null when a value is required).
If two statements are separated by newline (not SEMI), the second had better not look like the latter half of an expression. If it does, issue a warning.
Also, if the expression starts with a closure, it needs to have an explicit parameter list, in order to avoid the appearance of a compound statement. This is a hard error.
These rules are different from Java's "dumb expression" restriction. Unlike Java, Groovy blocks can end with arbitrary (even dumb) expressions, as a consequence of optional 'return' and 'continue' tokens.
To make the programmer's intention clear, a leading closure must have an explicit parameter list, and must not follow a previous statement separated only by newlines.
A sub-block of a block can be either open or closable. It is closable if and only if there are explicit closure arguments. Compare this to a block which is appended to a method call, which is given closure arguments, even if they are not explicit in the code.
A list constructor is a argument list enclosed in square brackets, without labels. Any argument can be decorated with a spread operator (*x), but not a label (a:x). Examples: [], [1], [1,2], [1,*l1,2], [*l1,*l2]. (The l1, l2 must be a sequence or null.)
A map constructor is an argument list enclosed in square brackets, with labels everywhere, except on spread arguments, which stand for whole maps spliced in. A colon alone between the brackets also forces the expression to be an empty map constructor. Examples: [:], [a:1], [a:1,b:2], [a:1,*:m1,b:2], [*:m1,*:m2] (The m1, m2 must be a map or null.) Values associated with identical keys overwrite from left to right: [a:1,a:2] === [a:2]
Some malformed constructor expressions are not detected in the parser, but in a post-pass. Bad examples: [1,b:2], [a:1,2], [:1]. (Note that method call arguments, by contrast, can be a mix of keyworded and non-keyworded arguments.)
Closure parameters are exactly like method parameters, except that they are not enclosed in parentheses, but rather are prepended to the front of a block, just after the brace. They are separated from the closure body by a CLOSABLE_BLOCK_OP token '->'.
A list of zero or more formal parameters. If a parameter is variable length (e.g. String... myArg) it should be to the right of any other parameters of the same kind. General form: (req, ..., opt, ..., [rest], key, ..., [restKeys], [block] This must be sorted out after parsing, since the various declaration forms are impossible to tell apart without backtracking.
Numeric constant.
Used to look ahead for a constructor
Create an AST node with the token type and text passed in, but with the same background information as another supplied Token (e.g. line numbers). To be used in place of antlr tree construction syntax, i.e. #[TOKEN,"text"] becomes create(TOKEN,"text",anotherToken) todo - change antlr.ASTFactory to do this instead...
After some type names, where zero or more empty bracket pairs are allowed. We use ARRAY_DECLARATOR to represent this. TODO: Is there some more Groovy way to view this in terms of the indexed property syntax?
Comma-separated list of one or more enum constant definitions.
Guard for enumConstants.
Catch obvious constructor calls, but not the expr.super(...) calls
A member name (x.y) or element name (x[y]) can serve as a command name, which may be followed by a list of arguments. Unlike parenthesized arguments, these must be plain expressions, without labels or spread operators.
A block known to be a closure, but which omits its arguments, is given this placeholder. A subsequent pass is responsible for deciding if there is an implicit 'it' parameter, or if the parameter list should be empty.
If a dot is followed by a parenthesized or quoted expression, the member is computed dynamically, and the member selection is done only at runtime. This forces a statically unchecked member access.
Declaration of a variable. This can be a class/instance variable, or a local variable in a method It can also include possible initialization.
This factory is the correct way to wire together a Groovy parser and lexer.
An expression may be followed by one or both of (...) and {...}. Note: If either is (...) or {...} present, it is a method call. The {...} is appended to the argument list, and matches a formal of type Closure. If there is no method member, a property (or field) is used instead, and must itself be callable.
If the methodCallArgs are absent, it is a property reference. If there is no property, it is treated as a field reference, but never a method reference.
Arguments in the (...) can be labeled, and the appended block can be labeled also. If there is a mix of unlabeled and labeled arguments, all the labeled arguments must follow the unlabeled arguments, except that the closure (labeled or not) is always a separate final argument. Labeled arguments are collected up and passed as a single argument to a formal of type Map.
Therefore, f(x,y, a:p, b:q) {s} is equivalent in all ways to f(x,y, [a:p,b:q], {s}). Spread arguments of sequence type count as unlabeled arguments, while spread arguments of map type count as labeled arguments. (This distinction must sometimes be checked dynamically.) A plain unlabeled argument is allowed to match a trailing Map or Closure argument: f(x, a:p) {s} === f(*[ x, [a:p], {s} ])
A list of one or more modifier, annotation, or "def".
Used only as a lookahead predicate for nested type declarations.
This is the grammar for what can follow a dot: x.a, x.@a, x.&a, x.'a', etc.
Note: typeArguments is handled by the caller of namePart.
object instantiation. Trees are built as illustrated by the following input/tree pairs: new T() new | T -- ELIST | arg1 -- arg2 -- .. -- argn new int[] new | int -- ARRAY_DECLARATOR new int[] {1,2} new | int -- ARRAY_DECLARATOR -- ARRAY_INIT | EXPR -- EXPR | | 1 2 new int[3] new | int -- ARRAY_DECLARATOR | EXPR | 3 new int[1][2] new | int -- ARRAY_DECLARATOR | ARRAY_DECLARATOR -- EXPR | | EXPR 1 | 2
Zero or more insignificant newlines, all gobbled up and thrown away.
Zero or more insignificant newlines, all gobbled up and thrown away, but a warning message is left for the user, if there was a newline.
An open block is not allowed to have closure arguments.
A labeled statement, consisting of a vanilla identifier followed by a colon.
A statement is an element of a block. Typical statements are declarations (which are scoped to the block) and expressions.
A formal parameter for a method or closure.
A statement separator is either a semicolon or a significant newline. Any number of additional (insignificant) newlines may accompany it.
A declaration with one declarator and no initialization, like a parameterDeclaration.
Used to parse loops like for (int x in y) (up to the in keyword).
Used in cases where a declaration cannot have commas, or ends with the "in" operator instead of '='.
A Groovy script or simple expression. Can be anything legal inside {...}.
An expression statement can be any general expression.
An expression statement can also be a command, which is a simple method call in which the outermost parentheses are omitted.
Certain "suspicious" looking forms are flagged for the user to disambiguate.
Things that can show up as expressions, but only in strict contexts like inside parentheses, argument lists, and list constructors.
Lookahead for suspicious statement warnings and errors.
I've split out constructors separately; we could maybe integrate back into variableDefinitions later on if we maybe simplified 'def' to be a type declaration?
An IDENT token whose spelling is required to start with an uppercase letter. In the case of a simple statement {UpperID name} the identifier is taken to be a type name, not a command name.
An assignment operator '=' followed by an expression. (Never empty.)
Copyright © 2003-2014 The Codehaus. All rights reserved.