pe
pe copied to clipboard
Separate error type for failing to parse a grammar
A parser is used to read pe grammars, so invalid grammars will raise a ParseError just as a valid grammar with bad input:
>>> pe.match('"a"+', 'b', flags=pe.STRICT|pe.MEMOIZE) # valid grammar, bad input
Traceback (most recent call last):
...
pe._errors.ParseError:
line 0, character 0
b
^
ParseError: `(?=(?P<_1>a+))(?P=_1)`
>>> pe.match('+"a"', 'b', flags=pe.STRICT|pe.MEMOIZE) # invalid grammar
Traceback (most recent call last):
...
pe._errors.ParseError:
line 0, character 0
+"a"
^
\arseError: `[\ \ ]`, `\
`, `\
`, `\#`, `\#`, `[a-zA-Z_]`, `\&`, `!`, `\~`, `[a-zA-Z_]`, `\(`, `'`, `"`, `"`, `\[`, `\.`, `\.`, `\.`
The latter case should be GrammarError.