Commit d2dfccad authored by Igor Dejanovic's avatar Igor Dejanovic

Better debug and error reporting. Few spelling fixes.

parent 74003628
...@@ -62,8 +62,9 @@ class NoMatch(Exception): ...@@ -62,8 +62,9 @@ class NoMatch(Exception):
self._up = True self._up = True
def __str__(self): def __str__(self):
return "Expected %s at position %s." % (self.rule, return "Expected '{}' at position {} => '{}'.".format(self.rule,
str(self.parser.pos_to_linecol(self.position))) str(self.parser.pos_to_linecol(self.position)),
self.parser.context(position=self.position))
def flatten(_iterable): def flatten(_iterable):
...@@ -203,7 +204,7 @@ class ParsingExpression(object): ...@@ -203,7 +204,7 @@ class ParsingExpression(object):
return result return result
#TODO: _nm_change_rule should be called from every parser expression parse #TODO: _nm_change_rule should be called from every parser expression parse
# method that can potentialy be the root parser rule. # method that can potentially be the root parser rule.
def _nm_change_rule(self, nm, parser): def _nm_change_rule(self, nm, parser):
""" """
Change rule for the given NoMatch object to a more generic if Change rule for the given NoMatch object to a more generic if
...@@ -262,6 +263,7 @@ class Repetition(ParsingExpression): ...@@ -262,6 +263,7 @@ class Repetition(ParsingExpression):
Base class for all repetition-like parser expressions (?,*,+) Base class for all repetition-like parser expressions (?,*,+)
""" """
class Optional(Repetition): class Optional(Repetition):
""" """
Optional will try to match parser expression specified buy will not fail in Optional will try to match parser expression specified buy will not fail in
...@@ -431,7 +433,7 @@ class Match(ParsingExpression): ...@@ -431,7 +433,7 @@ class Match(ParsingExpression):
comments.append(parser.comments_model.parse(parser)) comments.append(parser.comments_model.parse(parser))
parser._skip_ws() parser._skip_ws()
except NoMatch: except NoMatch:
# If comment match successfull try terminal match again # If comment match successfully try terminal match again
if comments: if comments:
match = self._parse(parser) match = self._parse(parser)
match.comments = NonTerminal('comment', self.c_pos, match.comments = NonTerminal('comment', self.c_pos,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment