Skip to content

Commit

Permalink
fix: [deps] remove unused java code in antlr & it will cause bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 4, 2020
1 parent 8944882 commit 9a8ab9a
Show file tree
Hide file tree
Showing 15 changed files with 2,662 additions and 3,110 deletions.
Empty file added _fixtures/deps/build.gradle
Empty file.
1 change: 1 addition & 0 deletions core/context/deps/dep_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package deps
1 change: 1 addition & 0 deletions core/context/deps/dep_app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package deps
Empty file.
77 changes: 40 additions & 37 deletions languages/g4/GroovyLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
*/
lexer grammar GroovyLexer;

options {
superClass = AbstractLexer;
}
//options {
// superClass = AbstractLexer;
//}
//
//@header {
// import static org.apache.groovy.parser.antlr4.SemanticPredicates.*;
Expand Down Expand Up @@ -214,7 +214,8 @@ StringLiteral
: GStringQuotationMark DqStringCharacter* GStringQuotationMark
| SqStringQuotationMark SqStringCharacter* SqStringQuotationMark

| Slash { this.isRegexAllowed() && _input.LA(1) != '*' }?
| Slash
// | Slash { this.isRegexAllowed() && _input.LA(1) != '*' }?
SlashyStringCharacter+ Slash

| TdqStringQuotationMark TdqStringCharacter* TdqStringQuotationMark
Expand All @@ -230,10 +231,10 @@ TdqGStringBegin
: TdqStringQuotationMark TdqStringCharacter* Dollar -> type(GStringBegin), pushMode(TDQ_GSTRING_MODE), pushMode(GSTRING_TYPE_SELECTOR_MODE)
;
SlashyGStringBegin
: Slash { this.isRegexAllowed() && _input.LA(1) != '*' }? SlashyStringCharacter* Dollar { isFollowedByJavaLetterInGString(_input) }? -> type(GStringBegin), pushMode(SLASHY_GSTRING_MODE), pushMode(GSTRING_TYPE_SELECTOR_MODE)
: Slash SlashyStringCharacter* Dollar -> type(GStringBegin), pushMode(SLASHY_GSTRING_MODE), pushMode(GSTRING_TYPE_SELECTOR_MODE)
;
DollarSlashyGStringBegin
: DollarSlashyGStringQuotationMarkBegin DollarSlashyStringCharacter* Dollar { isFollowedByJavaLetterInGString(_input) }? -> type(GStringBegin), pushMode(DOLLAR_SLASHY_GSTRING_MODE), pushMode(GSTRING_TYPE_SELECTOR_MODE)
: DollarSlashyGStringQuotationMarkBegin DollarSlashyStringCharacter* Dollar -> type(GStringBegin), pushMode(DOLLAR_SLASHY_GSTRING_MODE), pushMode(GSTRING_TYPE_SELECTOR_MODE)
;

mode DQ_GSTRING_MODE;
Expand Down Expand Up @@ -263,7 +264,7 @@ SlashyGStringEnd
: Dollar? Slash -> type(GStringEnd), popMode
;
SlashyGStringPart
: Dollar { isFollowedByJavaLetterInGString(_input) }? -> type(GStringPart), pushMode(GSTRING_TYPE_SELECTOR_MODE)
: Dollar -> type(GStringPart), pushMode(GSTRING_TYPE_SELECTOR_MODE)
;
SlashyGStringCharacter
: SlashyStringCharacter -> more
Expand All @@ -274,15 +275,15 @@ DollarSlashyGStringEnd
: DollarSlashyGStringQuotationMarkEnd -> type(GStringEnd), popMode
;
DollarSlashyGStringPart
: Dollar { isFollowedByJavaLetterInGString(_input) }? -> type(GStringPart), pushMode(GSTRING_TYPE_SELECTOR_MODE)
: Dollar -> type(GStringPart), pushMode(GSTRING_TYPE_SELECTOR_MODE)
;
DollarSlashyGStringCharacter
: DollarSlashyStringCharacter -> more
;

mode GSTRING_TYPE_SELECTOR_MODE;
GStringLBrace
: '{' { this.enterParen(); } -> type(LBRACE), popMode, pushMode(DEFAULT_MODE)
: '{' -> type(LBRACE), popMode, pushMode(DEFAULT_MODE)
;
GStringIdentifier
: IdentifierInGString -> type(Identifier), popMode, pushMode(GSTRING_PATH_MODE)
Expand All @@ -294,14 +295,7 @@ GStringPathPart
: Dot IdentifierInGString
;
RollBackOne
: . {
// a trick to handle GStrings followed by EOF properly
if (EOF == _input.LA(1) && ('"' == _input.LA(-1) || '/' == _input.LA(-1))) {
setType(GStringEnd);
} else {
setChannel(HIDDEN);
}
} -> popMode
: . -> popMode
;


