diff -r 0bbbcf5da2d4 -r 1825151d6455 analyzer/extensions.st --- a/analyzer/extensions.st Sat Oct 04 21:26:15 2014 +0100 +++ b/analyzer/extensions.st Sun Oct 05 00:29:07 2014 +0100 @@ -41,7 +41,7 @@ copies := OrderedCollection new. parsers do: [ :each | | result | - result := each + result := each copyInContext: aDictionary seen: aSeenDictionary. result isCollection @@ -70,7 +70,7 @@ !PPNotParser methodsFor:'*petitanalyzer-private'! firstSets: aFirstDictionary into: aSet - + ! ! !PPNotParser methodsFor:'*petitanalyzer-testing'! @@ -101,7 +101,7 @@ allNamedParsersDo: aBlock "Iterate over all the named parse nodes of the receiver." - self allParsersDo: [ :each | + self allParsersDo: [ :each | each name notNil ifTrue: [ aBlock value: each ] ] ! ! @@ -116,8 +116,8 @@ copyInContext: aDictionary seen: aSeenDictionary | copy | - aSeenDictionary - at: self + aSeenDictionary + at: self ifPresent: [ :value | ^ value ]. copy := aSeenDictionary at: self @@ -133,7 +133,7 @@ cycleSet "Answer a set of all nodes that are within one or more cycles of left-recursion. This is generally not a problem if at least one of the nodes is memoized, but it might make the grammar very inefficient and should be avoided if possible." - + | cycles | cycles := IdentitySet new. self cycleSet: OrderedCollection new firstSets: self firstSets into: cycles. @@ -155,7 +155,7 @@ | index | self isTerminal - ifTrue: [ ^ self ]. + ifTrue: [ ^ self ]. (index := aStack indexOf: self) > 0 ifTrue: [ ^ aSet addAll: (aStack copyFrom: index to: aStack size) ]. aStack addLast: self. @@ -168,7 +168,7 @@ firstSet "Answer the first-set of the receiver. Note, this implementation is inefficient when called on different receivers of the same grammar, instead use #firstSets to calculate the first-sets at once." - + ^ self firstSets at: self ! ! @@ -176,7 +176,7 @@ firstSets "Answer a dictionary with all the parsers reachable from the receiver as key and their first-set as value. The first-set of a parser is the list of terminal parsers that begin the parser derivable from that parser." - + | firstSets | firstSets := IdentityDictionary new. self allParsersDo: [ :each | @@ -215,7 +215,7 @@ followSets "Answer a dictionary with all the parsers reachable from the receiver as key and their follow-set as value. The follow-set of a parser is the list of terminal parsers that can appear immediately to the right of that parser." - + | current previous continue firstSets followSets | current := previous := 0. firstSets := self firstSets. @@ -223,7 +223,7 @@ self allParsersDo: [ :each | followSets at: each put: IdentitySet new ]. (followSets at: self) add: PPSentinel instance. [ followSets keysAndValuesDo: [ :parser :follow | - parser + parser followSets: followSets firstSets: firstSets into: follow ]. @@ -240,7 +240,7 @@ followSets: aFollowDictionary firstSets: aFirstDictionary into: aSet "PRIVATE: Try to add additional elements to the follow-set aSet of the receiver, use the incomplete aFollowDictionary and the complete aFirstDictionary." - + self children do: [ :parser | (aFollowDictionary at: parser) addAll: aSet ] ! ! @@ -267,7 +267,7 @@ innerChildrenDo: aBlock seen: aSet "Iterate over the inner children of the receiver." - + self children do: [ :each | (aSet includes: each) ifTrue: [ ^ self ]. @@ -289,7 +289,7 @@ isNullable "Answer true if the receiver is a nullable parser, e.g. it can successfully parse nothing." - + ^ false ! ! @@ -335,9 +335,9 @@ currentIndex := parserIndex - 1. [ currentDictionary := aDictionary copy. currentSeen := aSet copy. - parserList size < currentIndex or: [ + parserList size < currentIndex or: [ parsers := parserList copyFrom: parserIndex to: currentIndex. - (currentDictionary at: parser ifAbsentPut: [ parsers ]) = parsers and: [ + (currentDictionary at: parser ifAbsentPut: [ parsers ]) = parsers and: [ (self matchList: matchList index: matchIndex + 1 @@ -345,7 +345,7 @@ index: currentIndex + 1 inContext: currentDictionary seen: currentSeen) - ifTrue: [ + ifTrue: [ currentDictionary keysAndValuesDo: [ :key :value | aDictionary at: key put: value ]. ^ true ]. false ] ] ] whileFalse: [ currentIndex := currentIndex + 1 ]. @@ -386,7 +386,7 @@ namedChildrenDo: aBlock seen: aSet "Iterate over the named children of the receiver." - + self children do: [ :each | (aSet includes: each) ifTrue: [ ^ self ]. @@ -448,7 +448,7 @@ followSets: aFollowDictionary firstSets: aFirstDictionary into: aSet | firstSet | super followSets: aFollowDictionary firstSets: aFirstDictionary into: aSet. - + firstSet := aFirstDictionary at: self. self children do: [:p | (aFollowDictionary at: p) addAll: (firstSet reject: [:each | each isNullable]) ] ! ! @@ -500,13 +500,13 @@ index = parsers size ifTrue: [ followSet addAll: aSet ] ifFalse: [ - (self class withAll: (parsers + (self class withAll: (parsers copyFrom: index + 1 to: parsers size)) firstSets: aFirstDictionary into: (firstSet := IdentitySet new). (firstSet anySatisfy: [ :each | each isNullable ]) ifTrue: [ followSet addAll: aSet ]. - followSet addAll: (firstSet + followSet addAll: (firstSet reject: [ :each | each isNullable ]) ] ] ! !