435
|
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 methodsFor:'parsing'!
|
|
13 |
|
|
14 |
parseComments: anArray on: aStream
|
|
15 |
|
|
16 |
| start comments |
|
|
17 |
comments := anArray.
|
|
18 |
[
|
|
19 |
| peekTwice |
|
|
20 |
[ aStream atEnd not and: [ aStream peek isSeparator ] ]
|
|
21 |
whileTrue: [ aStream next ].
|
|
22 |
peekTwice := aStream peekTwice.
|
|
23 |
((peekTwice first = $/) and:
|
|
24 |
[ (peekTwice second = $*) or: [peekTwice second = $/]])] whileTrue: [
|
|
25 |
"
|
|
26 |
Transcript show: ('position ', aStream position asString, ' char ', aStream next asString); cr.
|
|
27 |
"
|
|
28 |
aStream next.
|
|
29 |
start := aStream position.
|
|
30 |
(aStream next = $*)
|
|
31 |
ifTrue: [ aStream upToAll: '*/' ]
|
|
32 |
ifFalse: [
|
|
33 |
| position |
|
|
34 |
position := aStream position.
|
|
35 |
aStream upToAnyOf: CharacterSet crlf].
|
|
36 |
comments := comments copyWith: (start to: aStream position) ].
|
|
37 |
^ comments
|
|
38 |
!
|
|
39 |
|
|
40 |
parseOn: aPPContext
|
|
41 |
| token comments memento |
|
|
42 |
memento := aPPContext remember.
|
|
43 |
comments := self
|
|
44 |
parseComments: #()
|
|
45 |
on: aPPContext.
|
|
46 |
token := super parseOn: aPPContext.
|
|
47 |
token isPetitFailure ifTrue: [
|
|
48 |
aPPContext restore: memento.
|
|
49 |
^ token ].
|
|
50 |
comments := self
|
|
51 |
parseComments: comments
|
|
52 |
on: aPPContext.
|
|
53 |
^ token comments: comments
|
|
54 |
! !
|
|
55 |
|
|
56 |
!PPJavaTokenParser methodsFor:'private'!
|
|
57 |
|
|
58 |
defaultTokenClass
|
|
59 |
^ PPJavaToken
|
|
60 |
! !
|
|
61 |
|