Permalink
Browse files

Factor out some duplication in parse(), and tweak some comments and d…

…ocs.
  • Loading branch information...
erikrose committed May 8, 2013
1 parent f498d06 commit 07c94a8c72d09e3a7c20adec5cd73d1d622de48d
View
@@ -65,7 +65,7 @@ Status
* It may be slow and use a lot of RAM; I haven't measured either yet. However,
I have yet to begin optimizing in earnest.
* Error reporting is now in place. ``repr`` methods of expressions, grammars,
- and nodes are clear and helpful and well. Ones of ``Grammar`` objects are
+ and nodes are clear and helpful as well. The ``Grammar`` ones are
even round-trippable!
* The grammar extensibility story is underdeveloped at the moment. You should
be able to extend a grammar by simply concatening more rules onto the
@@ -320,6 +320,7 @@ Version History
some attributes that let you construct your own custom presentation.
* Grammar construction now raises ``ParseError`` rather than ``BadGrammar``
if it can't parse your rules.
+ * ``parse()`` now takes an optional ``pos`` argument, like ``match()``.
* Make the ``_str__()`` method of ``UndefinedLabel`` return the right type.
* Support splitting rules across multiple lines, interleaving comments,
putting multiple rules on one line (but don't do that) and all sorts of
@@ -5,9 +5,9 @@ class ParseError(StrAndRepr, Exception):
"""A call to ``Expression.parse()`` or ``match()`` didn't match."""
def __init__(self, text, pos=-1, expr=None):
- # TODO: It would be nice to use self.args, but I don't want to pay a
- # penalty to call descriptors or have the confusion of numerical
- # indices in Expression._match().
+ # It would be nice to use self.args, but I don't want to pay a penalty
+ # to call descriptors or have the confusion of numerical indices in
+ # Expression._match().
self.text = text
self.pos = pos
self.expr = expr
@@ -37,11 +37,7 @@ def parse(self, text, pos=0):
consume the full string.
"""
- error = ParseError(text)
- node = self._match(text, pos, {}, error)
- if node is None:
- # It was not a complete parse.
- raise error
+ node = self.match(text, pos=pos)
if node.end < len(text):
raise IncompleteParseError(text, node.end, self)
return node
@@ -236,7 +236,6 @@ def test_unicode_crash(self):
"""Make sure matched unicode strings don't crash ``__str__``."""
grammar = Grammar(r'string = ~r"\S+"u')
str(grammar.parse(u'中文'))
- # Okay, this is passing now, because I commented out __str__ etc. in Node.
def test_unicode(self):
"""Smoke-test the conversion of expressions to bits of rules.
@@ -194,9 +194,8 @@ def test_comments(self):
# \n or \r to end.
eq_(list(sorted(str(grammar).splitlines())),
['''bold_text = stars text stars''',
- # Unicode flag is on by default in Python 3. I wonder
- # if we should turn it on all the time in
- # Parsimonious.
+ # TODO: Unicode flag is on by default in Python 3. I wonder if we
+ # should turn it on all the time in Parsimonious.
'''stars = "**"''',
'''text = ~"[A-Z 0-9]*"i%s''' % ('u' if version_info >= (3,)
else '')])

0 comments on commit 07c94a8

Please sign in to comment.