class documentation

class Parser: (source)

View In Hierarchy

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_eof Like fail_unknown_tag but for end of template situations.
Method fail_unknown_tag 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_identifier Return a new free identifier as :class:`~jinja2.nodes.InternalName`.
Method is_tuple_end Are we at the end of a tuple?
Method parse Parse the whole template into a `Template` node.
Method parse_and Undocumented
Method parse_assign_target 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_autoescape Undocumented
Method parse_block Undocumented
Method parse_call Undocumented
Method parse_call_args Undocumented
Method parse_call_block Undocumented
Method parse_compare Undocumented
Method parse_concat Undocumented
Method parse_condexpr Undocumented
Method parse_dict Undocumented
Method parse_expression 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_extends Undocumented
Method parse_filter Undocumented
Method parse_filter_block Undocumented
Method parse_filter_expr Undocumented
Method parse_for Parse a for loop.
Method parse_from Undocumented
Method parse_if Parse an if construct.
Method parse_import Undocumented
Method parse_import_context Undocumented
Method parse_include Undocumented
Method parse_list Undocumented
Method parse_macro Undocumented
Method parse_math1 Undocumented
Method parse_math2 Undocumented
Method parse_not Undocumented
Method parse_or Undocumented
Method parse_postfix Undocumented
Method parse_pow Undocumented
Method parse_primary Undocumented
Method parse_print Undocumented
Method parse_set Parse an assign statement.
Method parse_signature Undocumented
Method parse_statement Parse a single statement.
Method parse_statements 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_subscribed Undocumented
Method parse_subscript Undocumented
Method parse_test Undocumented
Method parse_tuple 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_unary Undocumented
Method parse_with 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_ut_eof Undocumented
Instance Variable _end_token_stack Undocumented
Instance Variable _last_identifier Undocumented
Instance Variable _tag_stack Undocumented
def __init__(self, environment, source, name=None, filename=None, state=None): (source)

Undocumented

Parameters
environment:EnvironmentUndocumented
source:strUndocumented
name:t.Optional[str]Undocumented
filename:t.Optional[str]Undocumented
state:t.Optional[str]Undocumented
def fail(self, msg, lineno=None, exc=TemplateSyntaxError): (source)

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:strUndocumented
lineno:t.Optional[int]Undocumented
exc:t.Type[TemplateSyntaxError]Undocumented
Returns
te.NoReturnUndocumented
def fail_eof(self, end_tokens=None, lineno=None): (source)

Like fail_unknown_tag but for end of template situations.

Parameters
end_tokens:t.Optional[t.Tuple[str, ...]]Undocumented
lineno:t.Optional[int]Undocumented
Returns
te.NoReturnUndocumented
def fail_unknown_tag(self, name, lineno=None): (source)

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:strUndocumented
lineno:t.Optional[int]Undocumented
Returns
te.NoReturnUndocumented
def free_identifier(self, lineno=None): (source)

Return a new free identifier as :class:`~jinja2.nodes.InternalName`.

Parameters
lineno:t.Optional[int]Undocumented
Returns
nodes.InternalNameUndocumented
def is_tuple_end(self, extra_end_rules=None): (source)

Are we at the end of a tuple?

Parameters
extra_end_rules:t.Optional[t.Tuple[str, ...]]Undocumented
Returns
boolUndocumented
def parse(self): (source)

Parse the whole template into a `Template` node.

Returns
nodes.TemplateUndocumented
def parse_and(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None, with_namespace=False): (source)

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
with_tuple:boolUndocumented
name_only:boolUndocumented
extra_end_rules:t.Optional[t.Tuple[str, ...]]Undocumented
with_namespace:boolUndocumented
Returns
t.Union[nodes.NSRef, nodes.Name, nodes.Tuple]Undocumented
def parse_autoescape(self): (source)

Undocumented

Returns
nodes.ScopeUndocumented
def parse_block(self): (source)

Undocumented

Returns
nodes.BlockUndocumented
def parse_call(self, node): (source)

Undocumented

Parameters
node:nodes.ExprUndocumented
Returns
nodes.CallUndocumented
def parse_call_args(self): (source)

Undocumented

Returns
t.TupleUndocumented
def parse_call_block(self): (source)

Undocumented

