diff -r b5316ef15274 -r f6f68d32de73 compiler/PEGFsa.st --- a/compiler/PEGFsa.st Mon Aug 17 12:13:16 2015 +0100 +++ b/compiler/PEGFsa.st Mon Aug 24 15:34:14 2015 +0100 @@ -64,8 +64,8 @@ ^ startState ! -stateNamed: name - ^ states detect: [ :e | e name = name ] +stateNamed: stateName + ^ states detect: [ :e | e name = stateName ] ! states @@ -203,6 +203,10 @@ ^ false ! +hasNoRetvals + ^ self finalStates isEmpty +! + is: state furtherThan: anotherState ^ (distances at: state) >= (distances at: anotherState) @@ -294,6 +298,7 @@ topologicalOrder | collection | collection := OrderedCollection new. + self statesReachableFrom: startState openSet: collection. ^ collection ! ! @@ -321,7 +326,7 @@ ! hash - ^ states hash bitXor: (startState bitXor: name) + ^ states hash bitXor: (startState hash bitXor: name hash) ! isIsomorphicTo: anotherFsa @@ -360,7 +365,9 @@ ]. states := map values asIdentitySet. - startState := map at: startState. + startState isNil ifFalse: [ + startState := map at: startState. + ]. states do: [ :s | s transitions do: [:t | @@ -369,59 +376,6 @@ ] ! ! -!PEGFsa methodsFor:'gt'! - -gtGraphViewIn: composite - - composite roassal2 - title: 'Graph'; - initializeView: [ RTMondrian new ]; - painting: [ :view | - self viewGraphOn: view. - ]. -! - -gtStringViewIn: composite - - - composite text - title: 'Textual Representation'; - display: [ :fsa | fsa asString ] -! - -viewGraphOn: b - b shape circle size: 50. - b shape color: Color gray muchLighter muchLighter. - b shape withText: #gtName. - b nodes: (self nonFinalStates). - - b shape circle size: 50. - b shape color: Color gray muchLighter. - b shape withText: #gtName. - b nodes: (self finalStates). - - b shape arrowedLine. - b edges - connectToAll: [ :state | - state transitions select: [:t | (self isBackTransition:t) not] - thenCollect: #destination ] - labelled: [ :t | (self transitionFrom: t key to: t value) gtName ]. - - b shape arrowedLine. - b shape color: Color red. - b edges - connectToAll: [ :state | - state transitions select: [:t | (self isBackTransition: t) ] - thenCollect: #destination ] - labelled: [ :t | (self transitionFrom: t key to: t value) gtName ]. - - - b layout horizontalTree . - b layout layout horizontalGap: 30. - - ^ b -! ! - !PEGFsa methodsFor:'ids'! defaultName @@ -433,7 +387,7 @@ ! prefix - ^ nil + ^ 'scan' ! suffix @@ -496,10 +450,6 @@ fromState addTransition: transition ! -addTransitionFrom: fromState to: toState onPredicate: block - self addTransitionFrom: fromState to: toState onPredicate: block priority: 0 -! - addTransitionFrom: fromState to: toState onPredicate: block priority: priority | transition | transition := PEGFsaPredicateTransition new @@ -560,6 +510,12 @@ ^ PEGFsaMinimizator new minimize: self ! +removeFinals + self finalStates do: [ :s | + s final: false + ] +! + removePriorities self states select: [ :s| s hasPriority ] thenDo: [ :s | s priority: 0 @@ -775,6 +731,7 @@ checkConsistency self assert: (states includes: startState). + states do: [ :s | s transitions do: [ :t | self assert: (states includes: t destination). ] ].