|
1 "{ Package: 'stx:goodies/petitparser/parsers/java' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPTokenParser subclass:#PPJavaTokenParser |
|
6 instanceVariableNames:'' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitJava-Core' |
|
10 ! |
|
11 |
|
12 PPJavaTokenParser comment:'' |
|
13 ! |
|
14 |
|
15 !PPJavaTokenParser methodsFor:'parsing'! |
|
16 |
|
17 parseComments: anArray on: aStream |
|
18 |
|
19 | start comments | |
|
20 comments := anArray. |
|
21 [ |
|
22 | peekTwice | |
|
23 [ aStream atEnd not and: [ aStream peek isSeparator ] ] |
|
24 whileTrue: [ aStream next ]. |
|
25 peekTwice := aStream peekTwice. |
|
26 ((peekTwice first = $/) and: |
|
27 [ (peekTwice second = $*) or: [peekTwice second = $/]])] whileTrue: [ |
|
28 " |
|
29 Transcript show: ('position ', aStream position asString, ' char ', aStream next asString); cr. |
|
30 " |
|
31 aStream next. |
|
32 start := aStream position. |
|
33 (aStream next = $*) |
|
34 ifTrue: [ aStream upToAll: '*/' ] |
|
35 ifFalse: [ |
|
36 | position | |
|
37 position := aStream position. |
|
38 aStream upToAnyOf: CharacterSet crlf]. |
|
39 comments := comments copyWith: (start to: aStream position) ]. |
|
40 ^ comments |
|
41 ! |
|
42 |
|
43 parseOn: aPPContext |
|
44 | token comments memento | |
|
45 memento := aPPContext remember. |
|
46 comments := self |
|
47 parseComments: #() |
|
48 on: aPPContext. |
|
49 token := super parseOn: aPPContext. |
|
50 token isPetitFailure ifTrue: [ |
|
51 aPPContext restore: memento. |
|
52 ^ token ]. |
|
53 comments := self |
|
54 parseComments: comments |
|
55 on: aPPContext. |
|
56 ^ token comments: comments |
|
57 ! ! |
|
58 |
|
59 !PPJavaTokenParser methodsFor:'private'! |
|
60 |
|
61 defaultTokenClass |
|
62 ^ PPJavaToken |
|
63 ! ! |
|
64 |