--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/PPCScanner.st Fri Jul 24 15:06:54 2015 +0100
@@ -0,0 +1,80 @@
+"{ 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
+! !
+