91 else: |
91 else: |
92 raise error.ParseError(_("syntax error"), pos) |
92 raise error.ParseError(_("syntax error"), pos) |
93 pos += 1 |
93 pos += 1 |
94 yield ('end', None, pos) |
94 yield ('end', None, pos) |
95 |
95 |
96 def compiletemplate(tmpl, context, strtoken="string"): |
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((strtoken, tmpl[pos:])) |
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 strtoken == 'string' and bs % 2 == 1: |
106 if bs % 2 == 1: |
107 # escaped (e.g. '\{', '\\\{', but not '\\{' nor r'\{') |
107 # escaped (e.g. '\{', '\\\{', but not '\\{') |
108 parsed.append((strtoken, (tmpl[pos:n - 1] + "{"))) |
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((strtoken, tmpl[pos:n])) |
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) |
116 parsed.append(parseres) |
116 parsed.append(parseres) |
117 |
117 |