Returns
nodes.CallBlockUndocumented
def parse_compare(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_concat(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_condexpr(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_dict(self): (source)

Undocumented

Returns
nodes.DictUndocumented
def parse_expression(self, with_condexpr=True): (source)

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
with_condexpr:boolUndocumented
Returns
nodes.ExprUndocumented
def parse_extends(self): (source)

Undocumented

Returns
nodes.ExtendsUndocumented
def parse_filter(self, node, start_inline=False): (source)

Undocumented

Parameters
node:t.Optional[nodes.Expr]Undocumented
start_inline:boolUndocumented
Returns
t.Optional[nodes.Expr]Undocumented
def parse_filter_block(self): (source)

Undocumented

Returns
nodes.FilterBlockUndocumented
def parse_filter_expr(self, node): (source)

Undocumented

Parameters
node:nodes.ExprUndocumented
Returns
nodes.ExprUndocumented
def parse_for(self): (source)

Parse a for loop.

Returns
nodes.ForUndocumented
def parse_from(self): (source)

Undocumented

Returns
nodes.FromImportUndocumented
def parse_if(self): (source)

Parse an if construct.

Returns
nodes.IfUndocumented
def parse_import(self): (source)

Undocumented

Returns
nodes.ImportUndocumented
def parse_import_context(self, node, default): (source)

Undocumented

Parameters
node:_ImportIncludeUndocumented
default:boolUndocumented
Returns
_ImportIncludeUndocumented
def parse_include(self): (source)

Undocumented

Returns
nodes.IncludeUndocumented
def parse_list(self): (source)

Undocumented

Returns
nodes.ListUndocumented
def parse_macro(self): (source)

Undocumented

Returns
nodes.MacroUndocumented
def parse_math1(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_math2(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_not(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_or(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_postfix(self, node): (source)

Undocumented

Parameters
node:nodes.ExprUndocumented
Returns
nodes.ExprUndocumented
def parse_pow(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_primary(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_print(self): (source)

Undocumented

Returns
nodes.OutputUndocumented
def parse_set(self): (source)

Parse an assign statement.

Returns
t.Union[nodes.Assign, nodes.AssignBlock]Undocumented
def parse_signature(self, node): (source)

Undocumented

Parameters
node:_MacroCallUndocumented
def parse_statement(self): (source)

Parse a single statement.

Returns
t.Union[nodes.Node, t.List[nodes.Node]]Undocumented
def parse_statements(self, end_tokens, drop_needle=False): (source)

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
end_tokens:t.Tuple[str, ...]Undocumented
drop_needle:boolUndocumented
Returns
t.List[nodes.Node]Undocumented
def parse_subscribed(self): (source)

Undocumented

Returns
nodes.ExprUndocumented
def parse_subscript(self, node): (source)

Undocumented

Parameters
node:nodes.ExprUndocumented
Returns
t.Union[nodes.Getattr, nodes.Getitem]Undocumented
def parse_test(self, node): (source)

Undocumented

Parameters
node:nodes.ExprUndocumented
Returns
nodes.ExprUndocumented
def parse_tuple(self, simplified=False, with_condexpr=True, extra_end_rules=None, explicit_parentheses=False): (source)

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:boolUndocumented
with_condexpr:boolUndocumented
extra_end_rules:t.Optional[t.Tuple[str, ...]]Undocumented
explicit_parentheses:boolUndocumented
Returns
t.Union[nodes.Tuple, nodes.Expr]Undocumented
def parse_unary(self, with_filter=True): (source)

Undocumented

Parameters
with_filter:boolUndocumented
Returns
nodes.ExprUndocumented
def parse_with(self): (source)

Undocumented

Returns
nodes.WithUndocumented
def subparse(self, end_tokens=None): (source)

Undocumented

Parameters
end_tokens:t.Optional[t.Tuple[str, ...]]Undocumented
Returns
t.List[nodes.Node]Undocumented
closed: bool = (source)

Undocumented

environment = (source)

Undocumented

filename = (source)

Undocumented

name = (source)

Undocumented

stream = (source)

Undocumented

def _fail_ut_eof(self, name, end_token_stack, lineno): (source)

Undocumented

Parameters
name:t.Optional[str]Undocumented
end_token_stack:t.List[t.Tuple[str, ...]]Undocumented
lineno:t.Optional[int]Undocumented
Returns
te.NoReturnUndocumented
_end_token_stack: t.List[t.Tuple[str, ...]] = (source)

Undocumented

_last_identifier: int = (source)

Undocumented

_tag_stack: t.List[str] = (source)

Undocumented