diff --git a/src/parse.py b/src/parse.py index 5a0347e..39af39f 100644 --- a/src/parse.py +++ b/src/parse.py @@ -325,16 +325,21 @@ # Formats a ParseErrorException def format_exception(exception): - id = "ParseError" - args = [exception.error] - if exception.expected is not None: - id = id + "Expected" + has_expected = exception.expected is not None + has_token = exception.token is not None + if has_expected: args = [exception.expected] - if exception.token is not None: - id = id + "At" + else: + args = [exception.error] + if has_token: line = exception.token.location.line offset = exception.token.location.offset args = args + [line, offset] + ids = [ + ["ParseError", "ParseErrorAt"], + ["ParseErrorExpected", "ParseErrorExpectedAt"], + ] + id = ids[has_expected][has_token] return Message(id, args)