Error actions and error recovery

Steve Horne stephenhorne... at
Wed Sep 5 01:48:34 UTC 2007

> pr = alnum+ ';';
> se = '{' pr* '}';
> main := se+;
> What I would like to accomplish is that if there's an error in pr I
> would like to skip to the next ';' or '}'. I there's an error finding
> the first '{', I would like to skip to the next '}'.

This expression doesn't search for '{' at all - it expects to find one
right at the start of the input, and another one immediately after
every '}' (with nothing in-between) until you reach the final '}' at
the end of the input stream.

Perhaps you need to make use of an (any* -- se) term to skip any non-
matching stuff between the blocks you are interested in...

pr = alnum+ ';';
se = '{' pr* '}';
other = (any* -- se);
main := other (se other)*;

Not sure how well this will work in practice - it looks like it needs
backtracking and may need to use the scanner construct...

pr = alnum+ ';';
se = '{' pr* '}';
other = (any+ -- '{');
main := |* se => { action };
               other => { do nothing };
               '{' => { last resort step past open brace action };

The idea here is the 'other' shouldn't even accept part of the 'se'
pattern. As soon as it spots an open brace, it should stop and give
the 'se' token a chance to match. If neither 'se' nor 'other' can
accept any characters, you must have an open brace as the next
character, so skip past that then continue.

For this to work, it is important that neither 'se' nor 'other' can
accept a empty match - if they did, I suspect you'd get an infinite
loop with the standalone '{' match never firing. Is that right,

More information about the ragel-users mailing list