Expand All @@ -323,29 +317,29 @@ SqStringCharacter
// character in the triple double quotation string. e.g. """a"""
fragment TdqStringCharacter
: ~["\\$]
| GStringQuotationMark { _input.LA(1) != '"' || _input.LA(2) != '"' || _input.LA(3) == '"' && (_input.LA(4) != '"' || _input.LA(5) != '"') }?
| GStringQuotationMark
| EscapeSequence
;

// character in the triple single quotation string. e.g. '''a'''
fragment TsqStringCharacter
: ~['\\]
| SqStringQuotationMark { _input.LA(1) != '\'' || _input.LA(2) != '\'' || _input.LA(3) == '\'' && (_input.LA(4) != '\'' || _input.LA(5) != '\'') }?
| SqStringQuotationMark
| EscapeSequence
;
// character in the slashy string. e.g. /a/
fragment SlashyStringCharacter
: SlashEscape
| Dollar { !isFollowedByJavaLetterInGString(_input) }?
| Dollar
| ~[/$\u0000]
;
// character in the collar slashy string. e.g. $/a/$
fragment DollarSlashyStringCharacter
: SlashEscape | DollarSlashEscape | DollarDollarEscape
| Slash { _input.LA(1) != '$' }?
| Dollar { !isFollowedByJavaLetterInGString(_input) }?
| Slash
| Dollar
| ~[/$\u0000]
;
Expand Down Expand Up @@ -456,10 +450,12 @@ IntegerLiteral
| HexIntegerLiteral
| OctalIntegerLiteral
| BinaryIntegerLiteral
) (Underscore { require(false, "Number ending with underscores is invalid", -1, true); })?
) (Underscore)?
// { require(false, "Number ending with underscores is invalid", -1, true); }
// !!! Error Alternative !!!
| Zero ([0-9] { invalidDigitCount++; })+ { require(false, "Invalid octal number", -(invalidDigitCount + 1), true); } IntegerTypeSuffix?
| Zero ([0-9])+ IntegerTypeSuffix?
// | Zero ([0-9] { invalidDigitCount++; })+ { require(false, "Invalid octal number", -(invalidDigitCount + 1), true); } IntegerTypeSuffix?
;
fragment
Expand Down Expand Up @@ -598,7 +594,7 @@ BinaryDigitOrUnderscore
FloatingPointLiteral
: ( DecimalFloatingPointLiteral
| HexadecimalFloatingPointLiteral
) (Underscore { require(false, "Number ending with underscores is invalid", -1, true); })?
) (Underscore)?
;
fragment
Expand Down Expand Up @@ -793,18 +789,25 @@ NOT_IDENTICAL : '!==';
ARROW : '->';

// !internalPromise will be parsed as !in ternalPromise, so semantic predicates are necessary
NOT_INSTANCEOF : '!instanceof' { isFollowedBy(_input, ' ', '\t', '\r', '\n') }?;
NOT_IN : '!in' { isFollowedBy(_input, ' ', '\t', '\r', '\n', '[', '(', '{') }?;
NOT_INSTANCEOF : '!instanceof' ;
NOT_IN : '!in' ;


// §3.11 Separators

LPAREN : '(' { this.enterParen(); } -> pushMode(DEFAULT_MODE);
RPAREN : ')' { this.exitParen(); } -> popMode;
LBRACE : '{' { this.enterParen(); } -> pushMode(DEFAULT_MODE);
RBRACE : '}' { this.exitParen(); } -> popMode;
LBRACK : '[' { this.enterParen(); } -> pushMode(DEFAULT_MODE);
RBRACK : ']' { this.exitParen(); } -> popMode;
LPAREN : '(' -> pushMode(DEFAULT_MODE);
RPAREN : ')' -> popMode;
LBRACE : '{' -> pushMode(DEFAULT_MODE);
RBRACE : '}' -> popMode;
LBRACK : '[' -> pushMode(DEFAULT_MODE);
RBRACK : ']' -> popMode;
//
//LPAREN : '(' { this.enterParen(); } -> pushMode(DEFAULT_MODE);
//RPAREN : ')' { this.exitParen(); } -> popMode;
//LBRACE : '{' { this.enterParen(); } -> pushMode(DEFAULT_MODE);
//RBRACE : '}' { this.exitParen(); } -> popMode;
//LBRACK : '[' { this.enterParen(); } -> pushMode(DEFAULT_MODE);
//RBRACK : ']' { this.exitParen(); } -> popMode;

SEMI : ';';
COMMA : ',';
Expand Down Expand Up @@ -925,23 +928,23 @@ WS : ([ \t\u000C]+ | LineEscape+) -> skip


// Inside (...) and [...] but not {...}, ignore newlines.
NL : '\r'? '\n' { this.ignoreTokenInsideParens(); }
NL : '\r'? '\n'
;

// Multiple-line comments(including groovydoc comments)
ML_COMMENT
: '/*' .*? '*/' { this.ignoreMultiLineCommentConditionally(); } -> type(NL)
: '/*' .*? '*/' -> type(NL)
;

