Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pystache_custom
Commits
e167059a
Commit
e167059a
authored
May 05, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More parser refactoring: eliminated _parse_section().
parent
f5b62fdc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
37 deletions
+6
-37
pystache/parser.py
+6
-37
No files found.
pystache/parser.py
View file @
e167059a
...
...
@@ -99,6 +99,8 @@ class Parser(object):
parse_tree
=
[]
index
=
start_index
content_end_index
,
parsed_section
=
None
,
None
while
True
:
match
=
self
.
_template_re
.
search
(
template
,
index
)
...
...
@@ -146,8 +148,10 @@ class Parser(object):
return
end_index
,
ParsedTemplate
(
parse_tree
),
match_index
index
,
parsed_section
,
content_end_index
=
\
self
.
_parse_section
(
tag_type
,
tag_key
,
template
,
end_index
)
if
tag_type
in
(
'#'
,
'^'
):
index
,
parsed_section
,
content_end_index
=
self
.
parse
(
template
,
end_index
,
tag_key
)
else
:
index
=
end_index
# Variable index is now the next character to process.
self
.
_handle_tag_type
(
template
,
parse_tree
,
tag_type
,
tag_key
,
leading_whitespace
,
...
...
@@ -158,41 +162,6 @@ class Parser(object):
return
ParsedTemplate
(
parse_tree
)
def
_parse_section
(
self
,
tag_type
,
section_key
,
template
,
start_index
):
"""
Parse the contents of a template section.
Arguments:
tag_type: the tag symbol.
section_key: the tag key of the section.
template: a unicode template string.
start_index: the string index at which the section contents begin.
Returns: a 3-tuple:
end_index: the string index after the closing section tag (and
including any trailing newlines), or the same index if there
is no section.
parsed_section: the section contents parsed as a ParsedTemplate
instance.
content_end_index: the string index after the section contents.
"""
if
not
tag_type
in
(
'#'
,
'^'
):
return
start_index
,
None
,
None
# Returns:
#
# end_index, parsed_section, section_end_index
#
return
self
.
parse
(
template
=
template
,
start_index
=
start_index
,
section_key
=
section_key
)
def
_handle_tag_type
(
self
,
template
,
parse_tree
,
tag_type
,
tag_key
,
leading_whitespace
,
section_start_index
,
section_end_index
,
parsed_section
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment