Lex the given sourcecode and return a generator that yields tokens as tuples in the form ``(lineno, token_type, value)``. This can be useful for :ref:`extension development ` and debugging templates. This does not perform preprocessing. If you wa
(
self,
source: str,
name: t.Optional[str] = None,
filename: t.Optional[str] = None,
)
| 617 | return Parser(self, source, name, filename).parse() |
| 618 | |
| 619 | def lex( |
| 620 | self, |
| 621 | source: str, |
| 622 | name: t.Optional[str] = None, |
| 623 | filename: t.Optional[str] = None, |
| 624 | ) -> t.Iterator[t.Tuple[int, str, str]]: |
| 625 | """Lex the given sourcecode and return a generator that yields |
| 626 | tokens as tuples in the form ``(lineno, token_type, value)``. |
| 627 | This can be useful for :ref:`extension development <writing-extensions>` |
| 628 | and debugging templates. |
| 629 | |
| 630 | This does not perform preprocessing. If you want the preprocessing |
| 631 | of the extensions to be applied you have to filter source through |
| 632 | the :meth:`preprocess` method. |
| 633 | """ |
| 634 | source = str(source) |
| 635 | try: |
| 636 | return self.lexer.tokeniter(source, name, filename) |
| 637 | except TemplateSyntaxError: |
| 638 | self.handle_exception(source=source) |
| 639 | |
| 640 | def preprocess( |
| 641 | self, |
no test coverage detected