goodmami / pe

Fastest general-purpose parsing library for Python with a familiar API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Separate error type for failing to parse a grammar

goodmami opened this issue · 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.