PetitParser - problem flattening a collection

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PetitParser - problem flattening a collection

Sean P. DeNigris
Administrator
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
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser - problem flattening a collection

Lukas Renggli
      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
>



--
Lukas Renggli
www.lukas-renggli.ch

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser - problem flattening a collection

Sean P. DeNigris
Administrator
Lukas Renggli wrote
      driveType separatedBy: ', ' asParse

(and see the implementation of #separatedBy: if this is not exactly
what you are looking for)
Thanks Lukas.  I ended up with:
        driveTypeList := (driveType, additionalDriveType star) ==> [ :nodes |
                (Array with: nodes first), nodes second ].
Cheers,
Sean