class Parser: (source)
This is the central parsing class Jinja uses. It's passed to extensions and can be used to parse expressions or statements.
Method | __init__ |
Undocumented |
Method | fail |
Convenience method that raises `exc` with the message, passed line number or last line number as well as the current name and filename. |
Method | fail |
Like fail_unknown_tag but for end of template situations. |
Method | fail |
Called if the parser encounters an unknown tag. Tries to fail with a human readable error message that could help to identify the problem. |
Method | free |
Return a new free identifier as :class:`~jinja2.nodes.InternalName`. |
Method | is |
Are we at the end of a tuple? |
Method | parse |
Parse the whole template into a `Template` node. |
Method | parse |
Undocumented |
Method | parse |
Parse an assignment target. As Jinja allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`... |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Parse an expression. Per default all expressions are parsed, if the optional `with_condexpr` parameter is set to `False` conditional expressions are not parsed. |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Parse a for loop. |
Method | parse |
Undocumented |
Method | parse |
Parse an if construct. |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Parse an assign statement. |
Method | parse |
Undocumented |
Method | parse |
Parse a single statement. |
Method | parse |
Parse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one... |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | parse |
Works like `parse_expression` but if multiple expressions are delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created. This method could also return a regular expression instead of a tuple if no commas where found. |
Method | parse |
Undocumented |
Method | parse |
Undocumented |
Method | subparse |
Undocumented |
Instance Variable | closed |
Undocumented |
Instance Variable | environment |
Undocumented |
Instance Variable | extensions |
Undocumented |
Instance Variable | filename |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | stream |
Undocumented |
Method | _fail |
Undocumented |
Instance Variable | _end |
Undocumented |
Instance Variable | _last |
Undocumented |
Instance Variable | _tag |
Undocumented |
Undocumented
Parameters | |
environment:Environment | Undocumented |
source:str | Undocumented |
name:t.Optional[ | Undocumented |
filename:t.Optional[ | Undocumented |
state:t.Optional[ | Undocumented |
Convenience method that raises `exc` with the message, passed line number or last line number as well as the current name and filename.
Parameters | |
msg:str | Undocumented |
lineno:t.Optional[ | Undocumented |
exc:t.Type[ | Undocumented |
Returns | |
te.NoReturn | Undocumented |
Like fail_unknown_tag but for end of template situations.
Parameters | |
endt.Optional[ | Undocumented |
lineno:t.Optional[ | Undocumented |
Returns | |
te.NoReturn | Undocumented |
Called if the parser encounters an unknown tag. Tries to fail with a human readable error message that could help to identify the problem.
Parameters | |
name:str | Undocumented |
lineno:t.Optional[ | Undocumented |
Returns | |
te.NoReturn | Undocumented |
Return a new free identifier as :class:`~jinja2.nodes.InternalName`.
Parameters | |
lineno:t.Optional[ | Undocumented |
Returns | |
nodes.InternalName | Undocumented |
Are we at the end of a tuple?
Parameters | |
extrat.Optional[ | Undocumented |
Returns | |
bool | Undocumented |
Parse an assignment target. As Jinja allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. If `with_namespace` is enabled, a namespace assignment may be parsed.
Parameters | |
withbool | Undocumented |
namebool | Undocumented |
extrat.Optional[ | Undocumented |
withbool | Undocumented |
Returns | |
t.Union[ | Undocumented |
Parse an expression. Per default all expressions are parsed, if the optional `with_condexpr` parameter is set to `False` conditional expressions are not parsed.
Parameters | |
withbool | Undocumented |
Returns | |
nodes.Expr | Undocumented |
Undocumented
Parameters | |
node:t.Optional[ | Undocumented |
startbool | Undocumented |
Returns | |
t.Optional[ | Undocumented |
Undocumented
Parameters | |
node:_ImportInclude | Undocumented |
default:bool | Undocumented |
Returns | |
_ImportInclude | Undocumented |
Parse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one. Then it checks for the block end and parses until if one of the `end_tokens` is reached. Per default the active token in the stream at the end of the call is the matched end token. If this is not wanted `drop_needle` can be set to `True` and the end token is removed.
Parameters | |
endt.Tuple[ | Undocumented |
dropbool | Undocumented |
Returns | |
t.List[ | Undocumented |
Undocumented
Parameters | |
node:nodes.Expr | Undocumented |
Returns | |
t.Union[ | Undocumented |
Works like `parse_expression` but if multiple expressions are delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created. This method could also return a regular expression instead of a tuple if no commas where found. The default parsing mode is a full tuple. If `simplified` is `True` only names and literals are parsed. The `no_condexpr` parameter is forwarded to :meth:`parse_expression`. Because tuples do not require delimiters and may end in a bogus comma an extra hint is needed that marks the end of a tuple. For example for loops support tuples between `for` and `in`. In that case the `extra_end_rules` is set to ``['name:in']``. `explicit_parentheses` is true if the parsing was triggered by an expression in parentheses. This is used to figure out if an empty tuple is a valid expression or not.
Parameters | |
simplified:bool | Undocumented |
withbool | Undocumented |
extrat.Optional[ | Undocumented |
explicitbool | Undocumented |
Returns | |
t.Union[ | Undocumented |
Undocumented
Parameters | |
endt.Optional[ | Undocumented |
Returns | |
t.List[ | Undocumented |
Undocumented
Parameters | |
name:t.Optional[ | Undocumented |
endt.List[ | Undocumented |
lineno:t.Optional[ | Undocumented |
Returns | |
te.NoReturn | Undocumented |