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
a3141ab8
Commit
a3141ab8
authored
Jan 14, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed Parser.parse() to read from the matches dictionary earlier.
parent
854b84c9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
25 deletions
+26
-25
pystache/parser.py
+26
-25
No files found.
pystache/parser.py
View file @
a3141ab8
...
...
@@ -31,7 +31,7 @@ def _compile_template_re(delimiters):
(?:
(?P<change>=) \s* (?P<delims>.+?) \s* = |
(?P<raw>{) \s* (?P<raw_name>.+?) \s* } |
(?P<tag>[
%(tag_types)
s]?) \s* (?P<
name
>[\s\S]+?)
(?P<tag>[
%(tag_types)
s]?) \s* (?P<
tag_key
>[\s\S]+?)
)
\s*
%(ctag)
s
"""
%
{
'tag_types'
:
tag_types
,
'otag'
:
re
.
escape
(
delimiters
[
0
]),
'ctag'
:
re
.
escape
(
delimiters
[
1
])}
...
...
@@ -99,24 +99,15 @@ class Parser(object):
matches
=
match
.
groupdict
()
index
=
self
.
_handle_match
(
template
,
parse_tree
,
matches
,
start_index
,
match_index
,
end_index
)
# Save the rest of the template.
parse_tree
.
append
(
template
[
index
:])
return
parse_tree
def
_handle_match
(
self
,
template
,
parse_tree
,
matches
,
start_index
,
match_index
,
end_index
):
engine
=
self
.
engine
# Normalize the matches dictionary.
if
matches
[
'change'
]
is
not
None
:
matches
.
update
(
tag
=
'='
,
name
=
matches
[
'delims'
])
matches
.
update
(
tag
=
'='
,
tag_key
=
matches
[
'delims'
])
elif
matches
[
'raw'
]
is
not
None
:
matches
.
update
(
tag
=
'&'
,
name
=
matches
[
'raw_name'
])
matches
.
update
(
tag
=
'&'
,
tag_key
=
matches
[
'raw_name'
])
tag_type
=
matches
[
'tag'
]
tag_key
=
matches
[
'tag_key'
]
leading_whitespace
=
matches
[
'whitespace'
]
# Standalone (non-interpolation) tags consume the entire line,
# both leading whitespace and trailing newline.
...
...
@@ -129,23 +120,32 @@ class Parser(object):
end_index
+=
template
[
end_index
]
==
'
\r
'
and
1
or
0
if
end_index
<
len
(
template
):
end_index
+=
template
[
end_index
]
==
'
\n
'
and
1
or
0
elif
matches
[
'whitespace'
]
:
parse_tree
.
append
(
matches
[
'whitespace'
]
)
match_index
+=
len
(
matches
[
'whitespace'
]
)
matches
[
'whitespace'
]
=
''
elif
leading_whitespace
:
parse_tree
.
append
(
leading_whitespace
)
match_index
+=
len
(
leading_whitespace
)
leading_whitespace
=
''
name
=
matches
[
'name'
]
index
=
self
.
_handle_match
(
template
,
parse_tree
,
tag_type
,
tag_key
,
leading_whitespace
,
start_index
,
match_index
,
end_index
)
# Save the rest of the template.
parse_tree
.
append
(
template
[
index
:])
return
parse_tree
def
_handle_match
(
self
,
template
,
parse_tree
,
tag_type
,
tag_key
,
leading_whitespace
,
start_index
,
match_index
,
end_index
):
if
tag_type
==
'!'
:
return
end_index
if
tag_type
==
'='
:
delimiters
=
name
.
split
()
delimiters
=
tag_key
.
split
()
self
.
_change_delimiters
(
delimiters
)
return
end_index
engine
=
self
.
engine
if
tag_type
==
'>'
:
func
=
engine
.
_make_get_partial
(
name
,
matches
[
'whitespace'
]
)
func
=
engine
.
_make_get_partial
(
tag_key
,
leading_whitespace
)
elif
tag_type
in
[
'#'
,
'^'
]:
try
:
...
...
@@ -156,20 +156,21 @@ class Parser(object):
end_index
=
e
.
position
if
tag_type
==
'#'
:
func
=
engine
.
_make_get_section
(
name
,
bufr
,
tmpl
,
self
.
_delimiters
)
func
=
engine
.
_make_get_section
(
tag_key
,
bufr
,
tmpl
,
self
.
_delimiters
)
else
:
func
=
engine
.
_make_get_inverse
(
name
,
bufr
)
func
=
engine
.
_make_get_inverse
(
tag_key
,
bufr
)
elif
tag_type
==
'&'
:
func
=
engine
.
_make_get_literal
(
name
)
func
=
engine
.
_make_get_literal
(
tag_key
)
elif
tag_type
==
''
:
func
=
engine
.
_make_get_escaped
(
name
)
func
=
engine
.
_make_get_escaped
(
tag_key
)
elif
tag_type
==
'/'
:
# TODO: check that tag key matches section start tag key.
# TODO: don't use exceptions for flow control.
raise
EndOfSection
(
parse_tree
,
template
[
start_index
:
match_index
],
end_index
)
...
...
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