[ragel-users] Advice on detecting errors
thurs... at cs.queensu.ca
Fri Mar 28 18:58:49 UTC 2008
If you just want to report where in the input the error occured you can
print the values at (or the location of) p. It is left at the character
the error occurred at.
If you want to give some idea of what was expected when the error
occurred you can use error actions. These are associated with particular
states and can print error messages directly or can set some variable
representing the context. See the relevant section in the manual.
In scanners, if no pattern matches then the state machine moves into the
error state. If you want to create an "else" pattern then put "any" at
the very end of the list of patterns. It will act as a default.
Manoj Rajagopalan wrote:
> Hi all,
> I have two questions.
> QUESTION 1:
> I'm not clear on how to detect syntax errors in Ragel. As a simple
> example, if I want allow a statement:
> set <name> = <value>;
> for which my pattern would be something like:
> set_stmt = space* 'set' (alpha alnum*) space* '=' space* digit+
> space* ';'
> and if I provide input like
> set var = 123bad;
> How can I get Ragel to point out a syntax error here?
> QUESTION 2:
> If I set up a scanner with a list of allowed expressions and ragel
> encounters an expression that is not on the list, what does it do? Is it
> possible to create a 'trap' pattern to output an unrecognized or badly
> formed input?
More information about the ragel-users