--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/parsers/java/PPJavaTokenParser.st Tue Apr 21 14:57:16 2015 +0100
@@ -0,0 +1,64 @@
+"{ Package: 'stx:goodies/petitparser/parsers/java' }"
+
+"{ NameSpace: Smalltalk }"
+
+PPTokenParser subclass:#PPJavaTokenParser
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ category:'PetitJava-Core'
+!
+
+PPJavaTokenParser comment:''
+!
+
+!PPJavaTokenParser methodsFor:'parsing'!
+
+parseComments: anArray on: aStream
+
+ | start comments |
+ comments := anArray.
+ [
+ | peekTwice |
+ [ aStream atEnd not and: [ aStream peek isSeparator ] ]
+ whileTrue: [ aStream next ].
+ peekTwice := aStream peekTwice.
+ ((peekTwice first = $/) and:
+ [ (peekTwice second = $*) or: [peekTwice second = $/]])] whileTrue: [
+"
+ Transcript show: ('position ', aStream position asString, ' char ', aStream next asString); cr.
+"
+ aStream next.
+ start := aStream position.
+ (aStream next = $*)
+ ifTrue: [ aStream upToAll: '*/' ]
+ ifFalse: [
+ | position |
+ position := aStream position.
+ aStream upToAnyOf: CharacterSet crlf].
+ comments := comments copyWith: (start to: aStream position) ].
+ ^ comments
+!
+
+parseOn: aPPContext
+ | token comments memento |
+ memento := aPPContext remember.
+ comments := self
+ parseComments: #()
+ on: aPPContext.
+ token := super parseOn: aPPContext.
+ token isPetitFailure ifTrue: [
+ aPPContext restore: memento.
+ ^ token ].
+ comments := self
+ parseComments: comments
+ on: aPPContext.
+ ^ token comments: comments
+! !
+
+!PPJavaTokenParser methodsFor:'private'!
+
+defaultTokenClass
+ ^ PPJavaToken
+! !
+