-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Optional feature: More verbose failed expression reporting
An option is added to the Parser class. This option is disabled by default, and the existing behavior is fully preserved. When the option is enabled, the final expected message is extended with extra information about the previously "weakly failed" rules. This way, not only the last failed NoMatch exception and its failing rules are displayed but also all the rules that were not matched during the whole parsing process.
- Loading branch information
Showing
5 changed files
with
405 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
####################################################################### | ||
# Name: test_error_reporting_verbose | ||
# Purpose: Test error reporting for various cases when verbose=True enabled. | ||
# Author: Igor R. Dejanović <igor DOT dejanovic AT gmail DOT com> | ||
# Copyright: (c) 2015 Igor R. Dejanović <igor DOT dejanovic AT gmail DOT com> | ||
# License: MIT License | ||
####################################################################### | ||
from __future__ import unicode_literals | ||
import pytest | ||
|
||
from arpeggio import Optional, Not, ParserPython, NoMatch, EOF, Sequence, RegExMatch, StrMatch, OrderedChoice | ||
from arpeggio import RegExMatch as _ | ||
|
||
|
||
def test_optional_with_better_match(): | ||
""" | ||
Test that optional match that has gone further in the input stream | ||
has precedence over non-optional. | ||
""" | ||
|
||
def grammar(): return [first, (Optional(second), 'six')] | ||
def first(): return 'one', 'two', 'three', '4' | ||
def second(): return 'one', 'two', 'three', 'four', 'five' | ||
|
||
parser = ParserPython(grammar, verbose=True) | ||
assert parser.verbose | ||
|
||
with pytest.raises(NoMatch) as e: | ||
parser.parse('one two three four 5') | ||
|
||
assert ( | ||
"Expected " | ||
"'six' at position (1, 1) or " | ||
"'4' at position (1, 15) or " | ||
"'five' at position (1, 20) => " | ||
"'hree four *5'." | ||
) == str(e.value) | ||
assert (e.value.line, e.value.col) == (1, 20) |
Oops, something went wrong.