Newbie advice

Dave Dribin ddri... at gmail.com
Mon Aug 27 16:53:24 UTC 2007


Thanks, again.  Can you see anything wrong with the following
approach?  To make it more interesting, I want to handle both Unix and
Windows newlines:

    newline = '\r'? '\n' @onNewline;
    any_line = [^\r\n]* newline;
    marker_line = '--' newline;
    section_body = (any_line - marker_line)*;

    section = (section_body marker_line $countMarker) $onChar
@onSection;

Thus, onChar buffers up the entire section, including the full marker
line.  But countMarker counts the number of characters in used in the
variable length marker, and onSection strips that many characters from
the buffer.

This seems to handle the general case of a variable length terminating
marker.  The downside is that it buffers up extra characters only to
yank them off, at the end.  So long as the terminating marker is
fairly short, I don't see this being a major issue.

Is it possible for countMarker to set an "ignore" flag that onChar
checks?  This would require that the countMarker action be called
before onChar, though, and I don't know if that is guaranteed.

-Dave



More information about the ragel-users mailing list