Skip to content

Commit c85e958

Browse files
committed
GROOVY-9381: Add native async/await support
1 parent fa02ed1 commit c85e958

41 files changed

Lines changed: 26737 additions & 4 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ dependencies {
118118
testImplementation "com.thoughtworks.qdox:qdox:${versions.qdox}"
119119
testImplementation "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
120120
testImplementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${versions.jackson}"
121+
testImplementation "io.reactivex.rxjava3:rxjava:${versions.rxjava3}"
122+
testImplementation "io.projectreactor:reactor-core:${versions.reactor}"
121123

122124
testFixturesImplementation projects.groovyXml
123125
testFixturesImplementation projects.groovyTest

gradle/verification-metadata.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<ignored-key id="C71FB765CD9DE313" reason="Key couldn't be downloaded from any key server"/>
117117
<ignored-key id="C7CA19B7B620D787" reason="Key couldn't be downloaded from any key server"/>
118118
<ignored-key id="CA80D1F0EB6CA4BA" reason="Key couldn't be downloaded from any key server"/>
119+
<ignored-key id="D1031D14464180E0" reason="Key couldn't be downloaded from any key server"/>
119120
<ignored-key id="D2151178A123C97F" reason="Key couldn't be downloaded from any key server"/>
120121
<ignored-key id="D364ABAA39A47320" reason="Key couldn't be downloaded from any key server"/>
121122
<ignored-key id="D7742D58455ECC7C" reason="Key couldn't be downloaded from any key server"/>
@@ -874,6 +875,16 @@
874875
<sha512 value="f220e44fe6b61f8dbb61226f832dfb16a09584384540fd48a4dff5c4de9fee060623f85cbead720dfe776aa25105949e70758a9bb1d9db43f63068d8d22164c9" origin="Generated by Gradle"/>
875876
</artifact>
876877
</component>
878+
<component group="io.projectreactor" name="reactor-core" version="3.7.3">
879+
<artifact name="reactor-core-3.7.3.jar">
880+
<pgp value="48B086A7D843CFA258E83286928FBF39003C0425"/>
881+
</artifact>
882+
</component>
883+
<component group="io.reactivex.rxjava3" name="rxjava" version="3.1.10">
884+
<artifact name="rxjava-3.1.10.jar">
885+
<pgp value="E9CC3CD1AE59E851E4DB3FA350FFD7487D34B5B9"/>
886+
</artifact>
887+
</component>
877888
<component group="jakarta.activation" name="jakarta.activation-api" version="1.2.1">
878889
<artifact name="jakarta.activation-api-1.2.1.jar">
879890
<pgp value="6DD3B8C64EF75253BEB2C53AD908A43FB7EC07AC"/>
@@ -2229,6 +2240,11 @@
22292240
<sha512 value="adcc480f68828ffd68d03846be852988b595c2e1bb69224d273578dd6c2ad2773edfe96625a7c00bc40ae0f2d1cac8412eaa54b88cc8e681b0b4c0ee3b082333" origin="Generated by Gradle"/>
22302241
</artifact>
22312242
</component>
2243+
<component group="org.reactivestreams" name="reactive-streams" version="1.0.4">
2244+
<artifact name="reactive-streams-1.0.4.jar">
2245+
<sha512 value="cdab6bd156f39106cd6bbfd47df1f4b0a89dc4aa28c68c31ef12a463193c688897e415f01b8d7f0d487b0e6b5bd2f19044bf8605704b024f26d6aa1f4f9a2471" origin="Generated by Gradle" reason="A key couldn't be downloaded"/>
2246+
</artifact>
2247+
</component>
22322248
<component group="org.reflections" name="reflections" version="0.10.2">
22332249
<artifact name="reflections-0.10.2.jar">
22342250
<pgp value="3F2A008A91D11A7FAC4A0786F13D3E721D56BD54"/>

src/antlr/GroovyLexer.g4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ DEF : 'def';
392392
IN : 'in';
393393
TRAIT : 'trait';
394394
THREADSAFE : 'threadsafe'; // reserved keyword
395+
ASYNC : 'async';
396+
AWAIT : 'await';
397+
DEFER : 'defer';
395398

396399
// §3.9 Keywords
397400
BuiltInPrimitiveType

src/antlr/GroovyParser.g4

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ modifier
134134
| VOLATILE
135135
| DEF
136136
| VAR
137+
| ASYNC
137138
)
138139
;
139140

@@ -600,7 +601,7 @@ switchStatement
600601
;
601602

602603
loopStatement
603-
: FOR LPAREN forControl RPAREN nls statement #forStmtAlt
604+
: FOR AWAIT? LPAREN forControl RPAREN nls statement #forStmtAlt
604605
| WHILE expressionInPar nls statement #whileStmtAlt
605606
| DO nls statement nls WHILE expressionInPar #doWhileStmtAlt
606607
;
@@ -642,6 +643,8 @@ statement
642643
| continueStatement #continueStmtAlt
643644
| { inSwitchExpressionLevel > 0 }?
644645
yieldStatement #yieldStmtAlt
646+
| YIELD RETURN nls expression #yieldReturnStmtAlt
647+
| DEFER nls statementExpression #deferStmtAlt
645648
| identifier COLON nls statement #labeledStmtAlt
646649
| assertStatement #assertStmtAlt
647650
| localVariableDeclaration #localVariableDeclarationStmtAlt
@@ -778,6 +781,10 @@ expression
778781
// must come before postfixExpression to resolve the ambiguities between casting and call on parentheses expression, e.g. (int)(1 / 2)
779782
: castParExpression castOperandExpression #castExprAlt
780783

784+
// async closure/lambda must come before postfixExpression to resolve the ambiguities between async and method call, e.g. async { ... }
785+
| ASYNC nls closureOrLambdaExpression #asyncClosureExprAlt
786+
| AWAIT nls (LPAREN expression RPAREN | expression) #awaitExprAlt
787+
781788
// qualified names, array expressions, method invocation, post inc/dec
782789
| postfixExpression #postfixExprAlt
783790

@@ -1228,6 +1235,9 @@ identifier
12281235
: Identifier
12291236
| CapitalizedIdentifier
12301237
| AS
1238+
| ASYNC
1239+
| AWAIT
1240+
| DEFER
12311241
| IN
12321242
| PERMITS
12331243
| RECORD
@@ -1246,12 +1256,15 @@ keywords
12461256
: ABSTRACT
12471257
| AS
12481258
| ASSERT
1259+
| ASYNC
1260+
| AWAIT
12491261
| BREAK
12501262
| CASE
12511263
| CATCH
12521264
| CLASS
12531265
| CONST
12541266
| CONTINUE
1267+
| DEFER
12551268
| DEF
12561269
| DEFAULT
12571270
| DO

0 commit comments

Comments
 (0)