When Rageling, Bring a Bird Beak

RedHanded From RedHanded, 1 year ago, 0 views

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.

comments

No comments yet.

You must be logged in to add your own comment.