435
|
1 |
"{ Package: 'stx:goodies/petitparser/parsers/java' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
PPJavaLexicon subclass:#PPJavaSyntax
|
|
6 |
instanceVariableNames:'compilationUnit annotations packageDeclaration importDeclaration
|
|
7 |
typeDeclaration qualifiedName annotation
|
|
8 |
classOrInterfaceDeclaration classDeclaration interfaceDeclaration
|
|
9 |
normalClassDeclaration enumDeclaration classModifiers
|
|
10 |
typeParameters type typeList classBody jsuper interfaces
|
|
11 |
typeParameter typeBound enumBody enumConstants
|
|
12 |
enumBodyDeclarations enumConstant arguments classBodyDeclaration
|
|
13 |
normalInterfaceDeclaration annotationTypeDeclaration
|
|
14 |
interfaceModifiers interfaceBody interfaceBodyDeclaration block
|
|
15 |
fieldDeclaration methodDeclaration methodModifiers
|
|
16 |
formalParameters throws qualifiedNameList
|
|
17 |
explicitConstructorInvocation blockStatement fieldModifiers
|
|
18 |
variableDeclarators variableDeclarator variableInitializer
|
|
19 |
interfaceFieldDeclaration interfaceMethodDeclaration
|
|
20 |
classOrInterfaceType primitiveType typeArguments typeArgument
|
|
21 |
formalParameterDecls ellipsisParameterDecl normalParameterDecl
|
|
22 |
variableModifiers nonWildcardTypeArguments primary
|
|
23 |
elementValuePairs elementValue elementValuePair
|
|
24 |
conditionalExpression elementValueArrayInitializer
|
|
25 |
annotationTypeBody annotationTypeElementDeclaration
|
|
26 |
annotationMethodDeclaration localVariableDeclarationStatement
|
|
27 |
statement localVariableDeclaration expression parExpression
|
|
28 |
ifStatement assertStatement basicForStatement
|
|
29 |
enhancedForStatement forInit expressionList forStatement
|
|
30 |
whileStatement catches catchClause formalParameter doStatement
|
|
31 |
tryStatement switchBlockStatementGroup switchLabel
|
|
32 |
switchStatement synchronizedStatement returnStatement
|
|
33 |
throwStatement breakStatement continueStatement
|
|
34 |
expressionStatement labeledStatement emptyStatement
|
|
35 |
assignmentOperator conditionalOrExpression
|
|
36 |
conditionalAndExpression inclusiveOrExpression
|
|
37 |
exclusiveOrExpression andExpression equalityExpression
|
|
38 |
instanceofExpression relationalExpression shiftExpression
|
|
39 |
relationalOperator additiveExpression shiftOperator
|
|
40 |
multiplicativeExpression unaryExpression
|
|
41 |
unaryExpressionNotPlusMinus castExpression selector innerCreator
|
|
42 |
superSuffix identifierSuffix creator classCreatorRest
|
|
43 |
arrayCreator createdName arrayInitializer constructorDeclaration
|
|
44 |
constructorModifiers methodNotConstructorDeclaration wildcard
|
|
45 |
emptySquaredParenthesis methodModifierNotAnnotation
|
|
46 |
classModifierNotAnnotation unaryNegationExpression
|
|
47 |
unaryPostfixExpression primaryWithselectors
|
|
48 |
startMethodDeclaration identifierWithAccessors
|
|
49 |
normalParametersWithElipsisDecls normalParametersDecls
|
|
50 |
blockStatements statementWithoutTrailingSubstatement integralType
|
|
51 |
floatingPointType numericType finally'
|
|
52 |
classVariableNames:''
|
|
53 |
poolDictionaries:''
|
|
54 |
category:'PetitJava-Core'
|
|
55 |
!
|
|
56 |
|
|
57 |
PPJavaSyntax comment:'Parses Java code into lots of arrays. This parser has a full java gramar coverage'
|
|
58 |
!
|
|
59 |
|
|
60 |
!PPJavaSyntax class methodsFor:'as yet unclassified'!
|
|
61 |
|
|
62 |
parseMethod: aString
|
|
63 |
^ self new parseMethod: aString
|
|
64 |
!
|
|
65 |
|
|
66 |
parseMethod: aString onError: aBlock
|
|
67 |
^ self new parseMethod: aString onError: aBlock
|
|
68 |
! !
|
|
69 |
|
|
70 |
!PPJavaSyntax methodsFor:'accessing'!
|
|
71 |
|
|
72 |
start
|
|
73 |
"Default start production."
|
|
74 |
|
|
75 |
^ compilationUnit end
|
|
76 |
! !
|
|
77 |
|
|
78 |
!PPJavaSyntax methodsFor:'as yet unclassified'!
|
|
79 |
|
|
80 |
fieldAccessExpression
|
|
81 |
|
|
82 |
|
|
83 |
^(
|
|
84 |
" Primary.Identifier"
|
|
85 |
(primary , (self tokenFor: '.'), identifier)
|
|
86 |
"Super.Identifier"
|
|
87 |
/((self tokenFor: 'super'), superSuffix )
|
|
88 |
"ClassName.super.Identifier"
|
|
89 |
/(identifier,(self tokenFor: '.'),(self tokenFor: 'super'),superSuffix)
|
|
90 |
)plus.
|
|
91 |
!
|
|
92 |
|
|
93 |
finally
|
|
94 |
^ ((self tokenFor: 'finally'), block).
|
|
95 |
!
|
|
96 |
|
|
97 |
integralType
|
|
98 |
^ (self tokenFor: 'byte')
|
|
99 |
/ (self tokenFor: 'short')
|
|
100 |
/ (self tokenFor: 'int')
|
|
101 |
/ (self tokenFor: 'long')
|
|
102 |
/ (self tokenFor: 'char')
|
|
103 |
! !
|
|
104 |
|
|
105 |
!PPJavaSyntax methodsFor:'grammar'!
|
|
106 |
|
|
107 |
arguments
|
|
108 |
|
|
109 |
^(self tokenFor: '('),
|
|
110 |
expressionList optional,
|
|
111 |
(self tokenFor: ')')
|
|
112 |
!
|
|
113 |
|
|
114 |
arrayCreator
|
|
115 |
|
|
116 |
^ ( (self tokenFor: 'new') , createdName ,
|
|
117 |
emptySquaredParenthesis plus,
|
|
118 |
arrayInitializer)
|
|
119 |
|
|
120 |
/( (self tokenFor: 'new'), createdName ,
|
|
121 |
((self tokenFor: '['), expression , (self tokenFor: ']')) plus,
|
|
122 |
emptySquaredParenthesis star)
|
|
123 |
!
|
|
124 |
|
|
125 |
arrayInitializer
|
|
126 |
|
|
127 |
^ (self tokenFor: '{'),
|
|
128 |
(variableInitializer , ((self tokenFor: ','), variableInitializer ) star) optional,
|
|
129 |
(self tokenFor: ',') optional,
|
|
130 |
(self tokenFor: '}')
|
|
131 |
!
|
|
132 |
|
|
133 |
block
|
|
134 |
|
|
135 |
^ (self tokenFor: '{') ,
|
|
136 |
blockStatements,
|
|
137 |
(self tokenFor: '}')
|
|
138 |
!
|
|
139 |
|
|
140 |
classCreatorRest
|
|
141 |
|
|
142 |
^ arguments , classBody optional
|
|
143 |
!
|
|
144 |
|
|
145 |
compilationUnit
|
|
146 |
|
|
147 |
^ (annotations optional, packageDeclaration) optional , importDeclaration star , typeDeclaration plus
|
|
148 |
!
|
|
149 |
|
|
150 |
createdName
|
|
151 |
|
|
152 |
^ classOrInterfaceType
|
|
153 |
/ primitiveType
|
|
154 |
!
|
|
155 |
|
|
156 |
creator
|
|
157 |
|
|
158 |
^ ( (self tokenFor: 'new'), nonWildcardTypeArguments optional , classOrInterfaceType , classCreatorRest)
|
|
159 |
/ arrayCreator
|
|
160 |
!
|
|
161 |
|
|
162 |
elementValue
|
|
163 |
|
|
164 |
^conditionalExpression
|
|
165 |
/ annotation
|
|
166 |
/ elementValueArrayInitializer
|
|
167 |
!
|
|
168 |
|
|
169 |
elementValueArrayInitializer
|
|
170 |
|
|
171 |
^ (self tokenFor: '{') ,
|
|
172 |
(elementValue ,
|
|
173 |
((self tokenFor: ',') , elementValue ) star
|
|
174 |
) optional ,
|
|
175 |
((self tokenFor: ',') optional ),
|
|
176 |
(self tokenFor: '}')
|
|
177 |
!
|
|
178 |
|
|
179 |
elementValuePair
|
|
180 |
|
|
181 |
^ identifier , (self tokenFor: '=') , elementValue
|
|
182 |
!
|
|
183 |
|
|
184 |
elementValuePairs
|
|
185 |
|
|
186 |
^ elementValuePair , ((self tokenFor: ',') , elementValuePair ) star
|
|
187 |
!
|
|
188 |
|
|
189 |
explicitConstructorInvocation
|
|
190 |
|
|
191 |
^ (
|
|
192 |
( nonWildcardTypeArguments optional,
|
|
193 |
((self tokenFor: 'this') / (self tokenFor: 'super')))
|
|
194 |
|
|
195 |
/ (primary ,
|
|
196 |
(self tokenFor: '.') ,
|
|
197 |
nonWildcardTypeArguments optional,
|
|
198 |
(self tokenFor: 'super'))) ,
|
|
199 |
|
|
200 |
arguments ,
|
|
201 |
(self tokenFor: ';')
|
|
202 |
!
|
|
203 |
|
|
204 |
identifierWithAccessors
|
|
205 |
^ identifier,
|
|
206 |
((self tokenFor: '.'), identifier ) star,
|
|
207 |
identifierSuffix optional
|
|
208 |
!
|
|
209 |
|
|
210 |
importDeclaration
|
|
211 |
|
|
212 |
^ ((self tokenFor: 'import') , (self tokenFor: 'static') optional , identifier),
|
|
213 |
( ( (self tokenFor: '.') , (self tokenFor: '*'))
|
|
214 |
/( ((self tokenFor: '.') , identifier) plus , ((self tokenFor: '.') , (self tokenFor: '*')) optional)
|
|
215 |
),
|
|
216 |
(self tokenFor: ';')
|
|
217 |
!
|
|
218 |
|
|
219 |
innerCreator
|
|
220 |
|
|
221 |
^ (self tokenFor: '.'), (self tokenFor: 'new'),
|
|
222 |
nonWildcardTypeArguments optional,
|
|
223 |
identifier ,
|
|
224 |
typeArguments optional,
|
|
225 |
classCreatorRest
|
|
226 |
!
|
|
227 |
|
|
228 |
interfaces
|
|
229 |
|
|
230 |
^ (self tokenFor: 'implements') , typeList
|
|
231 |
!
|
|
232 |
|
|
233 |
jsuper
|
|
234 |
|
|
235 |
^ (self tokenFor: 'extends') , type
|
|
236 |
!
|
|
237 |
|
|
238 |
nonWildcardTypeArguments
|
|
239 |
|
|
240 |
^(self tokenFor: '<'),
|
|
241 |
typeList ,
|
|
242 |
(self tokenFor: '>')
|
|
243 |
!
|
|
244 |
|
|
245 |
packageDeclaration
|
|
246 |
|
|
247 |
^ (self tokenFor: 'package') , qualifiedName , (self tokenFor: ';')
|
|
248 |
!
|
|
249 |
|
|
250 |
primary
|
|
251 |
|
|
252 |
^ parExpression
|
|
253 |
/( (self tokenFor: 'this'),
|
|
254 |
((self tokenFor: '.'), identifier ) star,
|
|
255 |
identifierSuffix optional)
|
|
256 |
/ identifierWithAccessors
|
|
257 |
/( (self tokenFor: 'super'), superSuffix )
|
|
258 |
/ literal
|
|
259 |
/ creator
|
|
260 |
/( primitiveType,
|
|
261 |
emptySquaredParenthesis star,
|
|
262 |
(self tokenFor: '.'), (self tokenFor: 'class'))
|
|
263 |
/( (self tokenFor: 'void'), (self tokenFor: '.'), (self tokenFor: 'class'))
|
|
264 |
|
|
265 |
!
|
|
266 |
|
|
267 |
qualifiedName
|
|
268 |
|
|
269 |
^ identifier , ((self tokenFor: '.'), identifier ) star
|
|
270 |
!
|
|
271 |
|
|
272 |
typeBound
|
|
273 |
|
|
274 |
^ type , ((self tokenFor: '&') , type) star
|
|
275 |
!
|
|
276 |
|
|
277 |
typeDeclaration
|
|
278 |
|
|
279 |
^ (self tokenFor: ';') / classOrInterfaceDeclaration
|
|
280 |
!
|
|
281 |
|
|
282 |
typeList
|
|
283 |
|
|
284 |
^ type , ((self tokenFor: ','), type) star
|
|
285 |
!
|
|
286 |
|
|
287 |
typeParameter
|
|
288 |
|
|
289 |
^ identifier , ((self tokenFor: 'extends') , typeBound) optional
|
|
290 |
!
|
|
291 |
|
|
292 |
typeParameters
|
|
293 |
|
|
294 |
^ (self tokenFor: '<') ,
|
|
295 |
typeParameter ,
|
|
296 |
((self tokenFor: ',') , typeParameter) star ,
|
|
297 |
(self tokenFor: '>')
|
|
298 |
!
|
|
299 |
|
|
300 |
unaryExpressionNotPlusMinus
|
|
301 |
|
|
302 |
^ unaryNegationExpression
|
|
303 |
/castExpression
|
|
304 |
/unaryPostfixExpression
|
|
305 |
!
|
|
306 |
|
|
307 |
variableInitializer
|
|
308 |
|
|
309 |
^ arrayInitializer
|
|
310 |
/ expression
|
|
311 |
! !
|
|
312 |
|
|
313 |
!PPJavaSyntax methodsFor:'grammar-annotations'!
|
|
314 |
|
|
315 |
annotation
|
|
316 |
|
|
317 |
^(self tokenFor: '@') , qualifiedName ,
|
|
318 |
((self tokenFor: '(') ,
|
|
319 |
(elementValuePairs / elementValue) optional ,
|
|
320 |
(self tokenFor: ')') ) optional
|
|
321 |
!
|
|
322 |
|
|
323 |
annotationMethodDeclaration
|
|
324 |
self flag: 'check whether method modifiers are the right modifiers to use'.
|
|
325 |
|
|
326 |
^ methodModifiers ,
|
|
327 |
type ,
|
|
328 |
identifier ,
|
|
329 |
(self tokenFor: '('), (self tokenFor: ')'),
|
|
330 |
((self tokenFor: 'default'), elementValue ) optional ,
|
|
331 |
(self tokenFor: ';')
|
|
332 |
!
|
|
333 |
|
|
334 |
annotationTypeBody
|
|
335 |
|
|
336 |
^ (self tokenFor: '{') ,
|
|
337 |
(annotationTypeElementDeclaration star),
|
|
338 |
(self tokenFor: '}')
|
|
339 |
!
|
|
340 |
|
|
341 |
annotationTypeDeclaration
|
|
342 |
|
|
343 |
^ interfaceModifiers , (self tokenFor: '@'),
|
|
344 |
(self tokenFor: 'interface') ,
|
|
345 |
identifier ,
|
|
346 |
annotationTypeBody
|
|
347 |
!
|
|
348 |
|
|
349 |
annotationTypeElementDeclaration
|
|
350 |
|
|
351 |
^ annotationMethodDeclaration
|
|
352 |
/ interfaceFieldDeclaration
|
|
353 |
/ normalClassDeclaration
|
|
354 |
/ enumDeclaration
|
|
355 |
/ annotationTypeDeclaration
|
|
356 |
/ (self tokenFor: ';')
|
|
357 |
!
|
|
358 |
|
|
359 |
annotations
|
|
360 |
|
|
361 |
^ annotation plus
|
|
362 |
! !
|
|
363 |
|
|
364 |
!PPJavaSyntax methodsFor:'grammar-classes'!
|
|
365 |
|
|
366 |
classBody
|
|
367 |
|
|
368 |
^ (self tokenFor: '{') , classBodyDeclaration star , (self tokenFor: '}')
|
|
369 |
!
|
|
370 |
|
|
371 |
classBodyDeclaration
|
|
372 |
|
|
373 |
^ (self tokenFor: ';')
|
|
374 |
/ ((self tokenFor: 'static') optional , block)
|
|
375 |
/ fieldDeclaration
|
|
376 |
/ methodDeclaration
|
|
377 |
/ classDeclaration
|
|
378 |
/ interfaceDeclaration
|
|
379 |
|
|
380 |
!
|
|
381 |
|
|
382 |
classDeclaration
|
|
383 |
|
|
384 |
^ normalClassDeclaration
|
|
385 |
/ enumDeclaration
|
|
386 |
!
|
|
387 |
|
|
388 |
classOrInterfaceDeclaration
|
|
389 |
|
|
390 |
^ classDeclaration
|
|
391 |
/ interfaceDeclaration
|
|
392 |
!
|
|
393 |
|
|
394 |
classOrInterfaceType
|
|
395 |
|
|
396 |
^ identifier ,
|
|
397 |
typeArguments optional,
|
|
398 |
((self tokenFor: '.'), identifier , typeArguments optional ) star
|
|
399 |
!
|
|
400 |
|
|
401 |
ellipsisParameterDecl
|
|
402 |
|
|
403 |
^ variableModifiers ,
|
|
404 |
type ,
|
|
405 |
('...' asParser token trim) ,
|
|
406 |
identifier
|
|
407 |
!
|
|
408 |
|
|
409 |
fieldDeclaration
|
|
410 |
|
|
411 |
^ fieldModifiers , type , variableDeclarators , (self tokenFor: ';')
|
|
412 |
!
|
|
413 |
|
|
414 |
fieldModifiers
|
|
415 |
|
|
416 |
^ ((self tokenFor: 'volatile') /
|
|
417 |
(self tokenFor: 'final') /
|
|
418 |
(self tokenFor: 'protected') /
|
|
419 |
(self tokenFor: 'private') /
|
|
420 |
(self tokenFor: 'public') /
|
|
421 |
(self tokenFor: 'static') /
|
|
422 |
(self tokenFor: 'transient') /
|
|
423 |
annotation) star
|
|
424 |
!
|
|
425 |
|
|
426 |
floatingPointType
|
|
427 |
^ (self tokenFor: 'float')
|
|
428 |
/ (self tokenFor: 'double').
|
|
429 |
|
|
430 |
!
|
|
431 |
|
|
432 |
formalParameter
|
|
433 |
|
|
434 |
^ variableModifiers ,
|
|
435 |
type ,
|
|
436 |
identifier ,
|
|
437 |
emptySquaredParenthesis star
|
|
438 |
!
|
|
439 |
|
|
440 |
formalParameterDecls
|
|
441 |
|
|
442 |
^ ellipsisParameterDecl
|
|
443 |
/ normalParametersWithElipsisDecls
|
|
444 |
/ normalParametersDecls
|
|
445 |
!
|
|
446 |
|
|
447 |
formalParameters
|
|
448 |
|
|
449 |
^ (self tokenFor: '(') ,
|
|
450 |
formalParameterDecls optional ,
|
|
451 |
(self tokenFor: ')')
|
|
452 |
!
|
|
453 |
|
|
454 |
normalClassDeclaration
|
|
455 |
|
|
456 |
^ classModifiers , (self tokenFor: 'class') , identifier ,
|
|
457 |
typeParameters optional,
|
|
458 |
jsuper optional,
|
|
459 |
interfaces optional ,
|
|
460 |
classBody
|
|
461 |
!
|
|
462 |
|
|
463 |
normalParameterDecl
|
|
464 |
|
|
465 |
^ variableModifiers ,
|
|
466 |
type ,
|
|
467 |
identifier ,
|
|
468 |
emptySquaredParenthesis star
|
|
469 |
!
|
|
470 |
|
|
471 |
normalParametersDecls
|
|
472 |
|
|
473 |
^ normalParameterDecl ,
|
|
474 |
((self tokenFor: ',') , normalParameterDecl) star
|
|
475 |
!
|
|
476 |
|
|
477 |
normalParametersWithElipsisDecls
|
|
478 |
|
|
479 |
^ (normalParameterDecl ,
|
|
480 |
(self tokenFor: ',')) plus ,
|
|
481 |
ellipsisParameterDecl
|
|
482 |
!
|
|
483 |
|
|
484 |
numericType
|
|
485 |
^ integralType / floatingPointType
|
|
486 |
!
|
|
487 |
|
|
488 |
primitiveType
|
|
489 |
|
|
490 |
^ (self tokenFor: 'boolean') / numericType
|
|
491 |
|
|
492 |
!
|
|
493 |
|
|
494 |
type
|
|
495 |
|
|
496 |
^ ( classOrInterfaceType
|
|
497 |
/ primitiveType
|
|
498 |
),
|
|
499 |
emptySquaredParenthesis star
|
|
500 |
!
|
|
501 |
|
|
502 |
typeArgument
|
|
503 |
|
|
504 |
^ type
|
|
505 |
/ wildcard
|
|
506 |
!
|
|
507 |
|
|
508 |
typeArguments
|
|
509 |
|
|
510 |
^ (self tokenFor: '<') ,
|
|
511 |
(typeArgument , ((self tokenFor: ','), typeArgument) star ) ,
|
|
512 |
(self tokenFor: '>')
|
|
513 |
!
|
|
514 |
|
|
515 |
variableDeclarator
|
|
516 |
|
|
517 |
^ identifier ,
|
|
518 |
((self tokenFor: '[') , (self tokenFor: ']')) star ,
|
|
519 |
((self tokenFor: '=') , variableInitializer) optional
|
|
520 |
!
|
|
521 |
|
|
522 |
variableDeclarators
|
|
523 |
|
|
524 |
^ variableDeclarator , ((self tokenFor: ','), variableDeclarator) star
|
|
525 |
!
|
|
526 |
|
|
527 |
wildcard
|
|
528 |
|
|
529 |
^ (self tokenFor: '?') ,
|
|
530 |
( ((self tokenFor: 'extends')/(self tokenFor: 'super')),
|
|
531 |
type
|
|
532 |
) optional
|
|
533 |
! !
|
|
534 |
|
|
535 |
!PPJavaSyntax methodsFor:'grammar-classes-enum'!
|
|
536 |
|
|
537 |
enumBody
|
|
538 |
|
|
539 |
^ (self tokenFor: '{') ,
|
|
540 |
enumConstants optional ,
|
|
541 |
(self tokenFor: ',') optional ,
|
|
542 |
enumBodyDeclarations optional ,
|
|
543 |
(self tokenFor: '}')
|
|
544 |
!
|
|
545 |
|
|
546 |
enumBodyDeclarations
|
|
547 |
|
|
548 |
^ (self tokenFor: ';') , classBodyDeclaration star
|
|
549 |
!
|
|
550 |
|
|
551 |
enumConstant
|
|
552 |
|
|
553 |
^ annotations optional , identifier , arguments optional , classBody optional
|
|
554 |
!
|
|
555 |
|
|
556 |
enumConstants
|
|
557 |
|
|
558 |
^ enumConstant , ((self tokenFor: ',') , enumConstant) star
|
|
559 |
!
|
|
560 |
|
|
561 |
enumDeclaration
|
|
562 |
|
|
563 |
^ classModifiers ,
|
|
564 |
(self tokenFor: 'enum'),
|
|
565 |
identifier ,
|
|
566 |
interfaces optional,
|
|
567 |
enumBody
|
|
568 |
! !
|
|
569 |
|
|
570 |
!PPJavaSyntax methodsFor:'grammar-classes-interface'!
|
|
571 |
|
|
572 |
interfaceBody
|
|
573 |
|
|
574 |
^ (self tokenFor: '{') , interfaceBodyDeclaration star , (self tokenFor: '}')
|
|
575 |
!
|
|
576 |
|
|
577 |
interfaceBodyDeclaration
|
|
578 |
|
|
579 |
^ interfaceFieldDeclaration
|
|
580 |
/ interfaceMethodDeclaration
|
|
581 |
/ interfaceDeclaration
|
|
582 |
/ classDeclaration
|
|
583 |
/ (self tokenFor: ';')
|
|
584 |
!
|
|
585 |
|
|
586 |
interfaceDeclaration
|
|
587 |
|
|
588 |
^normalInterfaceDeclaration
|
|
589 |
/ annotationTypeDeclaration
|
|
590 |
!
|
|
591 |
|
|
592 |
interfaceFieldDeclaration
|
|
593 |
|
|
594 |
^ fieldModifiers ,
|
|
595 |
type ,
|
|
596 |
variableDeclarators ,
|
|
597 |
(self tokenFor: ';')
|
|
598 |
!
|
|
599 |
|
|
600 |
interfaceMethodDeclaration
|
|
601 |
|
|
602 |
^ methodModifiers ,
|
|
603 |
typeParameters optional,
|
|
604 |
((self tokenFor: 'void') / type) ,
|
|
605 |
identifier ,
|
|
606 |
formalParameters ,
|
|
607 |
emptySquaredParenthesis star ,
|
|
608 |
throws optional ,
|
|
609 |
(self tokenFor: ';')
|
|
610 |
!
|
|
611 |
|
|
612 |
interfaceModifiers
|
|
613 |
|
|
614 |
^ ((self tokenFor: 'abstract')
|
|
615 |
/(self tokenFor: 'protected')
|
|
616 |
/(self tokenFor: 'private')
|
|
617 |
/(self tokenFor: 'public')
|
|
618 |
/(self tokenFor: 'static')
|
|
619 |
/(self tokenFor: 'strictfp')
|
|
620 |
/annotation) star
|
|
621 |
!
|
|
622 |
|
|
623 |
normalInterfaceDeclaration
|
|
624 |
|
|
625 |
^ interfaceModifiers ,
|
|
626 |
(self tokenFor: 'interface') ,
|
|
627 |
identifier ,
|
|
628 |
typeParameters optional ,
|
|
629 |
((self tokenFor: 'extends') , typeList ) optional ,
|
|
630 |
interfaceBody
|
|
631 |
! !
|
|
632 |
|
|
633 |
!PPJavaSyntax methodsFor:'grammar-classes-method'!
|
|
634 |
|
|
635 |
constructorDeclaration
|
|
636 |
|
|
637 |
^ constructorModifiers optional ,
|
|
638 |
typeParameters optional ,
|
|
639 |
identifier,
|
|
640 |
formalParameters ,
|
|
641 |
throws optional ,
|
|
642 |
(self tokenFor: '{' ) ,
|
|
643 |
explicitConstructorInvocation optional ,
|
|
644 |
blockStatement star ,
|
|
645 |
(self tokenFor: '}')
|
|
646 |
|
|
647 |
!
|
|
648 |
|
|
649 |
constructorModifiers
|
|
650 |
|
|
651 |
^ ((self tokenFor: 'protected')
|
|
652 |
/ (self tokenFor: 'private')
|
|
653 |
/ (self tokenFor: 'public')
|
|
654 |
/ annotation) plus
|
|
655 |
!
|
|
656 |
|
|
657 |
methodDeclaration
|
|
658 |
|
|
659 |
^ constructorDeclaration
|
|
660 |
/ methodNotConstructorDeclaration
|
|
661 |
!
|
|
662 |
|
|
663 |
methodModifierNotAnnotation
|
|
664 |
|
|
665 |
^ (self tokenFor: 'abstract')
|
|
666 |
/ (self tokenFor: 'final')
|
|
667 |
/ (self tokenFor: 'native')
|
|
668 |
/ (self tokenFor: 'protected')
|
|
669 |
/ (self tokenFor: 'private')
|
|
670 |
/ (self tokenFor: 'public')
|
|
671 |
/ (self tokenFor: 'static')
|
|
672 |
/ (self tokenFor: 'strictfp')
|
|
673 |
/ (self tokenFor: 'synchronized')
|
|
674 |
!
|
|
675 |
|
|
676 |
methodModifiers
|
|
677 |
|
|
678 |
^ ( methodModifierNotAnnotation
|
|
679 |
/ annotation) star
|
|
680 |
!
|
|
681 |
|
|
682 |
methodNotConstructorDeclaration
|
|
683 |
|
|
684 |
^ methodModifiers,
|
|
685 |
typeParameters optional,
|
|
686 |
((self tokenFor: 'void') / type),
|
|
687 |
identifier,
|
|
688 |
formalParameters ,
|
|
689 |
emptySquaredParenthesis star ,
|
|
690 |
throws optional,
|
|
691 |
(block / (self tokenFor: ';'))
|
|
692 |
!
|
|
693 |
|
|
694 |
parseMethod: aString
|
|
695 |
^ self parseMethod: aString onError: [ :msg :pos | self error: msg ]
|
|
696 |
!
|
|
697 |
|
|
698 |
parseMethod: aString onError: aBlock
|
|
699 |
^ startMethodDeclaration parse: aString onError: aBlock
|
|
700 |
!
|
|
701 |
|
|
702 |
qualifiedNameList
|
|
703 |
|
|
704 |
^ qualifiedName , ((self tokenFor: ',') , qualifiedName ) star
|
|
705 |
!
|
|
706 |
|
|
707 |
startMethodDeclaration
|
|
708 |
|
|
709 |
^ methodDeclaration end
|
|
710 |
!
|
|
711 |
|
|
712 |
throws
|
|
713 |
|
|
714 |
^ (self tokenFor: 'throws') , qualifiedNameList
|
|
715 |
! !
|
|
716 |
|
|
717 |
!PPJavaSyntax methodsFor:'grammar-expressions'!
|
|
718 |
|
|
719 |
additiveExpression
|
|
720 |
|
|
721 |
^ multiplicativeExpression ,
|
|
722 |
(( (self tokenFor: '+') / (self tokenFor: '-') ) , multiplicativeExpression ) star
|
|
723 |
!
|
|
724 |
|
|
725 |
andExpression
|
|
726 |
|
|
727 |
^ equalityExpression , ((self tokenFor: '&') , equalityExpression) star
|
|
728 |
!
|
|
729 |
|
|
730 |
assignmentOperator
|
|
731 |
|
|
732 |
^ (self tokenFor: '=')
|
|
733 |
/ (self tokenFor: '>>>=')
|
|
734 |
/ (self tokenFor: '>>=')
|
|
735 |
/ (self tokenFor: '<<=')
|
|
736 |
/ (self tokenFor: '&=')
|
|
737 |
/ (self tokenFor: '^=')
|
|
738 |
/ (self tokenFor: '|=')
|
|
739 |
/ (self tokenFor: '-=')
|
|
740 |
/ (self tokenFor: '+=')
|
|
741 |
/ (self tokenFor: '%=')
|
|
742 |
/ (self tokenFor: '/=')
|
|
743 |
/ (self tokenFor: '*=')
|
|
744 |
|
|
745 |
!
|
|
746 |
|
|
747 |
castExpression
|
|
748 |
|
|
749 |
^ ((self tokenFor: '('),
|
|
750 |
primitiveType ,
|
|
751 |
(self tokenFor: ')'), unaryExpression )
|
|
752 |
|
|
753 |
/ ((self tokenFor: '('),
|
|
754 |
type,
|
|
755 |
(self tokenFor: ')'), unaryExpressionNotPlusMinus )
|
|
756 |
!
|
|
757 |
|
|
758 |
conditionalAndExpression
|
|
759 |
|
|
760 |
^inclusiveOrExpression ,
|
|
761 |
((self tokenFor: '&&'), inclusiveOrExpression ) star
|
|
762 |
!
|
|
763 |
|
|
764 |
conditionalExpression
|
|
765 |
|
|
766 |
^conditionalOrExpression ,
|
|
767 |
((self tokenFor: '?'), expression , (self tokenFor: ':'), conditionalExpression ) optional
|
|
768 |
!
|
|
769 |
|
|
770 |
conditionalOrExpression
|
|
771 |
|
|
772 |
^conditionalAndExpression ,
|
|
773 |
((self tokenFor: '||'), conditionalAndExpression ) star
|
|
774 |
!
|
|
775 |
|
|
776 |
equalityExpression
|
|
777 |
|
|
778 |
^ instanceofExpression ,
|
|
779 |
(((self tokenFor: '!!=') / (self tokenFor: '==')) , instanceofExpression) star
|
|
780 |
!
|
|
781 |
|
|
782 |
exclusiveOrExpression
|
|
783 |
|
|
784 |
^ andExpression , ((self tokenFor: '^') , andExpression) star
|
|
785 |
!
|
|
786 |
|
|
787 |
expression
|
|
788 |
|
|
789 |
^ conditionalExpression ,
|
|
790 |
(assignmentOperator , expression) optional
|
|
791 |
!
|
|
792 |
|
|
793 |
identifierSuffix
|
|
794 |
|
|
795 |
^ ( emptySquaredParenthesis plus , (self tokenFor: '.'), (self tokenFor: 'class'))
|
|
796 |
/ (((self tokenFor: '[') , expression , (self tokenFor: ']')) plus)
|
|
797 |
/ arguments
|
|
798 |
/ ((self tokenFor: '.'),
|
|
799 |
( (self tokenFor: 'class')
|
|
800 |
/ (self tokenFor: 'this')
|
|
801 |
/ ((self tokenFor: 'super'), arguments)
|
|
802 |
/ (nonWildcardTypeArguments , identifier , arguments)))
|
|
803 |
/ innerCreator
|
|
804 |
!
|
|
805 |
|
|
806 |
inclusiveOrExpression
|
|
807 |
|
|
808 |
^ exclusiveOrExpression ,
|
|
809 |
((self tokenFor: '|') , exclusiveOrExpression) star
|
|
810 |
!
|
|
811 |
|
|
812 |
instanceofExpression
|
|
813 |
|
|
814 |
^ relationalExpression ,
|
|
815 |
((self tokenFor: 'instanceof') , type) optional
|
|
816 |
!
|
|
817 |
|
|
818 |
multiplicativeExpression
|
|
819 |
|
|
820 |
^ unaryExpression ,
|
|
821 |
(( (self tokenFor: '*')
|
|
822 |
/ (self tokenFor: '/')
|
|
823 |
/ (self tokenFor: '%') ) , unaryExpression ) star
|
|
824 |
!
|
|
825 |
|
|
826 |
parExpression
|
|
827 |
|
|
828 |
^ (self tokenFor: '(') , expression , (self tokenFor: ')')
|
|
829 |
!
|
|
830 |
|
|
831 |
primaryWithselectors
|
|
832 |
^ primary, selector star
|
|
833 |
!
|
|
834 |
|
|
835 |
relationalExpression
|
|
836 |
|
|
837 |
^ shiftExpression ,
|
|
838 |
(relationalOperator , shiftExpression) star
|
|
839 |
!
|
|
840 |
|
|
841 |
relationalOperator
|
|
842 |
|
|
843 |
^ (self tokenFor: '<=')
|
|
844 |
/ (self tokenFor: '>=')
|
|
845 |
/ (self tokenFor: '<')
|
|
846 |
/ (self tokenFor: '>')
|
|
847 |
!
|
|
848 |
|
|
849 |
selector
|
|
850 |
|
|
851 |
^ ( (self tokenFor: '.') , identifier, arguments optional )
|
|
852 |
/( (self tokenFor: '.'), (self tokenFor: 'this'))
|
|
853 |
/( (self tokenFor: '.'), (self tokenFor: 'super'), superSuffix)
|
|
854 |
/ innerCreator
|
|
855 |
/( (self tokenFor: '['), expression , (self tokenFor: ']'))
|
|
856 |
!
|
|
857 |
|
|
858 |
shiftExpression
|
|
859 |
|
|
860 |
^ additiveExpression,
|
|
861 |
(shiftOperator , additiveExpression) star
|
|
862 |
!
|
|
863 |
|
|
864 |
shiftOperator
|
|
865 |
self flag: 'maybe it should be detokenized, check the behavior with javac'.
|
|
866 |
|
|
867 |
^ (self tokenFor: '<<')
|
|
868 |
/ (self tokenFor: '>>>')
|
|
869 |
/ (self tokenFor: '>>')
|
|
870 |
!
|
|
871 |
|
|
872 |
statementWithoutTrailingSubstatement
|
|
873 |
|
|
874 |
^ (block/ emptyStatement/ expressionStatement/assertStatement/switchStatement/ doStatement/ breakStatement).
|
|
875 |
!
|
|
876 |
|
|
877 |
superSuffix
|
|
878 |
|
|
879 |
^ arguments
|
|
880 |
/ ( (self tokenFor: '.'), typeArguments optional ,
|
|
881 |
identifier ,
|
|
882 |
arguments optional)
|
|
883 |
!
|
|
884 |
|
|
885 |
unaryExpression
|
|
886 |
|
|
887 |
^ (((self tokenFor: '++')
|
|
888 |
/(self tokenFor: '+')
|
|
889 |
/(self tokenFor: '--')
|
|
890 |
/(self tokenFor: '-')),
|
|
891 |
unaryExpression)
|
|
892 |
/unaryExpressionNotPlusMinus
|
|
893 |
!
|
|
894 |
|
|
895 |
unaryNegationExpression
|
|
896 |
^ ((self tokenFor: '~') / (self tokenFor: '!!')), unaryExpression
|
|
897 |
!
|
|
898 |
|
|
899 |
unaryPostfixExpression
|
|
900 |
^ primaryWithselectors,
|
|
901 |
( (self tokenFor: '++')
|
|
902 |
/(self tokenFor: '--')) optional
|
|
903 |
! !
|
|
904 |
|
|
905 |
!PPJavaSyntax methodsFor:'grammar-modifiers'!
|
|
906 |
|
|
907 |
classModifierNotAnnotation
|
|
908 |
|
|
909 |
^ (self tokenFor: 'abstract')
|
|
910 |
/ (self tokenFor: 'final')
|
|
911 |
/ (self tokenFor: 'protected')
|
|
912 |
/ (self tokenFor: 'private')
|
|
913 |
/ (self tokenFor: 'public')
|
|
914 |
/ (self tokenFor: 'static')
|
|
915 |
/ (self tokenFor: 'strictfp')
|
|
916 |
|
|
917 |
!
|
|
918 |
|
|
919 |
classModifiers
|
|
920 |
|
|
921 |
^ (classModifierNotAnnotation
|
|
922 |
/annotation) star
|
|
923 |
!
|
|
924 |
|
|
925 |
variableModifiers
|
|
926 |
|
|
927 |
^((self tokenFor: 'final')
|
|
928 |
/ annotation) star
|
|
929 |
! !
|
|
930 |
|
|
931 |
!PPJavaSyntax methodsFor:'grammar-statements'!
|
|
932 |
|
|
933 |
assertStatement
|
|
934 |
|
|
935 |
^ (self tokenFor: 'assert') , expression ,
|
|
936 |
((self tokenFor: ':'), expression ) optional ,
|
|
937 |
(self tokenFor: ';')
|
|
938 |
!
|
|
939 |
|
|
940 |
basicForStatement
|
|
941 |
|
|
942 |
^ (self tokenFor: 'for') ,
|
|
943 |
(self tokenFor: '('),
|
|
944 |
forInit optional, (self tokenFor: ';'),
|
|
945 |
expression , (self tokenFor: ';'),
|
|
946 |
expressionList optional,
|
|
947 |
(self tokenFor: ')'),
|
|
948 |
statement
|
|
949 |
|
|
950 |
!
|
|
951 |
|
|
952 |
blockStatement
|
|
953 |
|
|
954 |
^ localVariableDeclarationStatement
|
|
955 |
/ classOrInterfaceDeclaration
|
|
956 |
/ statement
|
|
957 |
!
|
|
958 |
|
|
959 |
blockStatements
|
|
960 |
|
|
961 |
^ (blockStatement star).
|
|
962 |
!
|
|
963 |
|
|
964 |
breakStatement
|
|
965 |
|
|
966 |
^ (self tokenFor: 'break') , identifier optional , (self tokenFor: ';')
|
|
967 |
!
|
|
968 |
|
|
969 |
catchClause
|
|
970 |
|
|
971 |
^ (self tokenFor: 'catch') ,
|
|
972 |
(self tokenFor: '(') ,
|
|
973 |
formalParameter ,
|
|
974 |
(self tokenFor: ')'),
|
|
975 |
block
|
|
976 |
|
|
977 |
!
|
|
978 |
|
|
979 |
catches
|
|
980 |
|
|
981 |
^ catchClause plus
|
|
982 |
!
|
|
983 |
|
|
984 |
continueStatement
|
|
985 |
|
|
986 |
^ (self tokenFor: 'continue') , identifier optional , (self tokenFor: ';')
|
|
987 |
!
|
|
988 |
|
|
989 |
doStatement
|
|
990 |
|
|
991 |
^(self tokenFor: 'do') , statement ,
|
|
992 |
(self tokenFor: 'while') , parExpression ,
|
|
993 |
(self tokenFor: ';')
|
|
994 |
!
|
|
995 |
|
|
996 |
emptyStatement
|
|
997 |
|
|
998 |
^ (self tokenFor: ';')
|
|
999 |
!
|
|
1000 |
|
|
1001 |
enhancedForStatement
|
|
1002 |
|
|
1003 |
^ (self tokenFor: 'for') ,
|
|
1004 |
(self tokenFor: '(') ,
|
|
1005 |
variableModifiers ,
|
|
1006 |
type ,
|
|
1007 |
identifier ,
|
|
1008 |
(self tokenFor: ':'),
|
|
1009 |
expression,
|
|
1010 |
(self tokenFor: ')'),
|
|
1011 |
statement
|
|
1012 |
!
|
|
1013 |
|
|
1014 |
expressionList
|
|
1015 |
|
|
1016 |
^ expression , ((self tokenFor: ','), expression ) star
|
|
1017 |
!
|
|
1018 |
|
|
1019 |
expressionStatement
|
|
1020 |
|
|
1021 |
^ expression , (self tokenFor: ';')
|
|
1022 |
!
|
|
1023 |
|
|
1024 |
forInit
|
|
1025 |
|
|
1026 |
^ localVariableDeclaration
|
|
1027 |
/ expressionList
|
|
1028 |
!
|
|
1029 |
|
|
1030 |
forStatement
|
|
1031 |
|
|
1032 |
^ enhancedForStatement
|
|
1033 |
/ basicForStatement
|
|
1034 |
!
|
|
1035 |
|
|
1036 |
ifStatement
|
|
1037 |
|
|
1038 |
^(self tokenFor: 'if') , parExpression , statement ,
|
|
1039 |
((self tokenFor: 'else'), statement ) optional
|
|
1040 |
!
|
|
1041 |
|
|
1042 |
labeledStatement
|
|
1043 |
|
|
1044 |
^ identifier , (self tokenFor: ':') , statement
|
|
1045 |
!
|
|
1046 |
|
|
1047 |
localVariableDeclaration
|
|
1048 |
|
|
1049 |
^ variableModifiers , type , variableDeclarators
|
|
1050 |
!
|
|
1051 |
|
|
1052 |
localVariableDeclarationStatement
|
|
1053 |
|
|
1054 |
^ localVariableDeclaration , (self tokenFor: ';')
|
|
1055 |
!
|
|
1056 |
|
|
1057 |
returnStatement
|
|
1058 |
|
|
1059 |
^ (self tokenFor: 'return') , expression optional , (self tokenFor: ';')
|
|
1060 |
!
|
|
1061 |
|
|
1062 |
statement
|
|
1063 |
|
|
1064 |
^ statementWithoutTrailingSubstatement
|
|
1065 |
/ ifStatement
|
|
1066 |
/ forStatement
|
|
1067 |
/ whileStatement
|
|
1068 |
/ tryStatement
|
|
1069 |
/ synchronizedStatement
|
|
1070 |
/ returnStatement
|
|
1071 |
/ throwStatement
|
|
1072 |
/ continueStatement
|
|
1073 |
/ labeledStatement
|
|
1074 |
|
|
1075 |
!
|
|
1076 |
|
|
1077 |
switchBlockStatementGroup
|
|
1078 |
|
|
1079 |
^ switchLabel , blockStatement star
|
|
1080 |
!
|
|
1081 |
|
|
1082 |
switchLabel
|
|
1083 |
|
|
1084 |
^ ((self tokenFor: 'case') , expression , (self tokenFor: ':'))
|
|
1085 |
/ ((self tokenFor: 'default'), (self tokenFor: ':'))
|
|
1086 |
!
|
|
1087 |
|
|
1088 |
switchStatement
|
|
1089 |
|
|
1090 |
^(self tokenFor: 'switch') , parExpression ,
|
|
1091 |
(self tokenFor: '{'),
|
|
1092 |
switchBlockStatementGroup star ,
|
|
1093 |
(self tokenFor: '}')
|
|
1094 |
!
|
|
1095 |
|
|
1096 |
synchronizedStatement
|
|
1097 |
|
|
1098 |
^ (self tokenFor: 'synchronized') , parExpression , block
|
|
1099 |
!
|
|
1100 |
|
|
1101 |
throwStatement
|
|
1102 |
|
|
1103 |
^ (self tokenFor: 'throw') , expression , (self tokenFor: ';')
|
|
1104 |
!
|
|
1105 |
|
|
1106 |
tryStatement
|
|
1107 |
|
|
1108 |
^ (self tokenFor: 'try') , block ,
|
|
1109 |
( (catches , (self tokenFor: 'finally') , block)
|
|
1110 |
/ catches
|
|
1111 |
/ finally
|
|
1112 |
).
|
|
1113 |
!
|
|
1114 |
|
|
1115 |
whileStatement
|
|
1116 |
|
|
1117 |
^(self tokenFor: 'while') , parExpression , statement
|
|
1118 |
! !
|
|
1119 |
|