[ragel-users] Re: Fixing an edge case

Adrian Thurston thurs... at cs.queensu.ca
Tue Jan 16 19:07:21 UTC 2007

I've made this thread a little confusing, so here's a recap with some

This machine does not do what you want. It does properly execute empty_diff
when an empty diff is found, but it also executes empty_diff on the
transitions from diffHeader to either binaryDiff or textDiff.

diff1 = (
	diffHeader %empty_diff %/empty_diff
	( binaryDiff | textDiff ) ?

The following code is one way to fix the problem. It's like the above, but
separates the leaving/eof actions from the non-empty case. When diff2 exits
after only a diffHeader the empty diff action is executed. Note that here
diffHeader is unioned with itself. This relies on the fact that ragel
removes action duplicates from transition lists. Otherwise the actions of
diffHeader would be doubled up.

diff2 = (
	diffHeader %empty_diff %/empty_diff |
	diffHeader ( binaryDiff | textDiff )

And finally, this is another way to do it. I essentially factor out the
diffHeader. The "" machine is a single state which has the leaving/eof
actions embedded into it.
diff3 = (
	diffHeader (
		"" %empty_diff %/empty_diff |
		( binaryDiff | textDiff )

I hope this helps,

More information about the ragel-users mailing list