pe icon indicating copy to clipboard operation
pe copied to clipboard

Separate error type for failing to parse a grammar

Open goodmami opened this issue 4 years ago • 0 comments

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.

goodmami avatar Oct 11 '21 04:10 goodmami