PPContext.st
changeset 427 a7f5e6de19d2
parent 421 7e08b31e0dae
child 650 4c6ed0a28d18
equal deleted inserted replaced
426:2a65c972b937 427:a7f5e6de19d2
     1 "{ Package: 'stx:goodies/petitparser' }"
     1 "{ Package: 'stx:goodies/petitparser' }"
     2 
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
     3 Object subclass:#PPContext
     5 Object subclass:#PPContext
     4 	instanceVariableNames:'stream root properties globals'
     6 	instanceVariableNames:'stream root properties globals furthestFailure'
     5 	classVariableNames:''
     7 	classVariableNames:''
     6 	poolDictionaries:''
     8 	poolDictionaries:''
     7 	category:'PetitParser-Core'
     9 	category:'PetitParser-Core'
     8 !
    10 !
     9 
    11 
    15 		root: aPPParser;
    17 		root: aPPParser;
    16 		stream: aStream asPetitStream;
    18 		stream: aStream asPetitStream;
    17 		yourself
    19 		yourself
    18 ! !
    20 ! !
    19 
    21 
    20 
       
    21 
       
    22 !PPContext methodsFor:'accessing-globals'!
    22 !PPContext methodsFor:'accessing-globals'!
    23 
    23 
    24 globalAt: aKey
    24 globalAt: aKey
    25 	"Answer the global property value associated with aKey."
    25 	"Answer the global property value associated with aKey."
    26 	
    26 	
   138 !PPContext methodsFor:'failures'!
   138 !PPContext methodsFor:'failures'!
   139 
   139 
   140 furthestFailure
   140 furthestFailure
   141 	" the furthest failure encountered while parsing the input stream "
   141 	" the furthest failure encountered while parsing the input stream "
   142 	
   142 	
   143 	^ self globalAt: #furthestFailure ifAbsent: [ nil ]
   143 	"^ self globalAt: #furthestFailure ifAbsent: [ nil ]"
       
   144 	"performance optimization:"
       
   145 	^ furthestFailure
   144 !
   146 !
   145 
   147 
   146 noteFailure: aPPFailure
   148 noteFailure: aPPFailure
   147 	"record the furthest failure encountered while parsing the input stream "
   149 	"record the furthest failure encountered while parsing the input stream "
   148 
   150 
   149 	| furthestFailure |
       
   150 	furthestFailure := self furthestFailure.
       
   151 	( furthestFailure isNil or: [ aPPFailure position > furthestFailure position ]) 
   151 	( furthestFailure isNil or: [ aPPFailure position > furthestFailure position ]) 
   152 		ifTrue: [ self globalAt: #furthestFailure put: aPPFailure ].
   152 		ifTrue: [ furthestFailure := aPPFailure ].
   153 ! !
   153 ! !
   154 
   154 
   155 !PPContext methodsFor:'initialization'!
   155 !PPContext methodsFor:'initialization'!
   156 
   156 
   157 initialize
   157 initialize
   207 	].
   207 	].
   208 
   208 
   209 	aPPContextMemento keysAndValuesDo: [ :key :value |
   209 	aPPContextMemento keysAndValuesDo: [ :key :value |
   210 		properties at: key put: value
   210 		properties at: key put: value
   211 	]
   211 	]
       
   212 ! !
       
   213 
       
   214 !PPContext methodsFor:'printing'!
       
   215 
       
   216 printOn: aStream
       
   217 	super printOn: aStream.
       
   218 	aStream nextPut: $:.
       
   219 	aStream nextPut: $ .
       
   220 	stream printOn: aStream
   212 ! !
   221 ! !
   213 
   222 
   214 !PPContext methodsFor:'stream mimicry'!
   223 !PPContext methodsFor:'stream mimicry'!
   215 
   224 
   216 atEnd
   225 atEnd