MCPcopy
hub / github.com/pallets/jinja / lex

Method lex

src/jinja2/environment.py:624–643  ·  view source on GitHub ↗

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 <writing-extensions>` and debugging templates. This does not perform preprocessing. If you wa

(
        self,
        source: str,
        name: t.Optional[str] = None,
        filename: t.Optional[str] = None,
    )

Source from the content-addressed store, hash-verified

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

Callers 2

babel_extractFunction · 0.95

Calls 2

handle_exceptionMethod · 0.95
tokeniterMethod · 0.80

Tested by 1