Show More
@@ -93,23 +93,23 def tokenizer(data): | |||||
93 | pos += 1 |
|
93 | pos += 1 | |
94 | yield ('end', None, pos) |
|
94 | yield ('end', None, pos) | |
95 |
|
95 | |||
96 |
def compiletemplate(tmpl, context |
|
96 | def compiletemplate(tmpl, context): | |
97 | parsed = [] |
|
97 | parsed = [] | |
98 | pos, stop = 0, len(tmpl) |
|
98 | pos, stop = 0, len(tmpl) | |
99 | p = parser.parser(tokenizer, elements) |
|
99 | p = parser.parser(tokenizer, elements) | |
100 | while pos < stop: |
|
100 | while pos < stop: | |
101 | n = tmpl.find('{', pos) |
|
101 | n = tmpl.find('{', pos) | |
102 | if n < 0: |
|
102 | if n < 0: | |
103 |
parsed.append(( |
|
103 | parsed.append(('string', tmpl[pos:])) | |
104 | break |
|
104 | break | |
105 | bs = (n - pos) - len(tmpl[pos:n].rstrip('\\')) |
|
105 | bs = (n - pos) - len(tmpl[pos:n].rstrip('\\')) | |
106 |
if |
|
106 | if bs % 2 == 1: | |
107 |
# escaped (e.g. '\{', '\\\{', but not '\\{' |
|
107 | # escaped (e.g. '\{', '\\\{', but not '\\{') | |
108 |
parsed.append(( |
|
108 | parsed.append(('string', (tmpl[pos:n - 1] + "{"))) | |
109 | pos = n + 1 |
|
109 | pos = n + 1 | |
110 | continue |
|
110 | continue | |
111 | if n > pos: |
|
111 | if n > pos: | |
112 |
parsed.append(( |
|
112 | parsed.append(('string', tmpl[pos:n])) | |
113 |
|
113 | |||
114 | pd = [tmpl, n + 1, stop] |
|
114 | pd = [tmpl, n + 1, stop] | |
115 | parseres, pos = p.parse(pd) |
|
115 | parseres, pos = p.parse(pd) |
General Comments 0
You need to be logged in to leave comments.
Login now