Re: [Pyparsing] Get Better Error Messages - Prevent Backtracking
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2008-04-21 02:29:39
|
Eike - Wow! SIML is really quite an expressive language. I've added a link to the "Who's Using Pyparsing" page of the wiki to your project. pyparsing already has setErrorAction, although it is called setFailAction. Here is the docstring: """Define action to perform if parsing fails at this expression. Fail acton fn is a callable function that takes the arguments fn(s,loc,expr,err) where: - s = string being parsed - loc = location where expression match was attempted and failed - expr = the parse expression that failed - err = the exception thrown The function returns no value. It may throw ParseFatalException if it is desired to stop parsing immediately.""" If you are generating code, you might look into using Python's import hooks. Here is an example where I use pyparsing to parse state machine definitions in a file with the extension .pystate, where the states are defined with a state machine like: TrafficLight = { Red -> Green; Green -> Yellow; Yellow -> Red; } Here is the full example, with links to the code: http://www.geocities.com/ptmcg/python/index.html#stateMachine (I will be updating this soon to use an indentation-based parser for state machines, so I can get rid of those {}'s and ;'s!) -- Paul |