Login  Register

PetitParser - The Great Flatten Mystery

Posted by Sean P. DeNigris on Dec 04, 2010; 4:27am
URL: https://forum.world.st/PetitParser-The-Great-Flatten-Mystery-tp3072095.html

I am baffled... I want to turn 'I am not yet watching' into 'IAmNotYetWatching'.

I got really close with:
        | word additionalWord parser |
        word := #word asParser plus flatten ==> [ :s | s capitalized ].
        additionalWord := #space asParser, word ==> [ :n | n second ].
        parser := (word, additionalWord star).
        parser parse: 'I am not yet watching'.

Result: #('I' #('Am' 'Not' 'Yet' 'Watching'))

So I thought, "cool, just flatten that puppy and"... not even close!  I got the exact input string back!  What?!

        ... same as above with flatten added     \/
        parser := (word, additionalWord star) flatten.
        parser parse: 'I am not yet watching'.

Result: 'I am not yet watching'

Where did my capitals go and how did the spaces get back in there?

Thanks.
Sean
Cheers,
Sean