# HG changeset patch # User Claus Gittinger # Date 1567950600 -7200 # Node ID 2f598ee17a2d24132079d3f5996cd88528ccae4f # Parent 0bf7cd45f7ebb7ab284e9a9cbf1f2f4218891800 #REFACTORING by exept class: PPParser changed: #map: #parse:onError: diff -r 0bf7cd45f7eb -r 2f598ee17a2d 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