Expect a given token type and return it. This accepts the same argument as :meth:`jinja2.lexer.Token.test`.
(self, expr)
| 368 | self.closed = True |
| 369 | |
| 370 | def expect(self, expr): |
| 371 | """Expect a given token type and return it. This accepts the same |
| 372 | argument as :meth:`jinja2.lexer.Token.test`. |
| 373 | """ |
| 374 | if not self.current.test(expr): |
| 375 | expr = describe_token_expr(expr) |
| 376 | if self.current.type is TOKEN_EOF: |
| 377 | raise TemplateSyntaxError('unexpected end of template, ' |
| 378 | 'expected %r.' % expr, |
| 379 | self.current.lineno, |
| 380 | self.name, self.filename) |
| 381 | raise TemplateSyntaxError("expected token %r, got %r" % |
| 382 | (expr, describe_token(self.current)), |
| 383 | self.current.lineno, |
| 384 | self.name, self.filename) |
| 385 | try: |
| 386 | return self.current |
| 387 | finally: |
| 388 | next(self) |
| 389 | |
| 390 | |
| 391 | def get_lexer(environment): |
no test coverage detected