Error handling and reporting in Ragel
Oliver
oliver.schonef... at uni-bielefeld.de
Thu Mar 1 10:16:15 UTC 2007
Hello,
I'm currently using Ragel to write a parser for an XML-like language.
In
case of a parsing error, I want to be able to provide meaningful
feedback
to the user.
The following is a subset of my machine:
%{{
machine Test;
alphtype char;
NCName = [a-zA-Z] . [a-zA-Z0-9]*;
Prefix = NCName;
LocalPart = NCName;
PrefixedName = Prefix ':' LocalPart;
UnprefixedName = LocalPart;
QName = PrefixedName | UnprefixedName;
LQName = '(' NCName ')' QName;
AttValue = ('"' [^<&\"]* '"' | "'" [^<&\']* "'");
Attribute = QName Eq AttValue;
StartTag = '<' LQName (S Attribute)* S? '>';
main := StartTag*;
}}%
The following Input (without double quotes) should generate:
1) "<(l1) test>" -> "Expected QName."
2) "<l1)test>" -> "Expected '('."
I have been experimenting with global error state actions. I modified
the
'LQName' rule like this:
action err1 {
std::cout << "Expected '('." << std::endl;
}
# actions err2 ... err4 are similar to err1
LQName = '(' @!err1 NCName @!err2 ')' @!err3 QName @!err4;
It this the way to go, or can this be done elegantly in a less verbose
way.
Embedding error actions in all rules looks a litte cumbersome to me.
Best Regards,
Thanks,
Oliver
--
--------------------------------------------------------
And remember: "To Infinity And Far Beyond ... Somehow?!"
Hi! I'm a .signature virus! Copy me in your ~/.signature
to help me spread! <- Save this lifeform ;-)
More information about the ragel-users
mailing list