Hey, you can achieve your goal by extending the petit parser API as follows;
PPParser>>nullParser
" transforms whatever result to null "
^ self ==> [:e | NullResult instance ]
PPParser>>ignoreNulls
" removes NullResults from result "
^ self ==> [:e | e isCollection
ifTrue: [ e reject: [ :item | item isNullResult ]
ifFalse: [ e ] ]
Cheers,
Jan
On Mon, Jun 22, 2015 at 1:27 PM Peter Uhnák <i.uhnak(a)gmail.com> wrote:
The problem is, that in syntax there are often many
symbols that are no
longer needed once the string is parsed so I want to get rid of them.
For example imagine a string representation of an JSON array:
'[ 1, 2, 3 ]'
Once the string is parsed, the brackets are no longer needed so I can get
rid of them with a block
MyJsonParser>>array
^ ($[ asParser, arrayElements, $] asParser) ==> [ :nodes | nodes
second ]
This way the result of the array will not contain those $[ $] symbols
because I am not interested in them after the parsing.
So, I would prefer to explicitly state that I am not interested in certain
parser after it has done its job.
MyJsonParser>>array
^ $[ asParser ignore, arrayElements, $] asParser ignore
(or the other alternative mentioned in the first post)
Is what I am trying to accomplish clearer?
Peter
_______________________________________________
Moose-dev mailing list
Moose-dev(a)iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev