Search code examples
cparsingragel

Ragel alternative to fbreak; but without advance to next symbol?


I'm writing a program what parses HTML to extract URLs from there using Ragel.
After finding URL I need to perform some actions on it, and then ready to process next URL.
So I need to stop executing main loop at the URL end, execute some actions outside of parser, and then start from where I broke.

fbreak seems to be a good varinat, but unfortunatelly it ate next symbol in buffer. The issue here, besides there could be already buffer end, is that we effectively skip one symbol in input stream.

Is there is a way to break execution without advance to the next symbol in input stream, as fbreak does?
So far I figure out only dirty hack to write goto _out; instead of fbreak.


Solution

  • I believe you need to make an fhold call preceding your fbreak.

    Quoting the Ragel user guide:

    fhold; -- Do not advance over the current character. If processing data in multiple buffer blocks, the fhold statement should only be used once in the set of actions executed on a character. Multiple calls may result in backing up over the beginning of the buffer block. The fhold statement does not imply any transfer of control. It is equivalent to the p--; statement.