Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Administrator
5777 posts
|
I'm flopping around trying to flatten an array. I can't seem to get it...
input := '... Optical Drive Type: CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-R, DVD-R DL, DVD-RW, DVD+R, DVD+R DL, DVD+RW Optical Media Type:...' lineBreak := #cr asParser / #lf asParser. driveTypeHeader := 'Optical Drive Type: ' asParser skipUntil. driveType := (', ' asParser / lineBreak) negate plus flatten. additionalDriveType := ', ' asParser, driveType ==> [ :nodes | nodes second ]. driveTypeList := (driveType, additionalDriveType star). parser := driveTypeHeader, driveTypeList, lineBreak ==> [ :nodes | nodes second ]. parser parse: input. Returns: "#('CD-ROM' #('CD-R' 'CD-RW' 'DVD-ROM' 'DVD-R' 'DVD-R DL' 'DVD-RW' 'DVD+R' 'DVD+R DL' 'DVD+RW'))" Makes sense so far, but if I change the above to: ... driveTypeList := (driveType, additionalDriveType star) flatten. ... Returns: "'CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-R, DVD-R DL, DVD-RW, DVD+R, DVD+R DL, DVD+RW'" Instead of combining the arrays, it made one big string!? How do I do this? Thanks. Sean
Cheers,
Sean |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
5207 posts
|
driveType separatedBy: ', ' asParse
(and see the implementation of #separatedBy: if this is not exactly what you are looking for) Lukas On 11 November 2010 23:35, Sean P. DeNigris <[hidden email]> wrote: > > I'm flopping around trying to flatten an array. I can't seem to get it... > > input := '... > Optical Drive Type: CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-R, DVD-R DL, > DVD-RW, DVD+R, DVD+R DL, DVD+RW > Optical Media Type:...' > > lineBreak := #cr asParser / #lf asParser. > driveTypeHeader := 'Optical Drive Type: ' asParser skipUntil. > driveType := (', ' asParser / lineBreak) negate plus flatten. > additionalDriveType := ', ' asParser, driveType ==> [ :nodes | nodes second > ]. > driveTypeList := (driveType, additionalDriveType star). > parser := driveTypeHeader, driveTypeList, lineBreak ==> [ :nodes | nodes > second ]. > > parser parse: input. > > Returns: "#('CD-ROM' #('CD-R' 'CD-RW' 'DVD-ROM' 'DVD-R' 'DVD-R DL' 'DVD-RW' > 'DVD+R' 'DVD+R DL' 'DVD+RW'))" > > Makes sense so far, but if I change the above to: > ... > driveTypeList := (driveType, additionalDriveType star) flatten. > ... > Returns: "'CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-R, DVD-R DL, DVD-RW, DVD+R, > DVD+R DL, DVD+RW'" > > Instead of combining the arrays, it made one big string!? > > How do I do this? > > Thanks. > Sean > -- > View this message in context: http://forum.world.st/PetitParser-problem-flattening-a-collection-tp3038980p3038980.html > Sent from the Moose mailing list archive at Nabble.com. > _______________________________________________ > Moose-dev mailing list > [hidden email] > https://www.iam.unibe.ch/mailman/listinfo/moose-dev > ... [show rest of quote] -- Lukas Renggli www.lukas-renggli.ch _______________________________________________ Moose-dev mailing list [hidden email] https://www.iam.unibe.ch/mailman/listinfo/moose-dev |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Administrator
5777 posts
|
Thanks Lukas. I ended up with: driveTypeList := (driveType, additionalDriveType star) ==> [ :nodes | (Array with: nodes first), nodes second ].
Cheers,
Sean |
Free forum by Nabble | Edit this page |