Skip to content

Commit

Permalink
fixed setup.py, a type and removed the possibility to use multiple st…
Browse files Browse the repository at this point in the history
…atements per block. The latter makes it easier to write custom tags

--HG--
branch : trunk
  • Loading branch information
mitsuhiko committed Apr 21, 2008
1 parent 7324eb8 commit 2b60fe5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 34 deletions.
1 change: 1 addition & 0 deletions jinja2/ext.py
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions jinja2/i18n.py
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions jinja2/lexer.py
Expand Up @@ -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 = {
Expand Down
34 changes: 6 additions & 28 deletions jinja2/parser.py
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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]
Expand Down

0 comments on commit 2b60fe5

Please sign in to comment.