749
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
|
3 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
4 |
SWING Research Group, Czech Technical University in Prague
|
|
5 |
|
|
6 |
Parts of the code written by Claus Gittinger are under following
|
|
7 |
license:
|
|
8 |
|
|
9 |
This software is furnished under a license and may be used
|
|
10 |
only in accordance with the terms of that license and with the
|
|
11 |
inclusion of the above copyright notice. This software may not
|
|
12 |
be provided or otherwise made available to, or used by, any
|
|
13 |
other person. No title to or ownership of the software is
|
|
14 |
hereby transferred.
|
|
15 |
|
|
16 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
|
|
17 |
|
|
18 |
Permission is hereby granted, free of charge, to any person
|
|
19 |
obtaining a copy of this software and associated documentation
|
|
20 |
files (the 'Software'), to deal in the Software without
|
|
21 |
restriction, including without limitation the rights to use,
|
|
22 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23 |
copies of the Software, and to permit persons to whom the
|
|
24 |
Software is furnished to do so, subject to the following
|
|
25 |
conditions:
|
|
26 |
|
|
27 |
The above copyright notice and this permission notice shall be
|
|
28 |
included in all copies or substantial portions of the Software.
|
|
29 |
|
|
30 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
31 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
32 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
33 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
34 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
35 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
36 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
37 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
38 |
|
|
39 |
[1] Code written at SWING Research Group contain a signature
|
|
40 |
of one of the above copright owners.
|
|
41 |
"
|
|
42 |
"{ Package: 'stx:libjava' }"
|
|
43 |
|
|
44 |
PPCompositeParser subclass:#JavaParser
|
|
45 |
instanceVariableNames:'classDecl'
|
|
46 |
classVariableNames:''
|
|
47 |
poolDictionaries:''
|
|
48 |
category:'Languages-Java-Parser'
|
|
49 |
!
|
|
50 |
|
|
51 |
PPParser subclass:#BlockParser
|
|
52 |
instanceVariableNames:'openBlockChar closeBlockChar innerBlockCount'
|
|
53 |
classVariableNames:''
|
|
54 |
poolDictionaries:''
|
|
55 |
privateIn:JavaParser
|
|
56 |
!
|
|
57 |
|
|
58 |
PPParser subclass:#CommentParser
|
|
59 |
instanceVariableNames:''
|
|
60 |
classVariableNames:''
|
|
61 |
poolDictionaries:''
|
|
62 |
privateIn:JavaParser
|
|
63 |
!
|
|
64 |
|
|
65 |
PPParser subclass:#MultilineCommentParser
|
|
66 |
instanceVariableNames:''
|
|
67 |
classVariableNames:''
|
|
68 |
poolDictionaries:''
|
|
69 |
privateIn:JavaParser
|
|
70 |
!
|
|
71 |
|
|
72 |
PPJavaNode subclass:#PPBlockNode
|
|
73 |
instanceVariableNames:''
|
|
74 |
classVariableNames:''
|
|
75 |
poolDictionaries:''
|
|
76 |
privateIn:JavaParser::MultilineCommentParser
|
|
77 |
!
|
|
78 |
|
|
79 |
PPParser subclass:#LineNumberParser
|
|
80 |
instanceVariableNames:''
|
|
81 |
classVariableNames:''
|
|
82 |
poolDictionaries:''
|
|
83 |
privateIn:JavaParser
|
|
84 |
!
|
|
85 |
|
|
86 |
ReadStream subclass:#LineNumberStream
|
|
87 |
instanceVariableNames:'eolPositions lastPosition previousWasCR'
|
|
88 |
classVariableNames:'CR LF'
|
|
89 |
poolDictionaries:''
|
|
90 |
privateIn:JavaParser
|
|
91 |
!
|
|
92 |
|
|
93 |
JavaParser::MultilineCommentParser subclass:#JavaDocParser
|
|
94 |
instanceVariableNames:''
|
|
95 |
classVariableNames:''
|
|
96 |
poolDictionaries:''
|
|
97 |
privateIn:JavaParser
|
|
98 |
!
|
|
99 |
|
|
100 |
PPParser subclass:#StatementParser
|
|
101 |
instanceVariableNames:'brackets'
|
|
102 |
classVariableNames:''
|
|
103 |
poolDictionaries:''
|
|
104 |
privateIn:JavaParser
|
|
105 |
!
|
|
106 |
|
|
107 |
!JavaParser class methodsFor:'documentation'!
|
|
108 |
|
|
109 |
copyright
|
|
110 |
"
|
|
111 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
|
112 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
113 |
SWING Research Group, Czech Technical University in Prague
|
|
114 |
|
|
115 |
Parts of the code written by Claus Gittinger are under following
|
|
116 |
license:
|
|
117 |
|
|
118 |
This software is furnished under a license and may be used
|
|
119 |
only in accordance with the terms of that license and with the
|
|
120 |
inclusion of the above copyright notice. This software may not
|
|
121 |
be provided or otherwise made available to, or used by, any
|
|
122 |
other person. No title to or ownership of the software is
|
|
123 |
hereby transferred.
|
|
124 |
|
|
125 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
|
|
126 |
|
|
127 |
Permission is hereby granted, free of charge, to any person
|
|
128 |
obtaining a copy of this software and associated documentation
|
|
129 |
files (the 'Software'), to deal in the Software without
|
|
130 |
restriction, including without limitation the rights to use,
|
|
131 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
132 |
copies of the Software, and to permit persons to whom the
|
|
133 |
Software is furnished to do so, subject to the following
|
|
134 |
conditions:
|
|
135 |
|
|
136 |
The above copyright notice and this permission notice shall be
|
|
137 |
included in all copies or substantial portions of the Software.
|
|
138 |
|
|
139 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
140 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
141 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
142 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
143 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
144 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
145 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
146 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
147 |
|
|
148 |
[1] Code written at SWING Research Group contain a signature
|
|
149 |
of one of the above copright owners.
|
|
150 |
|
|
151 |
"
|
|
152 |
! !
|
|
153 |
|
|
154 |
!JavaParser class methodsFor:'parsing'!
|
|
155 |
|
|
156 |
methodsIn: sourceCode
|
|
157 |
^ (self parse: sourceCode) methods.
|
|
158 |
|
|
159 |
"Created: / 08-01-2011 / 15:42:24 / Jan Kurs <kurs.jan@post.cz>"
|
|
160 |
!
|
|
161 |
|
|
162 |
parse: code
|
|
163 |
^ JavaParseResult from: (super parse: code).
|
|
164 |
|
|
165 |
"Created: / 08-01-2011 / 16:05:01 / Jan Kurs <kurs.jan@post.cz>"
|
|
166 |
"Modified: / 07-04-2011 / 22:07:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
167 |
! !
|
|
168 |
|
|
169 |
!JavaParser methodsFor:'accessing'!
|
|
170 |
|
|
171 |
lineNumber
|
|
172 |
^ LineNumberParser new.
|
|
173 |
|
|
174 |
"Created: / 29-12-2010 / 22:14:02 / Jan Kurs <kurs.jan@post.cz>"
|
|
175 |
"Modified: / 07-04-2011 / 22:05:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
176 |
!
|
|
177 |
|
|
178 |
start
|
|
179 |
^ self javaFile end.
|
|
180 |
! !
|
|
181 |
|
|
182 |
!JavaParser methodsFor:'grammar'!
|
|
183 |
|
|
184 |
annotation
|
|
185 |
^ $@ asParser, self identifier, self annotationBlock optional
|
|
186 |
!
|
|
187 |
|
|
188 |
annotationBlock
|
|
189 |
^ BlockParser new
|
|
190 |
openBlockChar: $(;
|
|
191 |
closeBlockChar: $);
|
|
192 |
yourself;
|
|
193 |
trim
|
|
194 |
|
|
195 |
"Modified: / 07-04-2011 / 21:46:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
196 |
!
|
|
197 |
|
|
198 |
argument
|
|
199 |
^ (self finalKW optional, self type, self threeDotsKW optional, self typeIdentifier) trim
|
|
200 |
!
|
|
201 |
|
|
202 |
argumentList
|
|
203 |
^ (self argument separatedBy: ($, asParser trim) ==> [:token | nil]) ==> [: token | token select: [:each | each notNil ]].
|
|
204 |
!
|
|
205 |
|
|
206 |
block
|
|
207 |
^ BlockParser new trim
|
|
208 |
|
|
209 |
"Modified: / 07-04-2011 / 21:46:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
210 |
!
|
|
211 |
|
|
212 |
classBody
|
|
213 |
^ (${ asParser trim, self classContents star, $} asParser trim)
|
|
214 |
foldLeft: [:a :contents :b | contents select: [:each | each notNil ]]
|
|
215 |
|
|
216 |
"Modified: / 30-12-2010 / 11:21:09 / Jan Kurs <kurs.jan@post.cz>"
|
|
217 |
!
|
|
218 |
|
|
219 |
classContents
|
|
220 |
^ self methodDecl trim /
|
|
221 |
self constructor trim /
|
|
222 |
self staticInitializer trim /
|
|
223 |
self comment /
|
|
224 |
"Since classes may be nested recursively we have to use this syntax - without self"
|
|
225 |
classDecl trim /
|
|
226 |
"TODO JK: This will cause problems - sooner or later"
|
|
227 |
self statement.
|
|
228 |
|
|
229 |
"Modified: / 29-12-2010 / 22:12:11 / Jan Kurs <kurs.jan@post.cz>"
|
|
230 |
!
|
|
231 |
|
|
232 |
classDecl
|
|
233 |
^ self classModifiers,
|
|
234 |
(self classKW / self interfaceKW),
|
|
235 |
(self identifier, self genericBlock optional) flatten,
|
|
236 |
(self extends optional),
|
|
237 |
(self implements optional),
|
|
238 |
self classBody
|
|
239 |
!
|
|
240 |
|
|
241 |
classModifiers
|
|
242 |
^ ('public' asParser /
|
|
243 |
'private' asParser /
|
|
244 |
'static' asParser /
|
|
245 |
'abstract' asParser /
|
|
246 |
'final' asParser
|
|
247 |
|
|
248 |
) trim star
|
|
249 |
!
|
|
250 |
|
|
251 |
comment
|
|
252 |
^ (self oneLineComment / self multilineComment) ==> [ :token | nil ]
|
|
253 |
|
|
254 |
"Modified: / 30-12-2010 / 11:20:56 / Jan Kurs <kurs.jan@post.cz>"
|
|
255 |
!
|
|
256 |
|
|
257 |
constructor
|
|
258 |
^ (
|
|
259 |
self lineNumber,
|
|
260 |
self javadoc optional,
|
|
261 |
self methodModifiers optional,
|
|
262 |
self identifier,
|
|
263 |
self methodArguments,
|
|
264 |
self methodBody optional) trim
|
|
265 |
foldLeft: [:startLine :javadoc :modifiers :name :arguments :body |
|
|
266 |
JavaMethodDeclarationNode new
|
|
267 |
startLine: startLine;
|
|
268 |
javadoc: javadoc;
|
|
269 |
modifiers: modifiers;
|
|
270 |
retval: nil;
|
|
271 |
methodName: name;
|
|
272 |
arguments: arguments
|
|
273 |
].
|
|
274 |
|
|
275 |
"Modified: / 08-01-2011 / 16:27:25 / Jan Kurs <kurs.jan@post.cz>"
|
|
276 |
!
|
|
277 |
|
|
278 |
extends
|
|
279 |
^ self extendsKW, self type
|
|
280 |
!
|
|
281 |
|
|
282 |
fileHeader
|
|
283 |
^ self comment star, self package optional, self imports optional, self comment star
|
|
284 |
!
|
|
285 |
|
|
286 |
fullIdentifier
|
|
287 |
^ (self identifier separatedBy: $. asParser) trim flatten
|
|
288 |
|
|
289 |
!
|
|
290 |
|
|
291 |
genericBlock
|
|
292 |
^ BlockParser new
|
|
293 |
openBlockChar: $<;
|
|
294 |
closeBlockChar: $>;
|
|
295 |
yourself;
|
|
296 |
trim
|
|
297 |
|
|
298 |
"Modified: / 07-04-2011 / 21:46:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
299 |
!
|
|
300 |
|
|
301 |
identifier
|
|
302 |
^ (#letter asParser, #word asParser star) trim flatten
|
|
303 |
|
|
304 |
!
|
|
305 |
|
|
306 |
implements
|
|
307 |
^ self implementsKW, (self type separatedBy: $, asParser trim)
|
|
308 |
!
|
|
309 |
|
|
310 |
import
|
|
311 |
^ self comment star, 'import' asParser trim, self statement.
|
|
312 |
!
|
|
313 |
|
|
314 |
imports
|
|
315 |
^ self import star
|
|
316 |
!
|
|
317 |
|
|
318 |
javaFile
|
|
319 |
^ (self fileHeader, classDecl trim) foldLeft: [:header :c | c ]
|
|
320 |
!
|
|
321 |
|
|
322 |
javadoc
|
|
323 |
^ JavaDocParser new trim
|
|
324 |
|
|
325 |
"Modified: / 07-04-2011 / 22:06:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
326 |
!
|
|
327 |
|
|
328 |
methodArguments
|
|
329 |
^ ($( asParser, self argumentList optional, $) asParser) trim foldLeft: [:a :args :b | args].
|
|
330 |
!
|
|
331 |
|
|
332 |
methodBody
|
|
333 |
^ self block.
|
|
334 |
!
|
|
335 |
|
|
336 |
methodDecl
|
|
337 |
^ (
|
|
338 |
self lineNumber,
|
|
339 |
self javadoc optional,
|
|
340 |
self methodModifiers optional,
|
|
341 |
self genericBlock optional,
|
|
342 |
self methodRetval,
|
|
343 |
self identifier,
|
|
344 |
self methodArguments,
|
|
345 |
self throwsStatement optional,
|
|
346 |
self methodBody optional) trim
|
|
347 |
foldLeft: [:startLine :javadoc :modifiers :generic :retval :name :arguments :throws :body |
|
|
348 |
JavaMethodDeclarationNode new
|
|
349 |
javadoc: javadoc;
|
|
350 |
modifiers: modifiers;
|
|
351 |
retval: retval;
|
|
352 |
methodName: name;
|
|
353 |
arguments: arguments;
|
|
354 |
startLine: startLine
|
|
355 |
].
|
|
356 |
|
|
357 |
"Modified: / 29-12-2010 / 22:47:53 / Jan Kurs <kurs.jan@post.cz>"
|
|
358 |
!
|
|
359 |
|
|
360 |
methodModifiers
|
|
361 |
^ ('public' asParser /
|
|
362 |
'static' asParser /
|
|
363 |
'abstract' asParser /
|
|
364 |
'private' asParser /
|
|
365 |
'protected' asParser /
|
|
366 |
'native' asParser /
|
|
367 |
'final' asParser /
|
|
368 |
'synchronized' asParser /
|
|
369 |
self annotation
|
|
370 |
) trim star
|
|
371 |
!
|
|
372 |
|
|
373 |
methodRetval
|
|
374 |
^ self type
|
|
375 |
!
|
|
376 |
|
|
377 |
multilineComment
|
|
378 |
^ MultilineCommentParser new trim
|
|
379 |
|
|
380 |
"Modified: / 07-04-2011 / 22:03:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
381 |
!
|
|
382 |
|
|
383 |
nameToken
|
|
384 |
^ #word asParser
|
|
385 |
|
|
386 |
!
|
|
387 |
|
|
388 |
oneLineComment
|
|
389 |
^ CommentParser new trim
|
|
390 |
|
|
391 |
"Modified: / 07-04-2011 / 22:03:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
392 |
!
|
|
393 |
|
|
394 |
otherClassContent
|
|
395 |
^ self statement.
|
|
396 |
!
|
|
397 |
|
|
398 |
package
|
|
399 |
^ 'package' asParser trim, self statement.
|
|
400 |
!
|
|
401 |
|
|
402 |
primitiveType
|
|
403 |
^ ( 'int' asParser /
|
|
404 |
'byte' asParser /
|
|
405 |
'boolean' asParser /
|
|
406 |
'float' asParser /
|
|
407 |
'double' asParser /
|
|
408 |
'char' asParser
|
|
409 |
) trim
|
|
410 |
!
|
|
411 |
|
|
412 |
reference
|
|
413 |
^ self fullIdentifier
|
|
414 |
!
|
|
415 |
|
|
416 |
statement
|
|
417 |
^ StatementParser new trim ==> [: token | nil ].
|
|
418 |
|
|
419 |
"Modified: / 30-12-2010 / 11:20:45 / Jan Kurs <kurs.jan@post.cz>"
|
|
420 |
"Modified: / 07-04-2011 / 22:05:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
421 |
!
|
|
422 |
|
|
423 |
staticInitializer
|
|
424 |
^ 'static' asParser trim, BlockParser new ==> [:token | nil]
|
|
425 |
|
|
426 |
"Modified: / 07-04-2011 / 21:47:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
427 |
!
|
|
428 |
|
|
429 |
throwsStatement
|
|
430 |
^ self throwsKW, (self identifier separatedBy: $, asParser trim)
|
|
431 |
!
|
|
432 |
|
|
433 |
type
|
|
434 |
^
|
|
435 |
(
|
|
436 |
('void' asParser / self primitiveType / self reference) trim,
|
|
437 |
self genericBlock optional,
|
|
438 |
'[]' asParser optional
|
|
439 |
)
|
|
440 |
flatten
|
|
441 |
!
|
|
442 |
|
|
443 |
typeIdentifier
|
|
444 |
^ self identifier
|
|
445 |
! !
|
|
446 |
|
|
447 |
!JavaParser methodsFor:'keywords'!
|
|
448 |
|
|
449 |
classKW
|
|
450 |
^ 'class' asParser trim
|
|
451 |
!
|
|
452 |
|
|
453 |
extendsKW
|
|
454 |
^ 'extends' asParser trim
|
|
455 |
!
|
|
456 |
|
|
457 |
finalKW
|
|
458 |
^ 'final' asParser trim
|
|
459 |
!
|
|
460 |
|
|
461 |
implementsKW
|
|
462 |
^ 'implements' asParser trim
|
|
463 |
!
|
|
464 |
|
|
465 |
interfaceKW
|
|
466 |
^ 'interface' asParser trim
|
|
467 |
!
|
|
468 |
|
|
469 |
threeDotsKW
|
|
470 |
^ '...' asParser trim
|
|
471 |
!
|
|
472 |
|
|
473 |
throwsKW
|
|
474 |
^ 'throws' asParser trim
|
|
475 |
!
|
|
476 |
|
|
477 |
voidKW
|
|
478 |
^ 'void' asParser trim
|
|
479 |
! !
|
|
480 |
|
|
481 |
!JavaParser methodsFor:'parsing'!
|
|
482 |
|
|
483 |
parseOn: ppStream
|
|
484 |
^ super parseOn: (LineNumberStream on: ppStream collection).
|
|
485 |
"/ ^ super parseOn: ppStream.
|
|
486 |
|
|
487 |
"Created: / 29-12-2010 / 22:35:30 / Jan Kurs <kurs.jan@post.cz>"
|
|
488 |
"Modified: / 30-12-2010 / 10:01:20 / Jan Kurs <kurs.jan@post.cz>"
|
|
489 |
"Modified: / 07-04-2011 / 22:06:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
490 |
! !
|
|
491 |
|
|
492 |
!JavaParser::BlockParser class methodsFor:'documentation'!
|
|
493 |
|
|
494 |
version_SVN
|
|
495 |
^ '$Id$'
|
|
496 |
! !
|
|
497 |
|
|
498 |
!JavaParser::BlockParser methodsFor:'accessing'!
|
|
499 |
|
|
500 |
closeBlockChar: anObject
|
|
501 |
closeBlockChar := anObject
|
|
502 |
!
|
|
503 |
|
|
504 |
openBlockChar: anObject
|
|
505 |
openBlockChar := anObject
|
|
506 |
! !
|
|
507 |
|
|
508 |
!JavaParser::BlockParser methodsFor:'initialization'!
|
|
509 |
|
|
510 |
initialize
|
|
511 |
innerBlockCount := 0.
|
|
512 |
openBlockChar := ${.
|
|
513 |
closeBlockChar := $}.
|
|
514 |
! !
|
|
515 |
|
|
516 |
!JavaParser::BlockParser methodsFor:'parsing'!
|
|
517 |
|
|
518 |
decInnerBlockCount
|
|
519 |
innerBlockCount := innerBlockCount - 1.
|
|
520 |
!
|
|
521 |
|
|
522 |
incInnerBlockCount
|
|
523 |
innerBlockCount := innerBlockCount + 1.
|
|
524 |
!
|
|
525 |
|
|
526 |
parseLoop: aStream
|
|
527 |
| literal |
|
|
528 |
|
|
529 |
aStream atEnd ifFalse:
|
|
530 |
[
|
|
531 |
literal := aStream uncheckedPeek.
|
|
532 |
literal = openBlockChar ifTrue: [ self incInnerBlockCount].
|
|
533 |
literal = closeBlockChar ifTrue: [ self decInnerBlockCount].
|
|
534 |
aStream next.
|
|
535 |
^true
|
|
536 |
].
|
|
537 |
^false
|
|
538 |
!
|
|
539 |
|
|
540 |
parseOn: aStream
|
|
541 |
| literal |
|
|
542 |
" self halt.
|
|
543 |
"
|
|
544 |
(self parseLoop: aStream) ifFalse:
|
|
545 |
[
|
|
546 |
^ PPFailure message: 'unexpected end of input' at: aStream position
|
|
547 |
].
|
|
548 |
|
|
549 |
self zeroBlockCount ifTrue: [ ^ PPFailure message: ('expected ' copyWith: openBlockChar) at: aStream position ].
|
|
550 |
|
|
551 |
[self zeroBlockCount] whileFalse: [
|
|
552 |
(self parseLoop: aStream) ifFalse:
|
|
553 |
[
|
|
554 |
^ PPFailure message: 'unexpected end of input' at: aStream position
|
|
555 |
]
|
|
556 |
].
|
|
557 |
^ nil.
|
|
558 |
!
|
|
559 |
|
|
560 |
zeroBlockCount
|
|
561 |
^ innerBlockCount = 0
|
|
562 |
! !
|
|
563 |
|
|
564 |
!JavaParser::CommentParser class methodsFor:'documentation'!
|
|
565 |
|
|
566 |
version_SVN
|
|
567 |
^ '$Id$'
|
|
568 |
! !
|
|
569 |
|
|
570 |
!JavaParser::CommentParser methodsFor:'parsing'!
|
|
571 |
|
|
572 |
parseOn: aStream
|
|
573 |
| literal wasStar |
|
|
574 |
wasStar := false.
|
|
575 |
|
|
576 |
(aStream next: 2) = '//' ifFalse: [
|
|
577 |
^ PPFailure message: '// expected' at: aStream position.
|
|
578 |
].
|
|
579 |
|
|
580 |
[literal := aStream next.
|
|
581 |
literal = (Character cr) or: [ aStream atEnd ]
|
|
582 |
] whileFalse.
|
|
583 |
|
|
584 |
^ nil.
|
|
585 |
! !
|
|
586 |
|
|
587 |
!JavaParser::MultilineCommentParser class methodsFor:'documentation'!
|
|
588 |
|
|
589 |
version_SVN
|
|
590 |
^ '$Id$'
|
|
591 |
! !
|
|
592 |
|
|
593 |
!JavaParser::MultilineCommentParser methodsFor:'parsing'!
|
|
594 |
|
|
595 |
checkStart: aStream
|
|
596 |
^ (aStream next: self startSequence size) = self startSequence
|
|
597 |
!
|
|
598 |
|
|
599 |
parseOn: aStream
|
|
600 |
| literal wasStar line |
|
|
601 |
wasStar := false.
|
|
602 |
line := aStream lineNumber.
|
|
603 |
|
|
604 |
(self checkStart: aStream) ifFalse: [
|
|
605 |
^ PPFailure message: self startSequence, ' expected' at: aStream position.
|
|
606 |
].
|
|
607 |
|
|
608 |
[literal := aStream next.
|
|
609 |
aStream atEnd ifTrue:
|
|
610 |
[
|
|
611 |
^ PPFailure message: 'unexpected end of input' at: aStream position.
|
|
612 |
].
|
|
613 |
|
|
614 |
wasStar and: [literal = $/]
|
|
615 |
] whileFalse: [
|
|
616 |
wasStar := literal = $*
|
|
617 |
].
|
|
618 |
^ PPBlockNode new
|
|
619 |
startLine: line
|
|
620 |
|
|
621 |
"Modified: / 29-12-2010 / 21:29:26 / Jan Kurs <kurs.jan@post.cz>"
|
|
622 |
!
|
|
623 |
|
|
624 |
startSequence
|
|
625 |
^ '/*'
|
|
626 |
! !
|
|
627 |
|
|
628 |
!JavaParser::LineNumberParser class methodsFor:'documentation'!
|
|
629 |
|
|
630 |
version_SVN
|
|
631 |
^ '$Id$'
|
|
632 |
! !
|
|
633 |
|
|
634 |
!JavaParser::LineNumberParser methodsFor:'parsing'!
|
|
635 |
|
|
636 |
parseOn: aStream
|
|
637 |
^ aStream lineNumber.
|
|
638 |
|
|
639 |
"Created: / 29-12-2010 / 22:13:22 / Jan Kurs <kurs.jan@post.cz>"
|
|
640 |
! !
|
|
641 |
|
|
642 |
!JavaParser::LineNumberStream class methodsFor:'documentation'!
|
|
643 |
|
|
644 |
version_SVN
|
|
645 |
^ '$Id$'
|
|
646 |
! !
|
|
647 |
|
|
648 |
!JavaParser::LineNumberStream class methodsFor:'initialization'!
|
|
649 |
|
|
650 |
initialize
|
|
651 |
CR := Character cr.
|
|
652 |
Smalltalk isSmalltalkX ifTrue:[
|
|
653 |
CR := Character return.
|
|
654 |
].
|
|
655 |
LF := Character nl.
|
|
656 |
|
|
657 |
"Created: / 29-12-2010 / 23:11:17 / Jan Kurs <kurs.jan@post.cz>"
|
|
658 |
! !
|
|
659 |
|
|
660 |
!JavaParser::LineNumberStream methodsFor:'accessing'!
|
|
661 |
|
|
662 |
lineNumber
|
|
663 |
| index start stop pos |
|
|
664 |
pos := position.
|
|
665 |
pos >= eolPositions last ifTrue: [^eolPositions size].
|
|
666 |
start := 1.
|
|
667 |
stop := eolPositions size.
|
|
668 |
[start + 1 < stop] whileTrue:
|
|
669 |
[index := (start + stop) // 2.
|
|
670 |
(eolPositions at: index) <= pos
|
|
671 |
ifTrue: [start := index]
|
|
672 |
ifFalse: [stop := index]].
|
|
673 |
^start
|
|
674 |
|
|
675 |
"Created: / 30-12-2010 / 10:23:27 / Jan Kurs <kurs.jan@post.cz>"
|
|
676 |
!
|
|
677 |
|
|
678 |
next
|
|
679 |
| character |
|
|
680 |
character := super next.
|
|
681 |
position - 1 == lastPosition
|
|
682 |
ifTrue:
|
|
683 |
[
|
|
684 |
"/ self halt.
|
|
685 |
lastPosition := lastPosition + 1.
|
|
686 |
character == CR
|
|
687 |
ifTrue:
|
|
688 |
[eolPositions add: position.
|
|
689 |
previousWasCR := true]
|
|
690 |
ifFalse:
|
|
691 |
[(previousWasCR not and: [character == LF])
|
|
692 |
ifTrue: [eolPositions add: position].
|
|
693 |
previousWasCR := false]].
|
|
694 |
^character
|
|
695 |
|
|
696 |
"Modified: / 30-12-2010 / 10:55:09 / Jan Kurs <kurs.jan@post.cz>"
|
|
697 |
!
|
|
698 |
|
|
699 |
next: anInteger
|
|
700 |
"Override for positioning purposes"
|
|
701 |
|
|
702 |
| answer num |
|
|
703 |
num:= readLimit - position min: anInteger.
|
|
704 |
answer := OrderedCollection new: num.
|
|
705 |
|
|
706 |
num timesRepeat: [
|
|
707 |
answer add: self next.
|
|
708 |
].
|
|
709 |
^ answer asString.
|
|
710 |
|
|
711 |
|
|
712 |
"/ | answer endPosition |
|
|
713 |
"/ endPosition := position + anInteger min: readLimit.
|
|
714 |
"/ answer := collection copyFrom: position + 1 to: endPosition.
|
|
715 |
"/ position := endPosition.
|
|
716 |
"/ ^ answer
|
|
717 |
|
|
718 |
"Modified: / 30-12-2010 / 10:57:37 / Jan Kurs <kurs.jan@post.cz>"
|
|
719 |
!
|
|
720 |
|
|
721 |
uncheckedPeek
|
|
722 |
"An unchecked version of peek that throws an error if we try to peek over the end of the stream, even faster than #peek."
|
|
723 |
|
|
724 |
^ collection at: position + 1
|
|
725 |
! !
|
|
726 |
|
|
727 |
!JavaParser::LineNumberStream methodsFor:'converting'!
|
|
728 |
|
|
729 |
asPetitStream
|
|
730 |
^ self
|
|
731 |
! !
|
|
732 |
|
|
733 |
!JavaParser::LineNumberStream methodsFor:'initialization'!
|
|
734 |
|
|
735 |
initialize
|
|
736 |
eolPositions := OrderedCollection with: ZeroPosition.
|
|
737 |
lastPosition := ZeroPosition.
|
|
738 |
previousWasCR := false
|
|
739 |
|
|
740 |
"Created: / 30-12-2010 / 10:22:41 / Jan Kurs <kurs.jan@post.cz>"
|
|
741 |
!
|
|
742 |
|
|
743 |
on: aCollection
|
|
744 |
super on: aCollection.
|
|
745 |
eolPositions := OrderedCollection with: ZeroPosition.
|
|
746 |
lastPosition := ZeroPosition.
|
|
747 |
previousWasCR := false
|
|
748 |
|
|
749 |
"Created: / 30-12-2010 / 10:26:17 / Jan Kurs <kurs.jan@post.cz>"
|
|
750 |
! !
|
|
751 |
|
|
752 |
!JavaParser::LineNumberStream methodsFor:'printing'!
|
|
753 |
|
|
754 |
printOn: aStream
|
|
755 |
collection isString
|
|
756 |
ifFalse: [ ^ super printOn: aStream ].
|
|
757 |
aStream
|
|
758 |
nextPutAll: (collection copyFrom: 1 to: position);
|
|
759 |
nextPutAll: '·';
|
|
760 |
nextPutAll: (collection copyFrom: position + 1 to: readLimit)
|
|
761 |
! !
|
|
762 |
|
|
763 |
!JavaParser::JavaDocParser class methodsFor:'documentation'!
|
|
764 |
|
|
765 |
version_SVN
|
|
766 |
^ '$Id$'
|
|
767 |
! !
|
|
768 |
|
|
769 |
!JavaParser::JavaDocParser methodsFor:'parsing'!
|
|
770 |
|
|
771 |
parseOn: aStream
|
|
772 |
| blockNode |
|
|
773 |
blockNode := super parseOn: aStream.
|
|
774 |
|
|
775 |
blockNode isPetitFailure ifTrue: [
|
|
776 |
^ blockNode.
|
|
777 |
].
|
|
778 |
|
|
779 |
^ JavadocDeclarationNode new
|
|
780 |
startLine: blockNode startLine.
|
|
781 |
|
|
782 |
"Created: / 29-12-2010 / 21:22:42 / Jan Kurs <kurs.jan@post.cz>"
|
|
783 |
!
|
|
784 |
|
|
785 |
startSequence
|
|
786 |
^ '/**'
|
|
787 |
! !
|
|
788 |
|
|
789 |
!JavaParser::StatementParser class methodsFor:'documentation'!
|
|
790 |
|
|
791 |
version_SVN
|
|
792 |
^ '$Id$'
|
|
793 |
! !
|
|
794 |
|
|
795 |
!JavaParser::StatementParser methodsFor:'parsing'!
|
|
796 |
|
|
797 |
parseOn: aStream
|
|
798 |
| literal |
|
|
799 |
[literal = $;] whileFalse: [
|
|
800 |
aStream atEnd ifFalse:
|
|
801 |
[
|
|
802 |
literal := aStream uncheckedPeek.
|
|
803 |
aStream next.
|
|
804 |
]
|
|
805 |
ifTrue:
|
|
806 |
[
|
|
807 |
^ PPFailure message: 'unexpected end of input' at: aStream position.
|
|
808 |
].
|
|
809 |
|
|
810 |
"TODO JK: This will cause problems - sooner or later"
|
|
811 |
(literal = $}) ifTrue: [ ^
|
|
812 |
PPFailure message: 'cannot parser $}' at: aStream position.
|
|
813 |
].
|
|
814 |
].
|
|
815 |
^ nil
|
|
816 |
! !
|
|
817 |
|
|
818 |
!JavaParser class methodsFor:'documentation'!
|
|
819 |
|
|
820 |
version_SVN
|
|
821 |
^ '$Id$'
|
|
822 |
! !
|
|
823 |
|
|
824 |
JavaParser::LineNumberStream initialize! |