fixed setup.py, a type and removed the possibility to use multiple statements per block. The latter makes it easier to write custom tags
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent 7324eb8 · Browse files · 5 files·+11 added−34 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+11 added−34 removed
- other:+11 added−34 removed
Provenance
- Commit
2b60fe5- Tree
80ed870- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
7324eb8
5 files changed+11 added−34 removed
modified:jinja2/ext.py+1 added
32 unmodified lines33 """Called if one of the tags matched."""34 35 36 class CacheExtension(Extension):37+ """An example extension that adds cacheable blocks."""38 tags = set(['cache'])39 40 def parse(self, parser):41 lineno = parser.stream.next().lineno8 unmodified linesmodified:jinja2/i18n.py+1 added-2 removed
148 unmodified lines149 parser.stream.next()150 referenced.update(plural_names)151 else:152 parser.stream.next()153- parser.end_statement()153 154 # register free names as simple name expressions155 for var in referenced:156 if var not in variables:14 unmodified lines171 if variables:172 variables = nodes.Dict([nodes.Pair(nodes.Const(x, lineno=lineno), y)173 for x, y in variables.items()])174 else:176- vairables = None175+ variables = None176 177 node = self._make_node(singular, plural, variables, plural_expr)178 node.set_lineno(lineno)179 return node57 unmodified linesmodified:jinja2/lexer.py+2 added-3 removed
36 unmodified lines37 38 # set of used keywords39 keywords = set(['and', 'block', 'elif', 'else', 'endblock', 'print',40 'endfilter', 'endfor', 'endif', 'endmacro', 'endraw',41- 'extends', 'filter', 'for', 'if', 'in',42- 'include', 'is', 'macro', 'not', 'or', 'raw',43- 'recursive', 'set', 'call', 'endcall'])41+ 'extends', 'filter', 'for', 'if', 'in', 'include'42+ 'is', 'macro', 'not', 'or', 'raw', 'call', 'endcall'])43 44 # bind operators to token types45 operators = {46 '+': 'add',452 unmodified linesmodified:jinja2/parser.py+6 added-28 removed
14 unmodified lines15 16 _statement_keywords = frozenset(['for', 'if', 'block', 'extends', 'print',17 'macro', 'include'])18 _compare_operators = frozenset(['eq', 'ne', 'lt', 'lteq', 'gt', 'gteq', 'in'])19-statement_end_tokens = set(['elif', 'else', 'endblock', 'endfilter',20- 'endfor', 'endif', 'endmacro', 'variable_end',21- 'in', 'recursive', 'endcall', 'block_end'])19+statement_end_tokens = set(['variable_end', 'block_end', 'in'])20 21 22 class Parser(object):23 """The template parser class.13 unmodified lines37 for extension in environment.extensions:38 for tag in extension.tags:39 self.extensions[tag] = extension.parse40 43- def end_statement(self):44- """Make sure that the statement ends properly."""45- if self.stream.current.type is 'semicolon':46- self.stream.next()47- elif self.stream.current.type not in statement_end_tokens:48- raise TemplateSyntaxError('ambigous end of statement',49- self.stream.current.lineno,50- self.filename)51-41 def parse_statement(self):42 """Parse a single statement."""43 token_type = self.stream.current.type44 if token_type in _statement_keywords:11 unmodified lines56 if self.stream.current.type == 'assign':57 result = self.parse_assign(expr)58 else:59 result = nodes.ExprStmt(expr, lineno=lineno)71- self.end_statement()60 return result61 62 def parse_assign(self, target):63 """Parse an assign statement."""2 unmodified lines66 raise TemplateSyntaxError("can't assign to '%s'" %67 target, target.lineno,68 self.filename)69 expr = self.parse_tuple()82- self.end_statement()70 target.set_ctx('store')71 return nodes.Assign(target, expr, lineno=lineno)72 73 def parse_statements(self, end_tokens, drop_needle=False):4 unmodified lines78 # the first token may be a colon for python compatibility79 if self.stream.current.type is 'colon':80 self.stream.next()81 95- if self.stream.current.type is 'block_end':96- self.stream.next()97- result = self.subparse(end_tokens)98- else:99- result = []100- while not self.stream.current.test_many(end_tokens):101- if self.stream.current.type is 'block_end':102- self.stream.next()103- result.extend(self.subparse(end_tokens))104- break105- result.append(self.parse_statement())82+ # in the future it would be possible to add whole code sections83+ # by adding some sort of end of statement token and parsing those here.84+ self.stream.expect('block_end')85+ result = self.subparse(end_tokens)86+87 if drop_needle:88 self.stream.next()89 return result90 48 unmodified lines139 140 def parse_extends(self):141 node = nodes.Extends(lineno=self.stream.expect('extends').lineno)142 node.template = self.parse_expression()162- self.end_statement()143 return node144 145 def parse_include(self):146 node = nodes.Include(lineno=self.stream.expect('include').lineno)12 unmodified lines159 node.template = self.parse_expression()160 else:161 node.target = None162 node.template = expr183- self.end_statement()163 return node164 165 def parse_signature(self, node):166 node.args = args = []50 unmodified lines217 while self.stream.current.type not in statement_end_tokens:218 if node.nodes:219 self.stream.expect('comma')220 node.nodes.append(self.parse_expression())242- self.end_statement()221 return node222 223 def parse_expression(self, no_condexpr=False):224 """Parse an expression."""445 unmodified linesmodified:setup.py+1 added-1 removed
129 unmodified lines130 Extension('jinja2._speedups', ['jinja2/_speedups.c'])131 ]132 )133 },134- extras_require={'i18n': ['Babel>=0.8']}134+ extras_require={'i18n': ['Babel>=0.8']},135 entry_points="""136 [babel.extractors]137 jinja2 = jinja.i18n:babel_extract[i18n]138 """1 unmodified line