parser.py
This file
Path
jinja2/parser.py
882 lines · 33.9 KiB · Python
Last changed by
Added extension ordering, this fixes #376.Armin Ronacherbefore adoption5b3f4dc
History of this fileTake it
The walk stopped after 200 commits: lines older than cb1b97f point at it.
It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 1–7why, one step back1# -*- coding: utf-8 -*-2"""3 jinja2.parser4 ~~~~~~~~~~~~~56 Implements the template parser.7It's a new yearArmin Ronacherbefore adoption55494e4
line 8why, one step back8 :copyright: (c) 2010 by the Jinja Team.It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 9–12why, one step back9 :license: BSD, see LICENSE for more details.10"""11from jinja2 import nodes12from jinja2.exceptions import TemplateSyntaxError, TemplateAssertionErrorMore Python 3 support.Armin Ronacherbefore adoptionbd35772
line 13why, one step back13from jinja2.utils import nextgreatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
line 14why, one step back14from jinja2.lexer import describe_token, describe_token_exprIt's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 15–16why, one step back1516greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
line 17why, one step back17#: statements that callinto It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 18–28why, one step back18_statement_keywords = frozenset(['for', 'if', 'block', 'extends', 'print',19 'macro', 'include', 'from', 'import',20 'set'])21_compare_operators = frozenset(['eq', 'ne', 'lt', 'lteq', 'gt', 'gteq'])222324class Parser(object):25 """This is the central parsing class Jinja2 uses. It's passed to26 extensions and can be used to parse expressions or statements.27 """28Added support for `Environment.compile_expression`.Armin Ronacherbefore adoptionba6e25a
lines 29–30why, one step back29 def __init__(self, environment, source, name=None, filename=None,30 state=None):It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 31why, one step back31 self.environment = environmentAdded support for `Environment.compile_expression`.Armin Ronacherbefore adoptionba6e25a
line 32why, one step back32 self.stream = environment._tokenize(source, name, filename, state)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 33–36why, one step back33 self.name = name34 self.filename = filename35 self.closed = False36 self.extensions = {}Added extension ordering, this fixes #376.Armin Ronacherbefore adoption5b3f4dc
line 37why, one step back37 for extension in environment.iter_extensions():It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 38–40why, one step back38 for tag in extension.tags:39 self.extensions[tag] = extension.parse40 self._last_identifier = 0greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
lines 41–42why, one step back41 self._tag_stack = []42 self._end_token_stack = []It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 43–52why, one step back4344 def fail(self, msg, lineno=None, exc=TemplateSyntaxError):45 """Convenience method that raises `exc` with the message, passed46 line number or last line number as well as the current name and47 filename.48 """49 if lineno is None:50 lineno = self.stream.current.lineno51 raise exc(msg, lineno, self.name, self.filename)52greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
lines 53–56why, one step back53 def _fail_ut_eof(self, name, end_token_stack, lineno):54 expected = []55 for exprs in end_token_stack:56 expected.extend(map(describe_token_expr, exprs))ported fix for #368 from maintenance branch.Armin Ronacherbefore adoptiondf2907e
lines 57–62why, one step back57 if end_token_stack:58 currently_looking = ' or '.join(59 "'%s'" % describe_token_expr(expr)60 for expr in end_token_stack[-1])61 else:62 currently_looking = Nonegreatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
lines 63–68why, one step back6364 if name is None:65 message = ['Unexpected end of template.']66 else:67 message = ['Encountered unknown tag \'%s\'.' % name]68ported fix for #368 from maintenance branch.Armin Ronacherbefore adoptiondf2907e
lines 69–76why, one step back69 if currently_looking:70 if name is not None and name in expected:71 message.append('You probably made a nesting mistake. Jinja '72 'is expecting this tag, but currently looking '73 'for %s.' % currently_looking)74 else:75 message.append('Jinja was looking for the following tags: '76 '%s.' % currently_looking)greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
lines 77–97why, one step back7778 if self._tag_stack:79 message.append('The innermost block that needs to be '80 'closed is \'%s\'.' % self._tag_stack[-1])8182 self.fail(' '.join(message), lineno)8384 def fail_unknown_tag(self, name, lineno=None):85 """Called if the parser encounters an unknown tag. Tries to fail86 with a human readable error message that could help to identify87 the problem.88 """89 return self._fail_ut_eof(name, self._end_token_stack, lineno)9091 def fail_eof(self, end_tokens=None, lineno=None):92 """Like fail_unknown_tag but for end of template situations."""93 stack = list(self._end_token_stack)94 if end_tokens is not None:95 stack.append(end_tokens)96 return self._fail_ut_eof(None, stack, lineno)97It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 98–115why, one step back98 def is_tuple_end(self, extra_end_rules=None):99 """Are we at the end of a tuple?"""100 if self.stream.current.type in ('variable_end', 'block_end', 'rparen'):101 return True102 elif extra_end_rules is not None:103 return self.stream.current.test_any(extra_end_rules)104 return False105106 def free_identifier(self, lineno=None):107 """Return a new free identifier as :class:`~jinja2.nodes.InternalName`."""108 self._last_identifier += 1109 rv = object.__new__(nodes.InternalName)110 nodes.Node.__init__(rv, 'fi%d' % self._last_identifier, lineno=lineno)111 return rv112113 def parse_statement(self):114 """Parse a single statement."""115 token = self.stream.currentThis commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 116why, one step back116 if token.type != 'name':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 117why, one step back117 self.fail('tag name expected', token.lineno)greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
lines 118–129why, one step back118 self._tag_stack.append(token.value)119 pop_tag = True120 try:121 if token.value in _statement_keywords:122 return getattr(self, 'parse_' + self.stream.current.value)()123 if token.value == 'call':124 return self.parse_call_block()125 if token.value == 'filter':126 return self.parse_filter_block()127 ext = self.extensions.get(token.value)128 if ext is not None:129 return ext(self)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 130why, one step back130greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
lines 131–140why, one step back131 # did not work out, remove the token we pushed by accident132 # from the stack so that the unknown tag fail function can133 # produce a proper error message.134 self._tag_stack.pop()135 pop_tag = False136 self.fail_unknown_tag(token.value, token.lineno)137 finally:138 if pop_tag:139 self._tag_stack.pop()140It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 141–158why, one step back141 def parse_statements(self, end_tokens, drop_needle=False):142 """Parse multiple statements into a list until one of the end tokens143 is reached. This is used to parse the body of statements as it also144 parses template data if appropriate. The parser checks first if the145 current token is a colon and skips it if there is one. Then it checks146 for the block end and parses until if one of the `end_tokens` is147 reached. Per default the active token in the stream at the end of148 the call is the matched end token. If this is not wanted `drop_needle`149 can be set to `True` and the end token is removed.150 """151 # the first token may be a colon for python compatibility152 self.stream.skip_if('colon')153154 # in the future it would be possible to add whole code sections155 # by adding some sort of end of statement token and parsing those here.156 self.stream.expect('block_end')157 result = self.subparse(end_tokens)158greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
lines 159–163why, one step back159 # we reached the end of the template too early, the subparser160 # does not check for this, so we do that now161 if self.stream.current.type == 'eof':162 self.fail_eof(end_tokens)163It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 164why, one step back164 if drop_needle:More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 165why, one step back165 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 166–169why, one step back166 return result167168 def parse_set(self):169 """Parse an assign statement."""More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 170why, one step back170 lineno = next(self.stream).linenoIt's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 171–187why, one step back171 target = self.parse_assign_target()172 self.stream.expect('assign')173 expr = self.parse_tuple()174 return nodes.Assign(target, expr, lineno=lineno)175176 def parse_for(self):177 """Parse a for loop."""178 lineno = self.stream.expect('name:for').lineno179 target = self.parse_assign_target(extra_end_rules=('name:in',))180 self.stream.expect('name:in')181 iter = self.parse_tuple(with_condexpr=False,182 extra_end_rules=('name:recursive',))183 test = None184 if self.stream.skip_if('name:if'):185 test = self.parse_expression()186 recursive = self.stream.skip_if('name:recursive')187 body = self.parse_statements(('name:endfor', 'name:else'))More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 188why, one step back188 if next(self.stream).value == 'endfor':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 189–201why, one step back189 else_ = []190 else:191 else_ = self.parse_statements(('name:endfor',), drop_needle=True)192 return nodes.For(target, iter, body, else_, test,193 recursive, lineno=lineno)194195 def parse_if(self):196 """Parse an if construct."""197 node = result = nodes.If(lineno=self.stream.expect('name:if').lineno)198 while 1:199 node.test = self.parse_tuple(with_condexpr=False)200 node.body = self.parse_statements(('name:elif', 'name:else',201 'name:endif'))More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 202why, one step back202 token = next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 203–216why, one step back203 if token.test('name:elif'):204 new_node = nodes.If(lineno=self.stream.current.lineno)205 node.else_ = [new_node]206 node = new_node207 continue208 elif token.test('name:else'):209 node.else_ = self.parse_statements(('name:endif',),210 drop_needle=True)211 else:212 node.else_ = []213 break214 return result215216 def parse_block(self):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 217why, one step back217 node = nodes.Block(lineno=next(self.stream).lineno)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 218why, one step back218 node.name = self.stream.expect('name').valueAdded support for optional `scoped` modifier to blocks.Armin Ronacherbefore adoption74a0cd9
line 219why, one step back219 node.scoped = self.stream.skip_if('name:scoped')Further error message improvement, this time for #341.Armin Ronacherbefore adoption92622e9
lines 220–228why, one step back220221 # common problem people encounter when switching from django222 # to jinja. we do not support hyphens in block names, so let's223 # raise a nicer error message in that case.224 if self.stream.current.type == 'sub':225 self.fail('Block names in Jinja have to be valid Python '226 'identifiers and may not contain hypens, use an '227 'underscore instead.')228It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 229–233why, one step back229 node.body = self.parse_statements(('name:endblock',), drop_needle=True)230 self.stream.skip_if('name:' + node.name)231 return node232233 def parse_extends(self):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 234why, one step back234 node = nodes.Extends(lineno=next(self.stream).lineno)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 235–240why, one step back235 node.template = self.parse_expression()236 return node237238 def parse_import_context(self, node, default):239 if self.stream.current.test_any('name:with', 'name:without') and \240 self.stream.look().test('name:context'):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 241why, one step back241 node.with_context = next(self.stream).value == 'with'It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 242–247why, one step back242 self.stream.skip()243 else:244 node.with_context = default245 return node246247 def parse_include(self):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 248why, one step back248 node = nodes.Include(lineno=next(self.stream).lineno)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 249why, one step back249 node.template = self.parse_expression()Include statements can now be marked with ``ignore missing`` to skipArmin Ronacherbefore adoption37f58ce
lines 250–255why, one step back250 if self.stream.current.test('name:ignore') and \251 self.stream.look().test('name:missing'):252 node.ignore_missing = True253 self.stream.skip(2)254 else:255 node.ignore_missing = FalseIt's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 256–258why, one step back256 return self.parse_import_context(node, True)257258 def parse_import(self):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 259why, one step back259 node = nodes.Import(lineno=next(self.stream).lineno)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 260–265why, one step back260 node.template = self.parse_expression()261 self.stream.expect('name:as')262 node.target = self.parse_assign_target(name_only=True).name263 return self.parse_import_context(node, False)264265 def parse_from(self):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 266why, one step back266 node = nodes.FromImport(lineno=next(self.stream).lineno)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 267–273why, one step back267 node.template = self.parse_expression()268 self.stream.expect('name:import')269 node.names = []270271 def parse_context():272 if self.stream.current.value in ('with', 'without') and \273 self.stream.look().test('name:context'):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 274why, one step back274 node.with_context = next(self.stream).value == 'with'It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 275–281why, one step back275 self.stream.skip()276 return True277 return False278279 while 1:280 if node.names:281 self.stream.expect('comma')This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 282why, one step back282 if self.stream.current.type == 'name':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 283–294why, one step back283 if parse_context():284 break285 target = self.parse_assign_target(name_only=True)286 if target.name.startswith('_'):287 self.fail('names starting with an underline can not '288 'be imported', target.lineno,289 exc=TemplateAssertionError)290 if self.stream.skip_if('name:as'):291 alias = self.parse_assign_target(name_only=True)292 node.names.append((target.name, alias.name))293 else:294 node.names.append(target.name)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 295why, one step back295 if parse_context() or self.stream.current.type != 'comma':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 296–307why, one step back296 break297 else:298 break299 if not hasattr(node, 'with_context'):300 node.with_context = False301 self.stream.skip_if('comma')302 return node303304 def parse_signature(self, node):305 node.args = args = []306 node.defaults = defaults = []307 self.stream.expect('lparen')This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 308why, one step back308 while self.stream.current.type != 'rparen':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 309–318why, one step back309 if args:310 self.stream.expect('comma')311 arg = self.parse_assign_target(name_only=True)312 arg.set_ctx('param')313 if self.stream.skip_if('assign'):314 defaults.append(self.parse_expression())315 args.append(arg)316 self.stream.expect('rparen')317318 def parse_call_block(self):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 319why, one step back319 node = nodes.CallBlock(lineno=next(self.stream).lineno)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 320why, one step back320 if self.stream.current.type == 'lparen':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 321–332why, one step back321 self.parse_signature(node)322 else:323 node.args = []324 node.defaults = []325326 node.call = self.parse_expression()327 if not isinstance(node.call, nodes.Call):328 self.fail('expected call', node.lineno)329 node.body = self.parse_statements(('name:endcall',), drop_needle=True)330 return node331332 def parse_filter_block(self):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 333why, one step back333 node = nodes.FilterBlock(lineno=next(self.stream).lineno)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 334–339why, one step back334 node.filter = self.parse_filter(None, start_inline=True)335 node.body = self.parse_statements(('name:endfilter',),336 drop_needle=True)337 return node338339 def parse_macro(self):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 340why, one step back340 node = nodes.Macro(lineno=next(self.stream).lineno)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 341–347why, one step back341 node.name = self.parse_assign_target(name_only=True).name342 self.parse_signature(node)343 node.body = self.parse_statements(('name:endmacro',),344 drop_needle=True)345 return node346347 def parse_print(self):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 348why, one step back348 node = nodes.Output(lineno=next(self.stream).lineno)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 349why, one step back349 node.nodes = []This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 350why, one step back350 while self.stream.current.type != 'block_end':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 351–412why, one step back351 if node.nodes:352 self.stream.expect('comma')353 node.nodes.append(self.parse_expression())354 return node355356 def parse_assign_target(self, with_tuple=True, name_only=False,357 extra_end_rules=None):358 """Parse an assignment target. As Jinja2 allows assignments to359 tuples, this function can parse all allowed assignment targets. Per360 default assignments to tuples are parsed, that can be disable however361 by setting `with_tuple` to `False`. If only assignments to names are362 wanted `name_only` can be set to `True`. The `extra_end_rules`363 parameter is forwarded to the tuple parsing function.364 """365 if name_only:366 token = self.stream.expect('name')367 target = nodes.Name(token.value, 'store', lineno=token.lineno)368 else:369 if with_tuple:370 target = self.parse_tuple(simplified=True,371 extra_end_rules=extra_end_rules)372 else:373 target = self.parse_primary(with_postfix=False)374 target.set_ctx('store')375 if not target.can_assign():376 self.fail('can\'t assign to %r' % target.__class__.377 __name__.lower(), target.lineno)378 return target379380 def parse_expression(self, with_condexpr=True):381 """Parse an expression. Per default all expressions are parsed, if382 the optional `with_condexpr` parameter is set to `False` conditional383 expressions are not parsed.384 """385 if with_condexpr:386 return self.parse_condexpr()387 return self.parse_or()388389 def parse_condexpr(self):390 lineno = self.stream.current.lineno391 expr1 = self.parse_or()392 while self.stream.skip_if('name:if'):393 expr2 = self.parse_or()394 if self.stream.skip_if('name:else'):395 expr3 = self.parse_condexpr()396 else:397 expr3 = None398 expr1 = nodes.CondExpr(expr2, expr1, expr3, lineno=lineno)399 lineno = self.stream.current.lineno400 return expr1401402 def parse_or(self):403 lineno = self.stream.current.lineno404 left = self.parse_and()405 while self.stream.skip_if('name:or'):406 right = self.parse_and()407 left = nodes.Or(left, right, lineno=lineno)408 lineno = self.stream.current.lineno409 return left410411 def parse_and(self):412 lineno = self.stream.current.linenoPriority of `not` raised. It's now possible to write `not foo in bar`Armin Ronacherbefore adoptiond89f0f3
line 413why, one step back413 left = self.parse_not()It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 414why, one step back414 while self.stream.skip_if('name:and'):Priority of `not` raised. It's now possible to write `not foo in bar`Armin Ronacherbefore adoptiond89f0f3
line 415why, one step back415 right = self.parse_not()It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 416–419why, one step back416 left = nodes.And(left, right, lineno=lineno)417 lineno = self.stream.current.lineno418 return left419Priority of `not` raised. It's now possible to write `not foo in bar`Armin Ronacherbefore adoptiond89f0f3
lines 420–421why, one step back420 def parse_not(self):421 if self.stream.current.test('name:not'):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 422why, one step back422 lineno = next(self.stream).linenoPriority of `not` raised. It's now possible to write `not foo in bar`Armin Ronacherbefore adoptiond89f0f3
lines 423–425why, one step back423 return nodes.Not(self.parse_not(), lineno=lineno)424 return self.parse_compare()425It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 426–432why, one step back426 def parse_compare(self):427 lineno = self.stream.current.lineno428 expr = self.parse_add()429 ops = []430 while 1:431 token_type = self.stream.current.type432 if token_type in _compare_operators:More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 433why, one step back433 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 434–450why, one step back434 ops.append(nodes.Operand(token_type, self.parse_add()))435 elif self.stream.skip_if('name:in'):436 ops.append(nodes.Operand('in', self.parse_add()))437 elif self.stream.current.test('name:not') and \438 self.stream.look().test('name:in'):439 self.stream.skip(2)440 ops.append(nodes.Operand('notin', self.parse_add()))441 else:442 break443 lineno = self.stream.current.lineno444 if not ops:445 return expr446 return nodes.Compare(expr, ops, lineno=lineno)447448 def parse_add(self):449 lineno = self.stream.current.lineno450 left = self.parse_sub()This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 451why, one step back451 while self.stream.current.type == 'add':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 452why, one step back452 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 453–460why, one step back453 right = self.parse_sub()454 left = nodes.Add(left, right, lineno=lineno)455 lineno = self.stream.current.lineno456 return left457458 def parse_sub(self):459 lineno = self.stream.current.lineno460 left = self.parse_concat()This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 461why, one step back461 while self.stream.current.type == 'sub':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 462why, one step back462 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 463–470why, one step back463 right = self.parse_concat()464 left = nodes.Sub(left, right, lineno=lineno)465 lineno = self.stream.current.lineno466 return left467468 def parse_concat(self):469 lineno = self.stream.current.lineno470 args = [self.parse_mul()]This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 471why, one step back471 while self.stream.current.type == 'tilde':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 472why, one step back472 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 473–480why, one step back473 args.append(self.parse_mul())474 if len(args) == 1:475 return args[0]476 return nodes.Concat(args, lineno=lineno)477478 def parse_mul(self):479 lineno = self.stream.current.lineno480 left = self.parse_div()This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 481why, one step back481 while self.stream.current.type == 'mul':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 482why, one step back482 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 483–490why, one step back483 right = self.parse_div()484 left = nodes.Mul(left, right, lineno=lineno)485 lineno = self.stream.current.lineno486 return left487488 def parse_div(self):489 lineno = self.stream.current.lineno490 left = self.parse_floordiv()This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 491why, one step back491 while self.stream.current.type == 'div':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 492why, one step back492 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 493–500why, one step back493 right = self.parse_floordiv()494 left = nodes.Div(left, right, lineno=lineno)495 lineno = self.stream.current.lineno496 return left497498 def parse_floordiv(self):499 lineno = self.stream.current.lineno500 left = self.parse_mod()This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 501why, one step back501 while self.stream.current.type == 'floordiv':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 502why, one step back502 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 503–510why, one step back503 right = self.parse_mod()504 left = nodes.FloorDiv(left, right, lineno=lineno)505 lineno = self.stream.current.lineno506 return left507508 def parse_mod(self):509 lineno = self.stream.current.lineno510 left = self.parse_pow()This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 511why, one step back511 while self.stream.current.type == 'mod':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 512why, one step back512 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 513–520why, one step back513 right = self.parse_pow()514 left = nodes.Mod(left, right, lineno=lineno)515 lineno = self.stream.current.lineno516 return left517518 def parse_pow(self):519 lineno = self.stream.current.lineno520 left = self.parse_unary()This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 521why, one step back521 while self.stream.current.type == 'pow':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 522why, one step back522 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 523–530why, one step back523 right = self.parse_unary()524 left = nodes.Pow(left, right, lineno=lineno)525 lineno = self.stream.current.lineno526 return left527528 def parse_unary(self):529 token_type = self.stream.current.type530 lineno = self.stream.current.linenoThis commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 531why, one step back531 if token_type == 'sub':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 532why, one step back532 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 533–534why, one step back533 node = self.parse_unary()534 return nodes.Neg(node, lineno=lineno)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 535why, one step back535 if token_type == 'add':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 536why, one step back536 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 537–542why, one step back537 node = self.parse_unary()538 return nodes.Pos(node, lineno=lineno)539 return self.parse_primary()540541 def parse_primary(self, with_postfix=True):542 token = self.stream.currentThis commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 543why, one step back543 if token.type == 'name':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 544–550why, one step back544 if token.value in ('true', 'false', 'True', 'False'):545 node = nodes.Const(token.value in ('true', 'True'),546 lineno=token.lineno)547 elif token.value in ('none', 'None'):548 node = nodes.Const(None, lineno=token.lineno)549 else:550 node = nodes.Name(token.value, 'load', lineno=token.lineno)More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 551why, one step back551 next(self.stream)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 552why, one step back552 elif token.type == 'string':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 553why, one step back553 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 554–555why, one step back554 buf = [token.value]555 lineno = token.linenoThis commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 556why, one step back556 while self.stream.current.type == 'string':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 557why, one step back557 buf.append(self.stream.current.value)More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 558why, one step back558 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 559–560why, one step back559 node = nodes.Const(''.join(buf), lineno=lineno)560 elif token.type in ('integer', 'float'):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 561why, one step back561 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 562why, one step back562 node = nodes.Const(token.value, lineno=token.lineno)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 563why, one step back563 elif token.type == 'lparen':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 564why, one step back564 next(self.stream)implicit tuple expressions can no longer be totally empty.Armin Ronacherbefore adoptione614e88
line 565why, one step back565 node = self.parse_tuple(explicit_parentheses=True)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 566why, one step back566 self.stream.expect('rparen')This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 567why, one step back567 elif token.type == 'lbracket':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 568why, one step back568 node = self.parse_list()This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 569why, one step back569 elif token.type == 'lbrace':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 570–571why, one step back570 node = self.parse_dict()571 else:greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
line 572why, one step back572 self.fail("unexpected '%s'" % describe_token(token), token.lineno)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 573–577why, one step back573 if with_postfix:574 node = self.parse_postfix(node)575 return node576577 def parse_tuple(self, simplified=False, with_condexpr=True,implicit tuple expressions can no longer be totally empty.Armin Ronacherbefore adoptione614e88
line 578why, one step back578 extra_end_rules=None, explicit_parentheses=False):It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 579–591why, one step back579 """Works like `parse_expression` but if multiple expressions are580 delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created.581 This method could also return a regular expression instead of a tuple582 if no commas where found.583584 The default parsing mode is a full tuple. If `simplified` is `True`585 only names and literals are parsed. The `no_condexpr` parameter is586 forwarded to :meth:`parse_expression`.587588 Because tuples do not require delimiters and may end in a bogus comma589 an extra hint is needed that marks the end of a tuple. For example590 for loops support tuples between `for` and `in`. In that case the591 `extra_end_rules` is set to ``['name:in']``.implicit tuple expressions can no longer be totally empty.Armin Ronacherbefore adoptione614e88
lines 592–595why, one step back592593 `explicit_parentheses` is true if the parsing was triggered by an594 expression in parentheses. This is used to figure out if an empty595 tuple is a valid expression or not.It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 596–611why, one step back596 """597 lineno = self.stream.current.lineno598 if simplified:599 parse = lambda: self.parse_primary(with_postfix=False)600 elif with_condexpr:601 parse = self.parse_expression602 else:603 parse = lambda: self.parse_expression(with_condexpr=False)604 args = []605 is_tuple = False606 while 1:607 if args:608 self.stream.expect('comma')609 if self.is_tuple_end(extra_end_rules):610 break611 args.append(parse())This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 612why, one step back612 if self.stream.current.type == 'comma':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 613–616why, one step back613 is_tuple = True614 else:615 break616 lineno = self.stream.current.linenoimplicit tuple expressions can no longer be totally empty.Armin Ronacherbefore adoptione614e88
lines 617–629why, one step back617618 if not is_tuple:619 if args:620 return args[0]621622 # if we don't have explicit parentheses, an empty tuple is623 # not a valid expression. This would mean nothing (literally624 # nothing) in the spot of an expression would be an empty625 # tuple.626 if not explicit_parentheses:627 self.fail('Expected an expression, got \'%s\'' %628 describe_token(self.stream.current))629It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 630–634why, one step back630 return nodes.Tuple(args, 'load', lineno=lineno)631632 def parse_list(self):633 token = self.stream.expect('lbracket')634 items = []This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 635why, one step back635 while self.stream.current.type != 'rbracket':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 636–646why, one step back636 if items:637 self.stream.expect('comma')638 if self.stream.current.type == 'rbracket':639 break640 items.append(self.parse_expression())641 self.stream.expect('rbracket')642 return nodes.List(items, lineno=token.lineno)643644 def parse_dict(self):645 token = self.stream.expect('lbrace')646 items = []This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 647why, one step back647 while self.stream.current.type != 'rbrace':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 648–661why, one step back648 if items:649 self.stream.expect('comma')650 if self.stream.current.type == 'rbrace':651 break652 key = self.parse_expression()653 self.stream.expect('colon')654 value = self.parse_expression()655 items.append(nodes.Pair(key, value, lineno=key.lineno))656 self.stream.expect('rbrace')657 return nodes.Dict(items, lineno=token.lineno)658659 def parse_postfix(self, node):660 while 1:661 token_type = self.stream.current.typeThis commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 662why, one step back662 if token_type == 'dot' or token_type == 'lbracket':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 663why, one step back663 node = self.parse_subscript(node)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 664why, one step back664 elif token_type == 'lparen':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 665why, one step back665 node = self.parse_call(node)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 666why, one step back666 elif token_type == 'pipe':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 667why, one step back667 node = self.parse_filter(node)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 668why, one step back668 elif token_type == 'name' and self.stream.current.value == 'is':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 669–674why, one step back669 node = self.parse_test(node)670 else:671 break672 return node673674 def parse_subscript(self, node):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 675why, one step back675 token = next(self.stream)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 676why, one step back676 if token.type == 'dot':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 677why, one step back677 attr_token = self.stream.currentMore Python 3 support.Armin Ronacherbefore adoptionbd35772
line 678why, one step back678 next(self.stream)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 679why, one step back679 if attr_token.type == 'name':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 680–681why, one step back680 return nodes.Getattr(node, attr_token.value, 'load',681 lineno=token.lineno)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 682why, one step back682 elif attr_token.type != 'integer':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 683–685why, one step back683 self.fail('expected name or number', attr_token.lineno)684 arg = nodes.Const(attr_token.value, lineno=attr_token.lineno)685 return nodes.Getitem(node, arg, 'load', lineno=token.lineno)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 686why, one step back686 if token.type == 'lbracket':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 687–688why, one step back687 priority_on_attribute = False688 args = []This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 689why, one step back689 while self.stream.current.type != 'rbracket':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 690–696why, one step back690 if args:691 self.stream.expect('comma')692 args.append(self.parse_subscribed())693 self.stream.expect('rbracket')694 if len(args) == 1:695 arg = args[0]696 else:Fixed a bug in the parser that made ``{{ foo[1, 2] }}`` impossible.Armin Ronacherbefore adoptionee2d3c4
line 697why, one step back697 arg = nodes.Tuple(args, 'load', lineno=token.lineno)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 698–703why, one step back698 return nodes.Getitem(node, arg, 'load', lineno=token.lineno)699 self.fail('expected subscript expression', self.lineno)700701 def parse_subscribed(self):702 lineno = self.stream.current.lineno703This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 704why, one step back704 if self.stream.current.type == 'colon':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 705why, one step back705 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 706–708why, one step back706 args = [None]707 else:708 node = self.parse_expression()This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 709why, one step back709 if self.stream.current.type != 'colon':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 710why, one step back710 return nodeMore Python 3 support.Armin Ronacherbefore adoptionbd35772
line 711why, one step back711 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 712–713why, one step back712 args = [node]713This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 714why, one step back714 if self.stream.current.type == 'colon':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 715–720why, one step back715 args.append(None)716 elif self.stream.current.type not in ('rbracket', 'comma'):717 args.append(self.parse_expression())718 else:719 args.append(None)720This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 721why, one step back721 if self.stream.current.type == 'colon':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 722why, one step back722 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 723–743why, one step back723 if self.stream.current.type not in ('rbracket', 'comma'):724 args.append(self.parse_expression())725 else:726 args.append(None)727 else:728 args.append(None)729730 return nodes.Slice(lineno=lineno, *args)731732 def parse_call(self, node):733 token = self.stream.expect('lparen')734 args = []735 kwargs = []736 dyn_args = dyn_kwargs = None737 require_comma = False738739 def ensure(expr):740 if not expr:741 self.fail('invalid syntax for function call expression',742 token.lineno)743This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 744why, one step back744 while self.stream.current.type != 'rparen':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 745–747why, one step back745 if require_comma:746 self.stream.expect('comma')747 # support for trailing commaThis commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 748why, one step back748 if self.stream.current.type == 'rparen':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 749why, one step back749 breakThis commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 750why, one step back750 if self.stream.current.type == 'mul':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 751why, one step back751 ensure(dyn_args is None and dyn_kwargs is None)More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 752why, one step back752 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 753why, one step back753 dyn_args = self.parse_expression()This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 754why, one step back754 elif self.stream.current.type == 'pow':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 755why, one step back755 ensure(dyn_kwargs is None)More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 756why, one step back756 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 757–759why, one step back757 dyn_kwargs = self.parse_expression()758 else:759 ensure(dyn_args is None and dyn_kwargs is None)This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
lines 760–761why, one step back760 if self.stream.current.type == 'name' and \761 self.stream.look().type == 'assign':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 762–781why, one step back762 key = self.stream.current.value763 self.stream.skip(2)764 value = self.parse_expression()765 kwargs.append(nodes.Keyword(key, value,766 lineno=value.lineno))767 else:768 ensure(not kwargs)769 args.append(self.parse_expression())770771 require_comma = True772 self.stream.expect('rparen')773774 if node is None:775 return args, kwargs, dyn_args, dyn_kwargs776 return nodes.Call(node, args, kwargs, dyn_args, dyn_kwargs,777 lineno=token.lineno)778779 def parse_filter(self, node, start_inline=False):780 while self.stream.current.type == 'pipe' or start_inline:781 if not start_inline:More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 782why, one step back782 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 783–784why, one step back783 token = self.stream.expect('name')784 name = token.valueThis commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 785why, one step back785 while self.stream.current.type == 'dot':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 786why, one step back786 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 787why, one step back787 name += '.' + self.stream.expect('name').valueThis commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 788why, one step back788 if self.stream.current.type == 'lparen':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 789–799why, one step back789 args, kwargs, dyn_args, dyn_kwargs = self.parse_call(None)790 else:791 args = []792 kwargs = []793 dyn_args = dyn_kwargs = None794 node = nodes.Filter(node, name, args, kwargs, dyn_args,795 dyn_kwargs, lineno=token.lineno)796 start_inline = False797 return node798799 def parse_test(self, node):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 800why, one step back800 token = next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 801why, one step back801 if self.stream.current.test('name:not'):More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 802why, one step back802 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 803–806why, one step back803 negated = True804 else:805 negated = False806 name = self.stream.expect('name').valueThis commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 807why, one step back807 while self.stream.current.type == 'dot':More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 808why, one step back808 next(self.stream)It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 809–811why, one step back809 name += '.' + self.stream.expect('name').value810 dyn_args = dyn_kwargs = None811 kwargs = []This commit makes the parser and lexer use regular string comparison to support jythonAli Afsharbefore adoption272ca2a
line 812why, one step back812 if self.stream.current.type == 'lparen':It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 813–834why, one step back813 args, kwargs, dyn_args, dyn_kwargs = self.parse_call(None)814 elif self.stream.current.type in ('name', 'string', 'integer',815 'float', 'lparen', 'lbracket',816 'lbrace') and not \817 self.stream.current.test_any('name:else', 'name:or',818 'name:and'):819 if self.stream.current.test('name:is'):820 self.fail('You cannot chain multiple tests with is')821 args = [self.parse_expression()]822 else:823 args = []824 node = nodes.Test(node, name, args, kwargs, dyn_args,825 dyn_kwargs, lineno=token.lineno)826 if negated:827 node = nodes.Not(node, lineno=token.lineno)828 return node829830 def subparse(self, end_tokens=None):831 body = []832 data_buffer = []833 add_data = data_buffer.append834greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
lines 835–837why, one step back835 if end_tokens is not None:836 self._end_token_stack.append(end_tokens)837It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 838–843why, one step back838 def flush_data():839 if data_buffer:840 lineno = data_buffer[0].lineno841 body.append(nodes.Output(data_buffer[:], lineno=lineno))842 del data_buffer[:]843greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
lines 844–867why, one step back844 try:845 while self.stream:846 token = self.stream.current847 if token.type == 'data':848 if token.value:849 add_data(nodes.TemplateData(token.value,850 lineno=token.lineno))851 next(self.stream)852 elif token.type == 'variable_begin':853 next(self.stream)854 add_data(self.parse_tuple(with_condexpr=True))855 self.stream.expect('variable_end')856 elif token.type == 'block_begin':857 flush_data()858 next(self.stream)859 if end_tokens is not None and \860 self.stream.current.test_any(*end_tokens):861 return body862 rv = self.parse_statement()863 if isinstance(rv, list):864 body.extend(rv)865 else:866 body.append(rv)867 self.stream.expect('block_end')It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 868why, one step back868 else:greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
line 869why, one step back869 raise AssertionError('internal parsing error')It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
line 870why, one step back870greatly improved error message reporting. This fixes #339Armin Ronacherbefore adoption5dcb724
lines 871–875why, one step back871 flush_data()872 finally:873 if end_tokens is not None:874 self._end_token_stack.pop()875It's now possible to use ``{{ foo.0.0 }}``Armin Ronacherbefore adoptioncb1b97f
lines 876–882why, one step back876 return body877878 def parse(self):879 """Parse the whole template into a `Template` node."""880 result = nodes.Template(self.subparse(), lineno=1)881 result.set_environment(self.environment)882 return result