-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
[JENKINS-68652] Update ANTLR2 to ANTLR4 #7293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c6b7b0e
Start of transition to ANTLR4
slide b9b5d91
fix: Update ANTLR2 to ANTLR4 to fix JENKINS-68652
slide eb254d8
mvn spotless:apply
basil 34a8677
Ignore SpotBugs warnings in generated code
basil 2c8a07e
Restore Java 8 error message support
basil 70ea6bd
Merge branch 'master' into antlr4_update
basil dbb8236
Add files/dirs for ANTLR4
slide 0ff8df7
Reformat .g4 files add ANTLRException for backward compat.
slide 470a683
Merge branch 'master' into antlr4_update
basil 9b6d09d
fix typo
basil ff1f8a6
full set of exception constructors
basil bed2789
Remove unnecessary throws from tests
basil c63d928
Deprecate compatibility layer
basil bd3583e
Merge remote-tracking branch 'origin/master' into antlr4_update
basil ffc1efd
Implement feedback suggestions
slide 2ec365b
Merge branch 'master' into antlr4_update
basil d3e4abd
Clean up error handling
basil 8f52de2
fixups
basil f4b0ec8
No need for BailErrorStrategy and it is inconsistent with label expre…
basil 6c533d5
fixups
basil c96cf97
we like stacks
basil 0a434b4
Extract version into property for easy updating
basil 9e394c4
no need for executions in plugin management section
basil 2011696
Remove unnecessary JARs from WAR
basil 84d8e35
stack traces are wonderful
basil f19185d
Update .gitignore
basil e4f50b3
fixups
basil a90503e
Merge branch 'master' into antlr4_update
basil 977de92
fixup
basil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,3 +59,7 @@ war/node_modules/ | |
| war/yarn-error.log | ||
| .java-version | ||
| .checkstyle | ||
|
|
||
| # ANTLR generated files | ||
| *.tokens | ||
| core/gen/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
core/src/main/antlr4/hudson/model/labels/LabelExpressionLexer.g4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| lexer grammar LabelExpressionLexer; | ||
|
|
||
| AND | ||
| : '&&' | ||
| ; | ||
|
|
||
| OR | ||
| : '||' | ||
| ; | ||
|
|
||
| NOT | ||
| : '!' | ||
| ; | ||
|
|
||
| IMPLIES | ||
| : '->' | ||
| ; | ||
|
|
||
| IFF | ||
| : '<->' | ||
| ; | ||
|
|
||
| LPAREN | ||
| : '(' | ||
| ; | ||
|
|
||
| RPAREN | ||
| : ')' | ||
| ; | ||
|
|
||
| fragment IDENTIFIER_PART | ||
| : ~ ('&' | '|' | '!' | '<' | '>' | '(' | ')' | ' ' | '\t' | '"' | '\'' | '-') | ||
| ; | ||
|
|
||
| ATOM | ||
| /* | ||
| the real check of valid identifier happens in LabelAtom.get() | ||
|
|
||
| https://www.antlr2.org/doc/lexer.html#usingexplicit | ||
| If we are seeing currently a '-', we check that the next char is not a '>' which will be a IMPLIES. | ||
| Otherwise the ATOM and the IMPLIES will collide and expr like a->b will just be parsed as ATOM (without spaces) | ||
| */ | ||
|
|
||
| : ( | ||
| { _input.LA(2) != '>' }? '-' | IDENTIFIER_PART)+ | ||
| ; | ||
|
|
||
| WS | ||
| : (' ' | '\t')+ -> skip | ||
| ; | ||
|
|
||
| STRINGLITERAL | ||
| : '"' ('\\' ('b' | 't' | 'n' | 'f' | 'r' | '"' | '\'' | '\\') /* escape */ | ||
|
|
||
| | ~ ('\\' | '"' | '\r' | '\n'))* '"' | ||
| ; | ||
|
|
56 changes: 56 additions & 0 deletions
56
core/src/main/antlr4/hudson/model/labels/LabelExpressionParser.g4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| parser grammar LabelExpressionParser; | ||
|
|
||
| @ header | ||
| { | ||
| import hudson.model.Label; | ||
| } | ||
|
|
||
| options { tokenVocab = LabelExpressionLexer; } | ||
| // order of precedence is as per http://en.wikipedia.org/wiki/Logical_connective#Order_of_precedence | ||
|
|
||
| expr returns[Label l] | ||
| : term1 | ||
| { $l=$term1.ctx.l; } EOF | ||
| ; | ||
|
|
||
| term1 returns[Label l] locals[Label r] | ||
| : term2 | ||
| { $l=$term2.ctx.l; } (IFF term2 | ||
| { $r=$term2.ctx.l; $l=$l.iff($r); })* | ||
| ; | ||
| // (a->b)->c != a->(b->c) (for example in case of a=F,b=T,c=F) so don't allow chaining | ||
|
|
||
| term2 returns[Label l] locals[Label r] | ||
| : term3 | ||
| { $l=$term3.ctx.l; } (IMPLIES term3 | ||
| { $r=$term3.ctx.l; $l=$l.implies($r); })? | ||
| ; | ||
|
|
||
| term3 returns[Label l] locals[Label r] | ||
| : term4 | ||
| { $l=$term4.ctx.l; } (OR term4 | ||
| { $r=$term4.ctx.l; $l=$l.or($r); })* | ||
| ; | ||
|
|
||
| term4 returns[Label l] locals[Label r] | ||
| : term5 | ||
| { $l=$term5.ctx.l; } (AND term5 | ||
| { $r=$term5.ctx.l; $l=$l.and($r); })* | ||
| ; | ||
|
|
||
| term5 returns[Label l] | ||
| : term6 | ||
| { $l=$term6.ctx.l; } | ||
| | NOT term6 | ||
| { $l=$term6.ctx.l; $l=$l.not(); } | ||
| ; | ||
|
|
||
| term6 returns[Label l] | ||
| : LPAREN term1 RPAREN | ||
| { $l=$term1.ctx.l ; $l=$l.paren(); } | ||
| | ATOM | ||
| { $l=LabelAtom.get($ATOM.getText()); } | ||
| | STRINGLITERAL | ||
| { $l=LabelAtom.get(hudson.util.QuotedStringTokenizer.unquote($STRINGLITERAL.getText())); } | ||
| ; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| lexer grammar CrontabLexer; | ||
|
|
||
| TOKEN | ||
| : ('0' .. '9')+ | ||
| ; | ||
|
|
||
| WS | ||
| : (' ' | '\t')+ | ||
| ; | ||
|
|
||
| MINUS | ||
| : '-' | ||
| ; | ||
|
|
||
| STAR | ||
| : '*' | ||
| ; | ||
|
|
||
| DIV | ||
| : '/' | ||
| ; | ||
|
|
||
| OR | ||
| : ',' | ||
| ; | ||
|
|
||
| AT | ||
| : '@' | ||
| ; | ||
|
|
||
| H | ||
| : 'H' | ||
| ; | ||
|
|
||
| LPAREN | ||
| : '(' | ||
| ; | ||
|
|
||
| RPAREN | ||
| : ')' | ||
| ; | ||
|
|
||
| YEARLY | ||
| : 'yearly' | ||
| ; | ||
|
|
||
| ANNUALLY | ||
| : 'annually' | ||
| ; | ||
|
|
||
| MONTHLY | ||
| : 'monthly' | ||
| ; | ||
|
|
||
| WEEKLY | ||
| : 'weekly' | ||
| ; | ||
|
|
||
| DAILY | ||
| : 'daily' | ||
| ; | ||
|
|
||
| MIDNIGHT | ||
| : 'midnight' | ||
| ; | ||
|
|
||
| HOURLY | ||
| : 'hourly' | ||
| ; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| parser grammar CrontabParser; | ||
|
|
||
|
|
||
| options { tokenVocab = CrontabLexer; superClass = BaseParser; } | ||
| startRule[CronTab table] | ||
| : expr[0] | ||
| { $table.bits[0]=$expr.ctx.bits; } WS expr[1] | ||
| { $table.bits[1]=$expr.ctx.bits; } WS expr[2] | ||
| { $table.bits[2]=$expr.ctx.bits; } WS expr[3] | ||
| { $table.bits[3]=$expr.ctx.bits; } WS expr[4] | ||
| { $table.dayOfWeek=(int)$expr.ctx.bits; } EOF | ||
| | (AT ('yearly' | ||
| { | ||
| $table.set("H H H H *",getHashForTokens()); | ||
| } | 'annually' | ||
| { | ||
| $table.set("H H H H *",getHashForTokens()); | ||
| } | 'monthly' | ||
| { | ||
| $table.set("H H H * *",getHashForTokens()); | ||
| } | 'weekly' | ||
| { | ||
| $table.set("H H * * H",getHashForTokens()); | ||
| } | 'daily' | ||
| { | ||
| $table.set("H H * * *",getHashForTokens()); | ||
| } | 'midnight' | ||
| { | ||
| $table.set("H H(0-2) * * *",getHashForTokens()); | ||
| } | 'hourly' | ||
| { | ||
| $table.set("H * * * *",getHashForTokens()); | ||
| })) | ||
| ; | ||
|
|
||
| expr[int field] returns[long bits=0] locals[long lhs, long rhs=0] | ||
| : term[field] | ||
| { $lhs = $term.ctx.bits; } (OR expr[field] | ||
| { $rhs = $expr.ctx.bits; })? | ||
| { | ||
| $bits = $lhs|$rhs; | ||
| } | ||
| ; | ||
|
|
||
| term[int field] returns[long bits=0] locals[int d=NO_STEP, int s, int e] | ||
| : token | ||
| { $s=$token.ctx.value; } MINUS token | ||
| { $e=$token.ctx.value; } (DIV token | ||
| { $d=$token.ctx.value; })? | ||
| { | ||
| $bits = doRange($s,$e,$d,$field); | ||
| } | ||
| | token | ||
| { | ||
| rangeCheck($token.ctx.value,$field); | ||
| $bits = 1L<<$token.ctx.value; | ||
| } | ||
| | STAR (DIV token | ||
| { $d=$token.ctx.value; })? | ||
| { | ||
| $bits = doRange($d,$field); | ||
| } | ||
| | 'H' LPAREN token | ||
| { $s=$token.ctx.value; } MINUS token | ||
| { $e=$token.ctx.value; } RPAREN (DIV token | ||
| { $d=$token.ctx.value; })? | ||
| { | ||
| $bits = doHash($s,$e,$d,$field); | ||
| } | ||
| | 'H' (DIV token | ||
| { $d=$token.ctx.value; })? | ||
| { | ||
| $bits = doHash($d,$field); | ||
| } | ||
| ; | ||
|
|
||
| token returns[int value=0] | ||
| : TOKEN | ||
| { | ||
| $value = Integer.parseInt($TOKEN.getText()); | ||
| } | ||
| ; | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.