Commit 2de83f87 by Chris Jerdonek

Refactoring parser: removed a local variable (index) from parse().

parent ce1b81b1
...@@ -97,12 +97,11 @@ class Parser(object): ...@@ -97,12 +97,11 @@ class Parser(object):
""" """
parse_tree = [] parse_tree = []
index = start_index
content_end_index, parsed_section = None, None content_end_index, parsed_section = None, None
while True: while True:
match = self._template_re.search(template, index) match = self._template_re.search(template, start_index)
if match is None: if match is None:
break break
...@@ -110,7 +109,7 @@ class Parser(object): ...@@ -110,7 +109,7 @@ class Parser(object):
match_index = match.start() match_index = match.start()
end_index = match.end() end_index = match.end()
before_tag = template[index : match_index] before_tag = template[start_index : match_index]
parse_tree.append(before_tag) parse_tree.append(before_tag)
...@@ -149,9 +148,9 @@ class Parser(object): ...@@ -149,9 +148,9 @@ class Parser(object):
return end_index, match_index, ParsedTemplate(parse_tree) return end_index, match_index, ParsedTemplate(parse_tree)
if tag_type in ('#', '^'): if tag_type in ('#', '^'):
index, content_end_index, parsed_section = self.parse(template, end_index, tag_key) start_index, content_end_index, parsed_section = self.parse(template, end_index, tag_key)
else: else:
index = end_index start_index = end_index
# Variable index is now the next character to process. # Variable index is now the next character to process.
node = self._make_node(template, tag_type, tag_key, leading_whitespace, node = self._make_node(template, tag_type, tag_key, leading_whitespace,
...@@ -159,7 +158,7 @@ class Parser(object): ...@@ -159,7 +158,7 @@ class Parser(object):
parse_tree.append(node) parse_tree.append(node)
# Save the rest of the template. # Save the rest of the template.
parse_tree.append(template[index:]) parse_tree.append(template[start_index:])
return ParsedTemplate(parse_tree) return ParsedTemplate(parse_tree)
......
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