PetitParser - The Great Flatten Mystery

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

PetitParser - The Great Flatten Mystery

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

Re: PetitParser - The Great Flatten Mystery

Sean P. DeNigris
Administrator
Sean P. DeNigris wrote
... and how did the spaces get back in there?
Okay, got the spaces figured out, same problem as last time: "trim flatten" vs. "flatten trim"

Still don't understand the re-de-capitalization, though...

Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser - The Great Flatten Mystery

Lukas Renggli
#flatten does not transform your result, but returns a copy of the
consumed range from the input collection. Check the method comment of
#flatten, the class comment of PPFlattenParser, and the tests.

Try with something along:

word := #word asParser plus flatten ==> [ :s | s capitalized ].
space := #space asParser ==> [ :s | nil ].
parser := (word separatedBy: space) ==> [ :s | s reject: [ :each |
each isNil ] ].
start := parser foldLeft: [ :a :b | a , b ]

Lukas

--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev