Commit 5530e3ff authored by Igor Dejanovic's avatar Igor Dejanovic

Docstrings and small refactorings

parent bb63fb29
...@@ -48,9 +48,9 @@ class NoMatch(Exception): ...@@ -48,9 +48,9 @@ class NoMatch(Exception):
match is not successful. match is not successful.
Args: Args:
value (str): A value value (str): A name of the parsing expression or rule.
position (int): position (int): A position in the input stream where exception occurred.
parser (Parser): An instance of parser parser (Parser): An instance of a parser.
""" """
def __init__(self, value, position, parser): def __init__(self, value, position, parser):
self.value = value self.value = value
...@@ -60,7 +60,7 @@ class NoMatch(Exception): ...@@ -60,7 +60,7 @@ class NoMatch(Exception):
self.parser = parser self.parser = parser
# By default when NoMatch is thrown we will go up the Parse Model Tree. # By default when NoMatch is thrown we will go up the Parser Model.
self._up = True self._up = True
def __str__(self): def __str__(self):
...@@ -190,8 +190,8 @@ class ParsingExpression(object): ...@@ -190,8 +190,8 @@ class ParsingExpression(object):
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
we did not consume any input and we are moving up the parser model we did not consume any input and we are moving up the parser model.
tree. Used to report most generic language element expected at the Used to report most generic language element expected at the
place of the NoMatch exception. place of the NoMatch exception.
""" """
if self.root and self.c_pos == nm.position and nm._up: if self.root and self.c_pos == nm.position and nm._up:
...@@ -632,7 +632,7 @@ class Parser(object): ...@@ -632,7 +632,7 @@ class Parser(object):
reduce_tree (bool): If true non-terminals with single child will be reduce_tree (bool): If true non-terminals with single child will be
eliminated from the parse tree. eliminated from the parse tree.
debug (bool): If true debugging messages will be printed. debug (bool): If true debugging messages will be printed.
comments_model (a list of comments_model: parser model for comments.
""" """
def __init__(self, skipws=True, ws=DEFAULT_WS, reduce_tree=False, debug=False): def __init__(self, skipws=True, ws=DEFAULT_WS, reduce_tree=False, debug=False):
self.skipws = skipws self.skipws = skipws
...@@ -647,7 +647,6 @@ class Parser(object): ...@@ -647,7 +647,6 @@ class Parser(object):
def parse(self, _input): def parse(self, _input):
self.position = 0 # Input position self.position = 0 # Input position
self.nm_pos = 0 # Position for last NoMatch exception
self.nm = None # Last NoMatch exception self.nm = None # Last NoMatch exception
self.line_ends = [] self.line_ends = []
self.input = _input self.input = _input
...@@ -813,14 +812,14 @@ class ParserPython(Parser): ...@@ -813,14 +812,14 @@ class ParserPython(Parser):
if callable(expression): # Is this expression a parser rule? if callable(expression): # Is this expression a parser rule?
rule = expression.__name__ rule = expression.__name__
if rule in __rule_cache: if rule in __rule_cache:
c_rule = __rule_cache.get(rule)
if self.debug: if self.debug:
print "Rule %s founded in cache." % rule print "Rule %s founded in cache." % rule
if isinstance(__rule_cache.get(rule), CrossRef): if isinstance(c_rule, CrossRef):
self.__cross_refs += 1 self.__cross_refs += 1
if self.debug: if self.debug:
print "CrossRef usage: %s" % \ print "CrossRef usage: %s" % c_rule.rule_name
__rule_cache.get(rule).rule_name return c_rule
return __rule_cache.get(rule)
#expression_expression = expression() #expression_expression = expression()
#if callable(expression_expression): #if callable(expression_expression):
......
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