Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c6b7b0e
Start of transition to ANTLR4
slide Oct 20, 2022
b9b5d91
fix: Update ANTLR2 to ANTLR4 to fix JENKINS-68652
slide Oct 21, 2022
eb254d8
mvn spotless:apply
basil Oct 21, 2022
34a8677
Ignore SpotBugs warnings in generated code
basil Oct 21, 2022
2c8a07e
Restore Java 8 error message support
basil Oct 21, 2022
70ea6bd
Merge branch 'master' into antlr4_update
basil Oct 21, 2022
dbb8236
Add files/dirs for ANTLR4
slide Oct 21, 2022
0ff8df7
Reformat .g4 files add ANTLRException for backward compat.
slide Oct 22, 2022
470a683
Merge branch 'master' into antlr4_update
basil Oct 22, 2022
9b6d09d
fix typo
basil Oct 22, 2022
ff1f8a6
full set of exception constructors
basil Oct 22, 2022
bed2789
Remove unnecessary throws from tests
basil Oct 22, 2022
c63d928
Deprecate compatibility layer
basil Oct 22, 2022
bd3583e
Merge remote-tracking branch 'origin/master' into antlr4_update
basil Oct 26, 2022
ffc1efd
Implement feedback suggestions
slide Oct 28, 2022
2ec365b
Merge branch 'master' into antlr4_update
basil Oct 28, 2022
d3e4abd
Clean up error handling
basil Oct 28, 2022
8f52de2
fixups
basil Oct 28, 2022
f4b0ec8
No need for BailErrorStrategy and it is inconsistent with label expre…
basil Oct 28, 2022
6c533d5
fixups
basil Oct 28, 2022
c96cf97
we like stacks
basil Oct 28, 2022
0a434b4
Extract version into property for easy updating
basil Oct 28, 2022
9e394c4
no need for executions in plugin management section
basil Oct 28, 2022
2011696
Remove unnecessary JARs from WAR
basil Oct 28, 2022
84d8e35
stack traces are wonderful
basil Oct 28, 2022
f19185d
Update .gitignore
basil Oct 29, 2022
e4f50b3
fixups
basil Oct 29, 2022
a90503e
Merge branch 'master' into antlr4_update
basil Oct 30, 2022
977de92
fixup
basil Oct 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ THE SOFTWARE.
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<!-- JENKINS-21160: Remoting also depends on args4j; please update accordingly -->
<groupId>args4j</groupId>
Expand Down Expand Up @@ -190,6 +185,11 @@ THE SOFTWARE.
<artifactId>kxml2</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>${antlr.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
Expand Down
31 changes: 8 additions & 23 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ THE SOFTWARE.
<groupId>${project.groupId}</groupId>
<artifactId>remoting</artifactId>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
</dependency>
<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
Expand Down Expand Up @@ -278,6 +274,10 @@ THE SOFTWARE.
<groupId>net.sf.kxml</groupId>
<artifactId>kxml2</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
Expand Down Expand Up @@ -571,7 +571,6 @@ THE SOFTWARE.
<phase>generate-sources</phase>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/antlr</source>
<source>${project.build.directory}/generated-sources/localizer</source>
<source>${project.build.directory}/generated-sources/taglib-interface</source>
</sources>
Expand Down Expand Up @@ -632,29 +631,15 @@ THE SOFTWARE.
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>antlr-maven-plugin</artifactId>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<!-- version specified in grandparent pom -->
<executions>
<execution>
<id>cron</id>
<id>antlr</id>
<goals>
<goal>generate</goal>
<goal>antlr4</goal>
</goals>
<configuration>
<sourceDirectory>${basedir}/src/main/grammar</sourceDirectory>
<grammars>crontab.g</grammars>
</configuration>
</execution>
<execution>
<id>labelExpr</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<sourceDirectory>${basedir}/src/main/grammar</sourceDirectory>
<grammars>labelExpr.g</grammars>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
57 changes: 57 additions & 0 deletions core/src/main/antlr4/hudson/model/labels/LabelExpressionLexer.g4
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 core/src/main/antlr4/hudson/model/labels/LabelExpressionParser.g4
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())); }
;

70 changes: 70 additions & 0 deletions core/src/main/antlr4/hudson/scheduler/CrontabLexer.g4
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'
;

83 changes: 83 additions & 0 deletions core/src/main/antlr4/hudson/scheduler/CrontabParser.g4
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());
}
;

Loading