parsers/java/PPJavaTokenParser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 21 Apr 2015 14:57:16 +0100
changeset 435 3bc08fb90133
child 436 e1c44b571db9
permissions -rw-r--r--
Initial commit of PetitJava Name: PetitJava-JanKurs.160 Author: JanKurs Time: 19-12-2014, 01:00:18.354 PM UUID: 1cb1b46d-8c68-4751-9720-f0dd742f3e16

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