#REFACTORING by exept draft
authorClaus Gittinger <cg@exept.de>
Sun, 08 Sep 2019 15:50:00 +0200
changeset 645 2f598ee17a2d
parent 644 0bf7cd45f7eb
child 646 6e97d8145481
#REFACTORING by exept class: PPParser changed: #map: #parse:onError:
PPParser.st
--- a/PPParser.st	Sun Sep 08 15:49:47 2019 +0200
+++ b/PPParser.st	Sun Sep 08 15:50:00 2019 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "{ Package: 'stx:goodies/petitparser' }"
 
 "{ NameSpace: Smalltalk }"
@@ -296,11 +298,11 @@
 !
 
 map: aBlock
-	"Answer a new parser that works on the receiving sequence an passes in each element as a block argument."
-	
-	^ aBlock numArgs = 1
-		ifTrue: [ self ==> aBlock ]
-		ifFalse: [ self error: aBlock numArgs asString , ' arguments expected.' ]
+        "Answer a new parser that works on the receiving sequence an passes in each element as a block argument."
+        
+        ^ aBlock argumentCount == 1
+                ifTrue: [ self ==> aBlock ]
+                ifFalse: [ self error: aBlock numArgs asString , ' arguments expected.' ]
 !
 
 trim: aParser
@@ -500,17 +502,16 @@
 !
 
 parse: anObject onError: aBlock
-	"Parse anObject with the receiving parser and answer the parse-result or answer the result of evaluating aBlock. Depending on the number of arguments of the block it is simply evaluated, evaluated with the failure object, or evaluated with the error message and position."
-	
-	| result |
-	result := self parse: anObject.
-	result isPetitFailure
-		ifFalse: [ ^ result ].
-	aBlock numArgs = 0
-		ifTrue: [ ^ aBlock value ].
-	aBlock numArgs = 1
-		ifTrue: [ ^ aBlock value: result ].
-	^ aBlock value: result message value: result position
+        "Parse anObject with the receiving parser and answer the parse-result or answer the result of evaluating aBlock. Depending on the number of arguments of the block it is simply evaluated, evaluated with the failure object, or evaluated with the error message and position."
+        
+        | result numArgs |
+
+        result := self parse: anObject.
+        result isPetitFailure ifFalse: [ ^ result ].
+        numArgs := aBlock argumentCount.
+        numArgs == 0 ifTrue: [ ^ aBlock value ].
+        numArgs == 1 ifTrue: [ ^ aBlock value: result ].
+        ^ aBlock value:(result message) value:(result position)
 !
 
 parseOn: aStream