diff --git a/src/parse.py b/src/parse.py index 367bdea..e4b6d97 100644 --- a/src/parse.py +++ b/src/parse.py @@ -330,9 +330,10 @@ def format_context(context): task = context.task if context.token: + file = context.token.location.file line = context.token.location.line offset = context.token.location.offset - return Message("ParseContextAt", [task, line, offset]) + return Message("ParseContextAt", [task, file, line, offset]) else: return Message("ParseContext", [task]) @@ -347,9 +348,10 @@ else: args = [error] if has_token: + file = exception.token.location.file line = exception.token.location.line offset = exception.token.location.offset - args = args + [line, offset] + args = args + [file, line, offset] ids = [ ["ParserError", "ParserErrorAt"], ["ParserErrorExpected", "ParserErrorExpectedAt"], diff --git a/tests/parse/test_error.py b/tests/parse/test_error.py index 7e26d15..aad2f48 100644 --- a/tests/parse/test_error.py +++ b/tests/parse/test_error.py @@ -147,15 +147,16 @@ # location's line and offset # Two combinations are possible: # - Message("ParseContext", [task]) -# - Message("ParseContextAt", [task, line, offset]) +# - Message("ParseContextAt", [task, file, line, offset]) @given(draw_parse_context()) def test_parse_error_format_context(context): task = context.task has_location = context.token is not None if has_location: + file = context.token.location.file line = context.token.location.line offset = context.token.location.offset - expected = Message("ParseContextAt", [task, line, offset]) + expected = Message("ParseContextAt", [task, file, line, offset]) else: expected = Message("ParseContext", [task]) value = format_context(context) @@ -174,11 +175,12 @@ # location's line and offset # Four combinations are possible: # - Message("ParserError", [error]) -# - Message("ParserErrorAt", [error, line, offset]) +# - Message("ParserErrorAt", [error, file, line, offset]) # - Message("ParserErrorExpected", [expected]) -# - Message("ParserErrorExpectedAt", [expected, line, offset]) +# - Message("ParserErrorExpectedAt", [expected, file, line, offset]) # error is a message representing the ParseError, equivalent to: # - Message(error_message_ids[exception.error], []) +# file is a source file's name # line is a source file's line number # offset is a source file's line offset def _test_parse_error_format_exception(exception): @@ -188,9 +190,11 @@ err = Message(error_message_ids[exception.error], []) expect = exception.expected if has_location: + file = exception.token.location.file line = exception.token.location.line offset = exception.token.location.offset else: + file = None line = None offset = None # Truth table used for message lookup @@ -199,12 +203,12 @@ # Cases without an expected token: [ Message("ParserError", [err]), - Message("ParserErrorAt", [err, line, offset]), + Message("ParserErrorAt", [err, file, line, offset]), ], # Cases with an expected token: [ Message("ParserErrorExpected", [expect]), - Message("ParserErrorExpectedAt", [expect, line, offset]), + Message("ParserErrorExpectedAt", [expect, file, line, offset]), ], ] expected = messages[has_expected][has_location]