Grako - How to do error handling?
问题 How do I do error handling with Grako? EBNF (MyGrammar.ebnf): pattern = { tag | function }* ; tag = tag:( "%" name:id "%" ); function = function:("$" name:id "()" ); id = ?/([^\\%$,()=])+/? ; I'm generating the parser with python -m grako --whitespace '' MyGrammar.ebnf > my_parser.py Parsing an empty string and a "bad" string (that could not be matched by the grammar) both results to an empty AST Closure. parser = MyGrammarParser() ast = parser.parse(u"%test%", rule_name='pattern') #ast