[ragel-users] Error handling and reporting in Ragel

Adrian Thurston thurs... at cs.queensu.ca
Fri Mar 2 23:28:04 UTC 2007


Sorry I don't have much else for you. If you want to specialize error
actions they need to be specified directly in machine definition as you've
done. The alternative is a global error action which prints the
character/position which the error occurred at.

Regards,
 Adrian

Oliver wrote:
> 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