--- a/PPParser.st Mon Apr 13 14:19:55 2015 +0100
+++ b/PPParser.st Mon Apr 13 22:00:44 2015 +0100
@@ -1,5 +1,7 @@
"{ Package: 'stx:goodies/petitparser' }"
+"{ NameSpace: Smalltalk }"
+
Object subclass:#PPParser
instanceVariableNames:'properties'
classVariableNames:''
@@ -18,15 +20,6 @@
^ self basicNew initialize
! !
-
-
-
-
-
-
-
-
-
!PPParser methodsFor:'accessing'!
children
@@ -111,7 +104,8 @@
result := self parseOn: context.
"Return the furthest failure, it gives better results than the last failure"
- result isPetitFailure ifTrue: [ ^ context furthestFailure ].
+ (result isPetitFailure and: [ context furthestFailure notNil])
+ ifTrue: [ ^ context furthestFailure ].
^ result
!
@@ -312,6 +306,10 @@
"
^ PPLimitedChoiceParser with: self with: aParser
+!
+
+if: aBlock
+ ^ PPConditionalParser on: self block: aBlock
! !
!PPParser methodsFor:'operators-convenience'!
@@ -384,10 +382,34 @@
^ self trim: #blank asParser
!
+trimLeft
+ "Answer a new parser that consumes spaces before the receiving parser."
+
+ ^ self trimSpacesLeft
+!
+
+trimRight
+ "Answer a new parser that consumes spaces after the receiving parser."
+
+ ^ self trimSpacesRight
+!
+
trimSpaces
"Answer a new parser that consumes spaces before and after the receiving parser."
^ self trim: #space asParser
+!
+
+trimSpacesLeft
+ "Answer a new parser that consumes spaces before the receiving parser."
+
+ ^ (#space asParser star, self) ==> #second
+!
+
+trimSpacesRight
+ "Answer a new parser that consumes spaces after the receiving parser."
+
+ ^ (self, #space asParser star) ==> #first
! !
!PPParser methodsFor:'operators-repeating'!