parsers/java/PPJavaTokenParser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 21 Apr 2015 17:06:24 +0100
changeset 436 e1c44b571db9
parent 435 3bc08fb90133
child 439 1a7d51c92b9a
permissions -rw-r--r--
Fixes for Smalltalk/X * Do not use Character class>>#cr /#lf as semantics of this method differ in Smalltalk/X and Squeak. Use Character class>>#codePoint: instead * Do not use Squeakism Dictionary >> #keysSortedSafely - there is no need for this as all keys are strings.

"{ Package: 'stx:goodies/petitparser/parsers/java' }"

"{ NameSpace: Smalltalk }"

PPTokenParser subclass:#PPJavaTokenParser
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'PetitJava-Core'
!

!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
! !