compiler/PPCScanner.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 28 Jul 2015 07:16:10 +0100
changeset 507 c5773c25eedc
parent 502 1e45d3c96ec5
child 516 3b81c9e53352
permissions -rw-r--r--
Workaround for stc bug.

"{ Package: 'stx:goodies/petitparser/compiler' }"

"{ NameSpace: Smalltalk }"

Object subclass:#PPCScanner
	instanceVariableNames:'matches stream maxPriority currentChar'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Scanner'
!

!PPCScanner methodsFor:'accessing'!

stream
    ^ stream
!

stream: anObject
    stream := anObject
! !

!PPCScanner methodsFor:'as yet unclassified'!

recordMatch: match 
 	^ self recordMatch: match priority: 0
!

recordMatch: match priority: currentPriority
    (maxPriority < currentPriority) ifTrue: [ 
        matches := IdentityDictionary new.
        maxPriority := currentPriority.
    ].
         
    (maxPriority == currentPriority) ifTrue: [ 
     	matches at: match put: stream position
 	].
!

return
    ^ self returnPriority: SmallInteger minVal.
!

returnPriority: priority
    (maxPriority < priority) ifTrue: [ 
        ^ IdentityDictionary new
    ].
    ^ matches keysAndValuesRemove: [ :key :value | key class == PEGFsaFailure ]
! !

!PPCScanner methodsFor:'initialization'!

initialize
    super initialize.
    matches := IdentityDictionary new.	
    maxPriority := SmallInteger minVal.
! !

!PPCScanner methodsFor:'scanning'!

consumeConditionally: character
    (stream peek == character) ifTrue: [ stream next. ^ true ] ifFalse: [ ^ false ]
!

next
    stream next
!

peek
    ^ currentChar
!

peekBetween: start and: stop
    (currentChar == nil) ifTrue: [ ^ false ].
    ^ start <= currentChar codePoint and: [ currentChar codePoint <= stop ]
!

step
    currentChar := stream next
! !