--- a/analyzer/extensions.st Fri Oct 03 02:33:08 2014 +0100
+++ b/analyzer/extensions.st Fri Oct 03 02:45:16 2014 +0100
@@ -27,9 +27,9 @@
!PPLimitedRepeatingParser methodsFor:'*petitanalyzer-transforming'!
-replace:aParser with:anotherParser
- super replace:aParser with:anotherParser.
- limit == aParser ifTrue:[limit := anotherParser].
+replace: aParser with: anotherParser
+ super replace: aParser with: anotherParser.
+ limit == aParser ifTrue: [ limit := anotherParser ]
! !
!PPListParser methodsFor:'*petitanalyzer-matching'!
@@ -67,6 +67,18 @@
^ (super match: aParser inContext: aDictionary seen: anIdentitySet) and: [ self literal = aParser literal and: [ self message = aParser message ] ]
! !
+!PPNotParser methodsFor:'*petitanalyzer-private'!
+
+firstSets: aFirstDictionary into: aSet
+
+! !
+
+!PPNotParser methodsFor:'*petitanalyzer-testing'!
+
+isFirstSetTerminal
+ ^ true
+! !
+
!PPOptionalParser methodsFor:'*petitanalyzer-testing'!
isNullable
@@ -200,7 +212,7 @@
| firstSets |
firstSets := IdentityDictionary new.
self allParsersDo: [ :each |
- firstSets at: each put: (each isTerminal
+ firstSets at: each put: (each isFirstSetTerminal
ifTrue: [ IdentitySet with: each ]
ifFalse: [ IdentitySet new ]).
each isNullable
@@ -299,6 +311,14 @@
!PPParser methodsFor:'*petitanalyzer-testing'!
+isFirstSetTerminal
+ "Answer true if the receiver is a terminal or leaf parser, that means it does not delegate to any other parser."
+
+ ^ self children isEmpty
+! !
+
+!PPParser methodsFor:'*petitanalyzer-testing'!
+
isNullable
"Answer true if the receiver is a nullable parser, e.g. it can successfully parse nothing."
@@ -455,6 +475,16 @@
^ (super match: aParser inContext: aDictionary seen: anIdentitySet) and: [ self size = aParser size ]
! !
+!PPRepeatingParser methodsFor:'*petitanalyzer-private'!
+
+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]) ]
+! !
+
!PPRepeatingParser methodsFor:'*petitanalyzer-testing'!
isNullable