Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed setup.py, a type and removed the possibility to use multiple st…

…atements per block. The latter makes it easier to write custom tags

--HG--
branch : trunk
  • Loading branch information...
commit 2b60fe5c916a34d9ac857749451e7f6ce59c67bb 1 parent 7324eb8
@mitsuhiko authored
View
1  jinja2/ext.py
@@ -34,6 +34,7 @@ def parse(self, parser):
class CacheExtension(Extension):
+ """An example extension that adds cacheable blocks."""
tags = set(['cache'])
def parse(self, parser):
View
3  jinja2/i18n.py
@@ -150,7 +150,6 @@ def parse(self, parser):
referenced.update(plural_names)
else:
parser.stream.next()
- parser.end_statement()
# register free names as simple name expressions
for var in referenced:
@@ -173,7 +172,7 @@ def parse(self, parser):
variables = nodes.Dict([nodes.Pair(nodes.Const(x, lineno=lineno), y)
for x, y in variables.items()])
else:
- vairables = None
+ variables = None
node = self._make_node(singular, plural, variables, plural_expr)
node.set_lineno(lineno)
View
5 jinja2/lexer.py
@@ -38,9 +38,8 @@
# set of used keywords
keywords = set(['and', 'block', 'elif', 'else', 'endblock', 'print',
'endfilter', 'endfor', 'endif', 'endmacro', 'endraw',
- 'extends', 'filter', 'for', 'if', 'in',
- 'include', 'is', 'macro', 'not', 'or', 'raw',
- 'recursive', 'set', 'call', 'endcall'])
+ 'extends', 'filter', 'for', 'if', 'in', 'include'
+ 'is', 'macro', 'not', 'or', 'raw', 'call', 'endcall'])
# bind operators to token types
operators = {
View
34 jinja2/parser.py
@@ -16,9 +16,7 @@
_statement_keywords = frozenset(['for', 'if', 'block', 'extends', 'print',
'macro', 'include'])
_compare_operators = frozenset(['eq', 'ne', 'lt', 'lteq', 'gt', 'gteq', 'in'])
-statement_end_tokens = set(['elif', 'else', 'endblock', 'endfilter',
- 'endfor', 'endif', 'endmacro', 'variable_end',
- 'in', 'recursive', 'endcall', 'block_end'])
+statement_end_tokens = set(['variable_end', 'block_end', 'in'])
class Parser(object):
@@ -40,15 +38,6 @@ def __init__(self, environment, source, filename=None):
for tag in extension.tags:
self.extensions[tag] = extension.parse
- def end_statement(self):
- """Make sure that the statement ends properly."""
- if self.stream.current.type is 'semicolon':
- self.stream.next()
- elif self.stream.current.type not in statement_end_tokens:
- raise TemplateSyntaxError('ambigous end of statement',
- self.stream.current.lineno,
- self.filename)
-
def parse_statement(self):
"""Parse a single statement."""
token_type = self.stream.current.type
@@ -68,7 +57,6 @@ def parse_statement(self):
result = self.parse_assign(expr)
else:
result = nodes.ExprStmt(expr, lineno=lineno)
- self.end_statement()
return result
def parse_assign(self, target):
@@ -79,7 +67,6 @@ def parse_assign(self, target):
target, target.lineno,
self.filename)
expr = self.parse_tuple()
- self.end_statement()
target.set_ctx('store')
return nodes.Assign(target, expr, lineno=lineno)
@@ -92,17 +79,11 @@ def parse_statements(self, end_tokens, drop_needle=False):
if self.stream.current.type is 'colon':
self.stream.next()
- if self.stream.current.type is 'block_end':
- self.stream.next()
- result = self.subparse(end_tokens)
- else:
- result = []
- while not self.stream.current.test_many(end_tokens):
- if self.stream.current.type is 'block_end':
- self.stream.next()
- result.extend(self.subparse(end_tokens))
- break
- result.append(self.parse_statement())
+ # in the future it would be possible to add whole code sections
+ # by adding some sort of end of statement token and parsing those here.
+ self.stream.expect('block_end')
+ result = self.subparse(end_tokens)
+
if drop_needle:
self.stream.next()
return result
@@ -159,7 +140,6 @@ def parse_block(self):
def parse_extends(self):
node = nodes.Extends(lineno=self.stream.expect('extends').lineno)
node.template = self.parse_expression()
- self.end_statement()
return node
def parse_include(self):
@@ -180,7 +160,6 @@ def parse_include(self):
else:
node.target = None
node.template = expr
- self.end_statement()
return node
def parse_signature(self, node):
@@ -239,7 +218,6 @@ def parse_print(self):
if node.nodes:
self.stream.expect('comma')
node.nodes.append(self.parse_expression())
- self.end_statement()
return node
def parse_expression(self, no_condexpr=False):
View
2  setup.py
@@ -131,7 +131,7 @@ def _unavailable(self):
]
)
},
- extras_require={'i18n': ['Babel>=0.8']}
+ extras_require={'i18n': ['Babel>=0.8']},
entry_points="""
[babel.extractors]
jinja2 = jinja.i18n:babel_extract[i18n]
Please sign in to comment.
Something went wrong with that request. Please try again.