Skip to content

Commit

Permalink
Fix error reporting on match and not EOF.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Jul 24, 2018
1 parent 592eab9 commit b2550ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/test_textparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@ def test_grammar_1_mismatch(self):
('NUMBER', '1', 2)
],
2
),
(
[
('IF', 'IF', 1),
('STRING', 'foo', 2),
('WORD', 'bar', 3),
('.', '.', 4),
('.', '.', 5)
],
5
)
]

Expand Down
4 changes: 2 additions & 2 deletions textparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


__author__ = 'Erik Moqvist'
__version__ = '0.7.0'
__version__ = '0.8.0'


class _Tokens(object):
Expand Down Expand Up @@ -421,7 +421,7 @@ def parse(self, tokens):
tokens = _Tokens(tokens)
parsed = self._root.match(tokens)

if parsed is not None and tokens.get().kind == '__EOF__':
if parsed is not None and tokens.peek().kind == '__EOF__':
return parsed
else:
raise GrammarError(tokens.get().offset)
Expand Down

0 comments on commit b2550ef

Please sign in to comment.