I am playing with PetitParser (which looks super-cool!).
Following Lukas' blogpost , I defined my identifier as:
identifier := #letter asParser , #word asParser star.
then, I am using it to find the matches in a given string:
identifier matchesIn: 'foo 123 bar12'.
#($f #($o $o))
#($b #($a $r $1 $2))
#($a #($r $1 $2))
#($r #($1 $2))
Even though the result is correct and makes much sense, would it
be possible to simply have the longest matches?
As you can see in the implementation and in the comment of
#matchesIn:do: which is called by #matchesIn: the implementation tries
the parser at each input position. You can skip over matches by using
the following code instead:
PPParser>>matchesSkipIn: anObject do: aBlock
"Search anObject repeatedly for the matches of the receiver. Evaluate
aBlock for each match with the matched parse-tree as the argument.
Skip over the matched part."
(self ==> aBlock / #any asParser) star parse: anObject
Maybe that should be added? Maybe somebody has a better name :-)