This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: When Rageling, Bring a Bird Beak
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
While bunking inside Ragel, I’m starting to see the handiness of its lookahead operator. The bird beak :>, which gives a high priority to the next token in the machine.
In SuperRedCloth, this rule here was a flimsy way of matching a bit of text in parens:
title = ( '(' [^)]+ ')' );
It turns out I was able to cut down the generated grammer by something like fifty K by using this instead:
title = ( '(' chars+ :> ')' ) ;
The beak is great for any rule that’s getting too greedy and concludes with an exact character. Be warned, it may increase the complexity of the machine depending on how ambiguous your other rules are.
If I could offer one other bit of advice: stay away from the question mark, if you can. It seems like anything which uses the empty token can be expensive.