If you'd write the describe the items in the list, the code would
become simpler:
item := $" asParser , $" asParser negate star flatten , $" asParser
==> #second.
items := (item separatedBy: $, asParser trim)
withoutSeparators.
list := ${ asParser , items , $} asParser
==> #second.
#withoutSeparators also simplifies the code further. I just added that
to the latest version.
Lukas
On 25 February 2012 13:44, Sean P. DeNigris <sean(a)clipperadams.com> wrote:
What do you think of this PetitParser example? Is
there a better way to do
this?
Parse a string like '{"login", "bash"}' (an Applescript list)
into a
collection of items (i.e. #("login" "bash))...
| delimiter item contents listParser result listClose |
delimiter := ', ' asParser.
listClose := $} asParser.
item := (delimiter / listClose) negate plus flatten.
contents := (item separatedBy: delimiter) ==> [ :nodes | nodes reject: [ :n
| n = ', ' ] ].
listParser := ${ asParser, contents optional, listClose ==> #second.
result := listParser parse: returnString.
^ result isNil
ifTrue: [ OrderedCollection new ]
ifFalse: [ result collect: [ :e | self processAtom: e ] ].
Thanks.
Sean
--
View this message in context:
http://forum.world.st/PetitParser-Example-tp4420008p4420008.html
Sent from the Moose mailing list archive at
Nabble.com.
_______________________________________________
Moose-dev mailing list
Moose-dev(a)iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
--
Lukas Renggli
www.lukas-renggli.ch