compiler/PEGFsaChoiceDeterminizator.st
changeset 515 b5316ef15274
equal deleted inserted replaced
502:1e45d3c96ec5 515:b5316ef15274
       
     1 "{ Package: 'stx:goodies/petitparser/compiler' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 PEGFsaAbstractDeterminizator subclass:#PEGFsaChoiceDeterminizator
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'PetitCompiler-FSA'
       
    10 !
       
    11 
       
    12 !PEGFsaChoiceDeterminizator methodsFor:'as yet unclassified'!
       
    13 
       
    14 determinize
       
    15     super determinize.
       
    16 
       
    17     fsa removeLowPriorityTransitions.
       
    18     fsa removeUnreachableStates.
       
    19     fsa removePriorities.
       
    20 !
       
    21 
       
    22 joinInfo: info with: anotherInfo into: newInfo
       
    23     "Merging into the failure"
       
    24     (info isFsaFailure and: [anotherInfo isFsaFailure not]) ifTrue: [  
       
    25         newInfo final: anotherInfo isFinal.
       
    26         newInfo priority: anotherInfo priority.
       
    27         newInfo failure: false.
       
    28         ^ self
       
    29     ].
       
    30     
       
    31     (anotherInfo isFsaFailure and: [info isFsaFailure not]) ifTrue: [  
       
    32         newInfo final: info isFinal.
       
    33         newInfo priority: (anotherInfo priority max: info priority).
       
    34         newInfo failure: false.
       
    35         ^ self
       
    36     ].
       
    37     
       
    38     (info hasEqualPriorityTo: anotherInfo) ifTrue: [ 
       
    39         newInfo final: (info isFinal or: [ anotherInfo isFinal ]).
       
    40         newInfo failure: (info isFsaFailure or: [anotherInfo isFailure]).
       
    41         newInfo priority: info priority.	
       
    42         ^ self
       
    43     ].
       
    44     
       
    45     (info hasHigherPriorityThan: anotherInfo) ifTrue: [ 
       
    46  		newInfo priority: info priority.	
       
    47         newInfo failure: info isFsaFailure.
       
    48         newInfo final: info isFinal.
       
    49         ^ self
       
    50     ].
       
    51 
       
    52     newInfo priority: anotherInfo priority.
       
    53     newInfo failure: anotherInfo isFsaFailure.
       
    54     newInfo final: anotherInfo isFinal.
       
    55 !
       
    56 
       
    57 joinState: state with: anotherState
       
    58     self assert: state isMultivalue not.
       
    59     self assert: anotherState isMultivalue not.
       
    60 
       
    61     ^ super joinState: state with: anotherState
       
    62 !
       
    63 
       
    64 joinTransitions: state with: anotherState into: newState
       
    65     self assert: newState isMultivalue not.
       
    66     
       
    67     newState transitions addAll: (state transitions collect: #copy).
       
    68     newState transitions addAll: (anotherState transitions collect: #copy).
       
    69     newState mergeTransitions.
       
    70 ! !
       
    71 
       
    72 !PEGFsaChoiceDeterminizator methodsFor:'joining'!
       
    73 
       
    74 joinRetval: state with: anotherState into: newState
       
    75     "Different retvals cannot merge their info"
       
    76     self assert: (state hasDifferentRetvalThan: anotherState) not. 
       
    77     self assert: state retval == anotherState retval.
       
    78 ! !
       
    79