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
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
#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