Skip to content

Commit cf5eec5

Browse files
committed
Updated the specification
1 parent 20456b9 commit cf5eec5

File tree

4 files changed

+147
-141
lines changed

4 files changed

+147
-141
lines changed

README.md

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,63 +35,61 @@ abstract syntax description language (ASDL) as follows:
3535
3636
module Java
3737
{
38-
mod = CompilationUnit(Package? package, Import* imports, declaration* types)
39-
| ModularUnit(Import* imports, Module types)
38+
mod = CompilationUnit(Package? package, Import* imports, declaration* body)
39+
| ModularUnit(Import* imports, Module body)
4040
4141
declaration = EmptyDecl()
4242
| Package(Annotation* annotations, qname name)
43-
| Import(Annotation* annotations, bool static, qname name, bool on_demand)
44-
| Module(bool open, qname name, directive* directives)
45-
| Field(modifier* modifiers, jtype type, declarator* declarators)
46-
| Method(modifier* modifiers, typeparams? type_params, Annotation* annotations, jtype return_type,
47-
identifier id, params parameters, dim* dims, qname* throws, Block? body)
48-
| Constructor(modifier* modifiers, typeparams? type_params, identifier id, params? parameters, Block? body)
43+
| Import(bool? static, qname name, bool? on_demand)
44+
| Module(bool? open, qname name, directive* directives)
45+
| Field(modifier* modifiers, jtype type, declarator+ declarators)
46+
| Method(modifier* modifiers, typeparams? type_params, Annotation* annotations,
47+
jtype return_type, identifier id, params? parameters, dim* dims,
48+
qname* throws, Block? body)
49+
| Constructor(modifier* modifiers, typeparams? type_params, identifier id,
50+
params? parameters, Block body)
4951
| AnnotationMethod(modifier* modifiers, jtype type, identifier id,
5052
(elementarrayinit | Annotation | expr)? default_value)
51-
| Initializer(bool static, Block body)
52-
| Class(modifier* modifiers, identifier id, typeparams? type_params, jtype? extends, jtype* implements,
53-
jtype* permits, declaration* body)
54-
| Enum(modifier* modifiers, identifier id, jtype* implements, enumconstant* constants,
55-
declaration* body)
56-
| Interface(modifier* modifiers, identifier id, typeparams? type_params, jtype* extends, jtype* permits,
57-
declaration* body)
58-
| AnnotationDecl(modifier* modifiers, identifier id, jtype* extends, jtype* permits, declaration* body)
59-
| Record(modifier* modifiers, identifier id, typeparams? type_params, recordcomponent* components,
60-
jtype* implements, jtype* permits, declaration* body)
53+
| Initializer(Block body, bool? static)
54+
| Class(modifier* modifiers, identifier id, typeparams? type_params,
55+
jtype? extends, jtype* implements, jtype* permits, declaration* body)
56+
| Enum(modifier* modifiers, identifier id, jtype* implements,
57+
enumconstant* constants, declaration* body)
58+
| Interface(modifier* modifiers, identifier id, typeparams? type_params,
59+
jtype? extends, jtype* implements, declaration* body)
60+
| AnnotationDecl(modifier* modifiers, identifier id, declaration* body)
61+
| Record(modifier* modifiers, identifier id, typeparams? type_params,
62+
recordcomponent* components, jtype* implements, declaration* body)
6163
attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
6264
6365
directive = Requires(modifier* modifiers, qname name)
64-
| Exports(modifier* modifiers, qname name, qname to)
65-
| Opens(modifier* modifiers, qname name, qname to)
66-
| Uses(modifier* modifiers, qname name)
67-
| Provides(modifier* modifiers, qname name, qname with_)
66+
| Exports(qname name, qname to)
67+
| Opens(qname name, qname to)
68+
| Uses(qname name)
69+
| Provides(qname name, qname with_)
6870
attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
6971
7072
stmt = Empty()
7173
| Block(stmt* body)
7274
| Compound(stmt* body)
7375
74-
| LocalClass(Class decl)
75-
| LocalInterface(Interface decl)
76-
| LocalRecord(Record decl)
77-
| LocalVariable(modifier* modifiers, jtype type, declarator* variables)
76+
| LocalType((Class | Interface | Record) decl)
77+
| LocalVariable(modifier* modifiers, jtype type, declarator+ variables)
7878
7979
| Labeled(identifier label, stmt body)
8080
8181
| If(expr test, stmt body, stmt? orelse)
8282
| Switch(expr value, switchblock body)
8383
| While(expr test, stmt body)
8484
| DoWhile(stmt body, expr test)
85-
| For((expr* | LocalVariable)? init, expr? test, expr* update, stmt body)
86-
| ForEach(modifier* modifiers, jtype type, identifier id, expr iter, stmt body)
85+
| For((expr* | LocalVariable?) init, expr? test, expr* update, stmt body)
86+
| ForEach(modifier* modifiers, jtype type,
87+
identifier id, expr iter, stmt body)
8788
| Try(Block body, catch* catches, Block? final)
88-
| TryWithResources(Block body,
89-
(resource | qname)* resources,
90-
catch* catches,
91-
Block? final)
92-
89+
| TryWithResources((resource | qname)+ resources,
90+
Block body, catch* catches, Block? final)
9391
| Assert(expr test, expr? msg)
94-
| Throw(expr value)
92+
| Throw(expr exc)
9593
| Expression(expr value)
9694
| Return(expr? value)
9795
| Yield(expr value)
@@ -112,82 +110,87 @@ module Java
112110
| NewArray(jtype type, expr* expr_dims, dim* dims, arrayinit? initializer)
113111
| SwitchExp(expr value, switchexprule* rules)
114112
| This()
115-
| Super(typeargs? type_args. identifier? id)
113+
| Super(typeargs? type_args, identifier? id)
116114
| Constant(literal value)
117115
| Name(identifier id)
118116
| ClassExpr(jtype type)
119117
| ExplicitGenericInvocation(typeargs? type_args, expr value)
120118
| Subscript(expr value, expr index)
121119
| Member(expr value, expr member)
122120
| Call(expr func, expr* args)
123-
| Reference((expr | jtype )type, typeargs? type_args, identifier id, bool new)
121+
| Reference((expr | jtype ) type, typeargs? type_args, identifier? id, bool? new)
124122
| Match(jtype type, identifier id)
125123
attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
126124
127-
operator = Or() | And() | BitOr() | BitXor() | BitAnd() | Eq() | NotEq() | Lt() | LtE() | Gt() | GtE()
128-
| LShift() | RShift() | URShift() | Add() | Sub() | Mult() | Div() | Mod()
125+
operator = Or() | And() | BitOr() | BitXor() | BitAnd() | Eq() | NotEq()
126+
| Lt() | LtE() | Gt() | GtE() | LShift() | RShift() | URShift()
127+
| Add() | Sub() | Mult() | Div() | Mod()
129128
130129
unaryop = PreInc() | PreDec() | UAdd() | USub() | Invert() | Not()
131130
132131
postop = PostInc() | PostDec()
133132
134-
enumconstant = (Annotation* annotations, identifier id, expr* arguments, Block? body)
133+
enumconstant = (Annotation* annotations, identifier id, expr* args, declaration* body)
135134
136135
recordcomponent = (jtype type, identifier id)
137136
138-
switchlabel = Case(expr value) | DefaultCase()
139-
switchgroup = (switchlabel* labels, stmt* statements)
137+
switchlabel = Case(expr guard) | DefaultCase()
138+
switchgroup = (switchlabel* labels, stmt* body)
140139
switchblock = (switchgroup* groups, switchlabel* labels)
141140
142-
catch = (modifier* modifiers, qname* excs, identifier id, Block body)
141+
catch = (modifier* modifiers, qname+ excs, identifier id, Block body)
143142
144143
resource = (modifier* modifiers, jtype type, declarator variable)
145144
146145
switchexplabel = ExpCase() | ExpDefault()
147-
switchexprule = (switchexplabel label, (expr | guardedpattern)* cases, bool arrow, stmt* body)
146+
switchexprule = (switchexplabel label, (expr | guardedpattern)* cases,
147+
bool arrow, stmt* body)
148148
149149
arrayinit = ((expr | arrayinit)* values)
150150
151151
receiver = (jtype type, identifier* identifiers)
152152
param = (modifier* modifiers, jtype type, variabledeclaratorid id)
153153
arity = (modifier* modifiers, jtype type, Annotation* annotations, variabledeclaratorid id)
154-
params = (receiver receiver_param, (param | arity)* parameters)
154+
params = (receiver? receiver_param, (param | arity)* parameters)
155155
156-
literal = IntLiteral(int value, bool long) | FloatLiteral(float value, bool double) | BoolLiteral(bool value)
157-
| CharLiteral(char value) | StringLiteral(string value) | TextBlock(string value) | NullLiteral()
156+
literal = IntLiteral(int value, bool? long) | FloatLiteral(float value, bool? double)
157+
| BoolLiteral(bool value) | CharLiteral(char value) | StringLiteral(string value)
158+
| TextBlock(string* value) | NullLiteral()
158159
159-
modifier = Abstract() | Default() | Final() | Native() | NonSealed() | Private() | Protected()
160-
| Public() | Sealed() | Static() | Strictfp() | Synchronized() | Transient() | Transitive() | Volatile()
160+
modifier = Abstract() | Default() | Final() | Native() | NonSealed() | Private()
161+
| Protected() | Public() | Sealed() | Static() | Strictfp() | Synchronized()
162+
| Transient() | Transitive() | Volatile()
161163
| Annotation(qname name, (elementvaluepair | elementarrayinit | Annotation | expr)* elements)
162164
163165
164166
elementvaluepair = (identifier id, (elementarrayinit | Annotation | expr) value)
165167
elementarrayinit = ((elementarrayinit | Annotation | expr)* values)
166168
167-
jtype = Void() | Var() | Boolean() | Byte() | Short() | Int() | Long() | Char() | Float() | Double()
169+
jtype = Void() | Var() | Boolean() | Byte() | Short()
170+
| Int() | Long() | Char() | Float() | Double()
168171
| Wildcard(Annotation* annotations, wildcardbound? bound)
169172
| Coit(Annotation* annotations, identifier id, typeargs? type_args)
170173
| ClassType(Annotation* annotations, Coit+ coits)
171174
| ArrayType(Annotation* annotations, jtype type, dim* dims)
172175
173176
174-
wildcardbound = (jtype type, bool extends, bool super_)
177+
wildcardbound = (jtype type, bool? extends, bool? super_)
175178
176-
typeargs = (jtype* types)
179+
typeargs = (jtype+ types)
177180
178181
dim = (Annotation* annotations)
179182
180183
variabledeclaratorid = (identifier id, dim* dims)
181-
declarator = (variabledeclaratorid id, expr? value)
184+
declarator = (variabledeclaratorid id, expr? init)
182185
183-
typebound = (Annotation* annotations, jtype* types)
186+
typebound = (Annotation* annotations, jtype+ types)
184187
typeparam = (Annotation* annotations, identifier id, typebound? bound)
185-
typeparams = (typeparam* params)
188+
typeparams = (typeparam* parameters)
186189
187190
pattern = (modifier* modifiers, jtype type, Annotation* annotations, identifier id)
188-
guardedpattern = (pattern pattern, expr* conditions)
191+
guardedpattern = (pattern value, expr* conditions)
189192
190-
qname = (identifier* identifiers)
193+
qname = (identifier+ identifiers)
191194
}
192195
```
193196

demo.ipynb

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"id": "initial_id",
1818
"metadata": {
1919
"ExecuteTime": {
20-
"end_time": "2025-01-25T12:50:19.947286Z",
21-
"start_time": "2025-01-25T12:50:19.837080Z"
20+
"end_time": "2025-02-06T12:59:58.830347Z",
21+
"start_time": "2025-02-06T12:59:58.446584Z"
2222
}
2323
},
2424
"source": [
@@ -60,8 +60,8 @@
6060
"id": "bf312f502956220",
6161
"metadata": {
6262
"ExecuteTime": {
63-
"end_time": "2025-01-25T12:50:21.196711Z",
64-
"start_time": "2025-01-25T12:50:21.192256Z"
63+
"end_time": "2025-02-06T13:00:03.338320Z",
64+
"start_time": "2025-02-06T13:00:03.333906Z"
6565
}
6666
},
6767
"source": [
@@ -77,8 +77,8 @@
7777
"id": "8b94a8dcd4020c50",
7878
"metadata": {
7979
"ExecuteTime": {
80-
"end_time": "2025-01-25T12:50:21.807181Z",
81-
"start_time": "2025-01-25T12:50:21.803281Z"
80+
"end_time": "2025-02-06T13:00:04.937872Z",
81+
"start_time": "2025-02-06T13:00:04.933719Z"
8282
}
8383
},
8484
"source": [
@@ -116,8 +116,8 @@
116116
"id": "4d8718b803e0f47b",
117117
"metadata": {
118118
"ExecuteTime": {
119-
"end_time": "2025-01-25T12:50:24.162800Z",
120-
"start_time": "2025-01-25T12:50:22.950369Z"
119+
"end_time": "2025-02-06T13:00:09.058994Z",
120+
"start_time": "2025-02-06T13:00:07.820237Z"
121121
}
122122
},
123123
"source": [
@@ -151,8 +151,8 @@
151151
"id": "52f23f3918051e40",
152152
"metadata": {
153153
"ExecuteTime": {
154-
"end_time": "2025-01-25T12:50:26.137178Z",
155-
"start_time": "2025-01-25T12:50:25.574662Z"
154+
"end_time": "2025-02-06T13:00:12.419839Z",
155+
"start_time": "2025-02-06T13:00:11.854787Z"
156156
}
157157
},
158158
"source": [
@@ -174,8 +174,8 @@
174174
"id": "583c68223e6d6843",
175175
"metadata": {
176176
"ExecuteTime": {
177-
"end_time": "2025-01-25T12:50:27.158381Z",
178-
"start_time": "2025-01-25T12:50:27.154091Z"
177+
"end_time": "2025-02-06T13:00:15.180650Z",
178+
"start_time": "2025-02-06T13:00:15.175932Z"
179179
}
180180
},
181181
"source": [
@@ -187,11 +187,10 @@
187187
"output_type": "stream",
188188
"text": [
189189
"class Add {\n",
190-
"\n",
191190
" public static int add(int a, int b) {\n",
192191
" return a + b;\n",
193192
" }\n",
194-
"\n",
193+
" \n",
195194
" public static void main(String[] args) {\n",
196195
" System.out.println(add(27, 55));\n",
197196
" }\n",
@@ -214,8 +213,8 @@
214213
"id": "2cfe0a0b889b9fbb",
215214
"metadata": {
216215
"ExecuteTime": {
217-
"end_time": "2025-01-25T12:50:34.309813Z",
218-
"start_time": "2025-01-25T12:50:34.305679Z"
216+
"end_time": "2025-02-06T13:00:17.182339Z",
217+
"start_time": "2025-02-06T13:00:17.177639Z"
219218
}
220219
},
221220
"source": [
@@ -240,8 +239,8 @@
240239
"id": "e7d82968c176df7d",
241240
"metadata": {
242241
"ExecuteTime": {
243-
"end_time": "2025-01-25T12:50:34.939826Z",
244-
"start_time": "2025-01-25T12:50:34.935823Z"
242+
"end_time": "2025-02-06T13:00:18.090187Z",
243+
"start_time": "2025-02-06T13:00:18.086898Z"
245244
}
246245
},
247246
"source": [
@@ -255,8 +254,8 @@
255254
"id": "2d69c9374f3e472",
256255
"metadata": {
257256
"ExecuteTime": {
258-
"end_time": "2025-01-25T12:50:35.638315Z",
259-
"start_time": "2025-01-25T12:50:35.634525Z"
257+
"end_time": "2025-02-06T13:00:19.047446Z",
258+
"start_time": "2025-02-06T13:00:19.044028Z"
260259
}
261260
},
262261
"source": [
@@ -270,8 +269,8 @@
270269
"id": "e7537f68f596fdea",
271270
"metadata": {
272271
"ExecuteTime": {
273-
"end_time": "2025-01-25T12:50:36.359583Z",
274-
"start_time": "2025-01-25T12:50:36.355463Z"
272+
"end_time": "2025-02-06T13:00:20.172020Z",
273+
"start_time": "2025-02-06T13:00:20.168020Z"
275274
}
276275
},
277276
"source": [
@@ -284,11 +283,10 @@
284283
"output_type": "stream",
285284
"text": [
286285
"class Add {\n",
287-
"\n",
288286
" public static int add(int a, int b) {\n",
289287
" return a - b;\n",
290288
" }\n",
291-
"\n",
289+
" \n",
292290
" public static void main(String[] args) {\n",
293291
" System.out.println(add(27, 55));\n",
294292
" }\n",
@@ -311,8 +309,8 @@
311309
"id": "1edccb99a2180641",
312310
"metadata": {
313311
"ExecuteTime": {
314-
"end_time": "2025-01-25T12:50:38.071178Z",
315-
"start_time": "2025-01-25T12:50:38.067505Z"
312+
"end_time": "2025-02-06T13:00:21.747847Z",
313+
"start_time": "2025-02-06T13:00:21.743691Z"
316314
}
317315
},
318316
"source": [
@@ -327,8 +325,8 @@
327325
"id": "ee6bb639f1cb1049",
328326
"metadata": {
329327
"ExecuteTime": {
330-
"end_time": "2025-01-25T12:50:39.437582Z",
331-
"start_time": "2025-01-25T12:50:38.718069Z"
328+
"end_time": "2025-02-06T13:00:23.134239Z",
329+
"start_time": "2025-02-06T13:00:22.418301Z"
332330
}
333331
},
334332
"source": [
@@ -353,8 +351,8 @@
353351
"id": "b640254f9c8c038c",
354352
"metadata": {
355353
"ExecuteTime": {
356-
"end_time": "2025-01-25T12:50:40.369866Z",
357-
"start_time": "2025-01-25T12:50:40.084728Z"
354+
"end_time": "2025-02-06T13:00:24.273726Z",
355+
"start_time": "2025-02-06T13:00:23.979681Z"
358356
}
359357
},
360358
"source": [

0 commit comments

Comments
 (0)