// Single-line comments
SL_COMMENT
: '//' ~[\r\n\uFFFF]* { this.ignoreTokenInsideParens(); } -> type(NL)
: '//' ~[\r\n\uFFFF]* -> type(NL)
;

// Script-header comments.
// The very first characters of the file may be "#!". If so, ignore the first line.
SH_COMMENT
: '#!' { require(0 == this.tokenIndex, "Shebang comment should appear at the first line", -2, true); } ~[\r\n\uFFFF]* -> skip
: '#!' ~[\r\n\uFFFF]* -> skip
;

// Unexpected characters will be handled by groovy parser later.
Expand Down
6 changes: 6 additions & 0 deletions languages/g4/GroovyLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ UNEXPECTED_CHAR=129
'->'=75
'!instanceof'=76
'!in'=77
'('=78
')'=79
'{'=80
'}'=81
'['=82
']'=83
';'=84
','=85
'='=87
Expand Down
26 changes: 11 additions & 15 deletions languages/g4/GroovyParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ parser grammar GroovyParser;

options {
tokenVocab = GroovyLexer;
contextSuperClass = GroovyParserRuleContext;
superClass = AbstractParser;
// contextSuperClass = GroovyParserRuleContext;
// superClass = AbstractParser;
}
//
//@header {
Expand Down Expand Up @@ -459,8 +459,8 @@ literal
: IntegerLiteral #integerLiteralAlt
| FloatingPointLiteral #floatingPointLiteralAlt
| stringLiteral #stringLiteralAlt
| BooleanLiteral #booleanLiteralAlt
| NullLiteral #nullLiteralAlt
| BooleanLiteral #boolLiteralAlt
| NullLiteral #nilLiteralAlt
;

// GSTRING
Expand Down Expand Up @@ -582,7 +582,7 @@ blockStatement
;

localVariableDeclaration
: { !SemanticPredicates.isInvalidLocalVariableDeclaration(_input) }?
: // { !SemanticPredicates.isInvalidLocalVariableDeclaration(_input) }?
variableDeclaration[0]
;

Expand Down Expand Up @@ -678,8 +678,7 @@ statement
| localVariableDeclaration #localVariableDeclarationStmtAlt

// validate the method in the AstBuilder#visitMethodDeclaration, e.g. method without method body is not allowed
| { !SemanticPredicates.isInvalidMethodDeclaration(_input) }?
methodDeclaration[3, 9] #methodDeclarationStmtAlt
| methodDeclaration[3, 9] #methodDeclarationStmtAlt

| statementExpression #expressionStmtAlt

Expand Down Expand Up @@ -761,14 +760,12 @@ expressionInPar
: LPAREN enhancedStatementExpression rparen
;

expressionList[boolean canSpread]
expressionList[bool canSpread]
: expressionListElement[$canSpread] (COMMA expressionListElement[$canSpread])*
;

expressionListElement[boolean canSpread]
: ( MUL { require($canSpread, "spread operator is not allowed here", -1); }
|
) expression
expressionListElement[bool canSpread]
: (MUL | ) expression
;

enhancedStatementExpression
Expand Down Expand Up @@ -902,7 +899,6 @@ enhancedExpression
commandExpression
: expression
(
{ !SemanticPredicates.isFollowingArgumentsOrClosure($expression.ctx) }?
argumentList
|
/* if pathExpression is a method call, no need to have any more arguments */
Expand Down Expand Up @@ -1157,7 +1153,7 @@ identifier
| VAR
|
// if 'static' followed by DOT, we can treat them as identifiers, e.g. static.unused = { -> }
{ DOT == _input.LT(2).getType() }?
// { DOT == _input.LT(2).getType() }?
STATIC
| IN
// | DEF
Expand Down Expand Up @@ -1231,7 +1227,7 @@ rparen
: RPAREN
|
// !!!Error Alternative, impact the performance of parsing
{ require(false, "Missing ')'"); }
// { require(false, "Missing ')'"); }
;

nls
Expand Down
14 changes: 7 additions & 7 deletions languages/groovy/GroovyLexer.interp

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions languages/groovy/GroovyLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ UNEXPECTED_CHAR=129
'->'=75
'!instanceof'=76
'!in'=77
'('=78
')'=79
'{'=80
'}'=81
'['=82
']'=83
';'=84
','=85
'='=87
Expand Down
14 changes: 7 additions & 7 deletions languages/groovy/GroovyParser.interp

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions languages/groovy/GroovyParser.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ UNEXPECTED_CHAR=129
'->'=75
'!instanceof'=76
'!in'=77
'('=78
')'=79
'{'=80
'}'=81
'['=82
']'=83
';'=84
','=85
'='=87
Expand Down
Loading

0 comments on commit 9a8ab9a

Please sign in to comment.