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
ce1b81b1
Commit
ce1b81b1
authored
May 05, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More parser refactoring: further simplified _handle_tag_type().
parent
e167059a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
27 deletions
+22
-27
pystache/parser.py
+22
-27
No files found.
pystache/parser.py
View file @
ce1b81b1
...
...
@@ -146,57 +146,52 @@ class Parser(object):
if
tag_key
!=
section_key
:
raise
ParsingError
(
"Section end tag mismatch:
%
s !=
%
s"
%
(
tag_key
,
section_key
))
return
end_index
,
ParsedTemplate
(
parse_tree
),
match_index
return
end_index
,
match_index
,
ParsedTemplate
(
parse_tree
)
if
tag_type
in
(
'#'
,
'^'
):
index
,
parsed_section
,
content_end_index
=
self
.
parse
(
template
,
end_index
,
tag_key
)
index
,
content_end_index
,
parsed_section
=
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
,
end_index
,
content_end_index
,
parsed_section
)
node
=
self
.
_make_node
(
template
,
tag_type
,
tag_key
,
leading_whitespace
,
end_index
,
content_end_index
,
parsed_section
)
parse_tree
.
append
(
node
)
# Save the rest of the template.
parse_tree
.
append
(
template
[
index
:])
return
ParsedTemplate
(
parse_tree
)
def
_handle_tag_type
(
self
,
template
,
parse_tree
,
tag_type
,
tag_key
,
leading_whitespace
,
section_start_index
,
section_end_index
,
parsed_section
):
def
_make_node
(
self
,
template
,
tag_type
,
tag_key
,
leading_whitespace
,
section_start_index
,
section_end_index
,
parsed_section
):
"""
Create and return a node of the parse tree.
"""
# TODO: switch to using a dictionary instead of a bunch of ifs and elifs.
if
tag_type
==
'!'
:
return
return
u''
if
tag_type
==
'='
:
delimiters
=
tag_key
.
split
()
self
.
_change_delimiters
(
delimiters
)
return
return
u''
if
tag_type
==
''
:
return
self
.
engine
.
_make_get_escaped
(
tag_key
)
func
=
self
.
engine
.
_make_get_escaped
(
tag_key
)
elif
tag_type
==
'&'
:
func
=
self
.
engine
.
_make_get_literal
(
tag_key
)
elif
tag_type
==
'#'
:
if
tag_type
==
'&'
:
return
self
.
engine
.
_make_get_literal
(
tag_key
)
func
=
self
.
engine
.
_make_get_section
(
tag_key
,
parsed_section
,
self
.
_delimiters
,
if
tag_type
==
'#'
:
return
self
.
engine
.
_make_get_section
(
tag_key
,
parsed_section
,
self
.
_delimiters
,
template
,
section_start_index
,
section_end_index
)
elif
tag_type
==
'^'
:
func
=
self
.
engine
.
_make_get_inverse
(
tag_key
,
parsed_section
)
elif
tag_type
==
'>'
:
func
=
self
.
engine
.
_make_get_partial
(
tag_key
,
leading_whitespace
)
else
:
if
tag_type
==
'^'
:
return
self
.
engine
.
_make_get_inverse
(
tag_key
,
parsed_section
)
raise
Exception
(
"Unrecognized tag type:
%
s"
%
repr
(
tag_type
))
if
tag_type
==
'>'
:
return
self
.
engine
.
_make_get_partial
(
tag_key
,
leading_whitespace
)
parse_tree
.
append
(
func
)
raise
Exception
(
"Unrecognized tag type:
%
s"
%
repr
(
tag_type
)
)
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