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

Method parse_statement

src/jinja2/parser.py:167–194  ·  view source on GitHub ↗

Parse a single statement.

(self)

Source from the content-addressed store, hash-verified

165 return rv
166
167 def parse_statement(self) -> t.Union[nodes.Node, t.List[nodes.Node]]:
168 """Parse a single statement."""
169 token = self.stream.current
170 if token.type != "name":
171 self.fail("tag name expected", token.lineno)
172 self._tag_stack.append(token.value)
173 pop_tag = True
174 try:
175 if token.value in _statement_keywords:
176 f = getattr(self, f"parse_{self.stream.current.value}")
177 return f() # type: ignore
178 if token.value == "call":
179 return self.parse_call_block()
180 if token.value == "filter":
181 return self.parse_filter_block()
182 ext = self.extensions.get(token.value)
183 if ext is not None:
184 return ext(self)
185
186 # did not work out, remove the token we pushed by accident
187 # from the stack so that the unknown tag fail function can
188 # produce a proper error message.
189 self._tag_stack.pop()
190 pop_tag = False
191 self.fail_unknown_tag(token.value, token.lineno)
192 finally:
193 if pop_tag:
194 self._tag_stack.pop()
195
196 def parse_statements(
197 self, end_tokens: t.Tuple[str, ...], drop_needle: bool = False

Callers 1

subparseMethod · 0.95

Calls 5

failMethod · 0.95
parse_call_blockMethod · 0.95
parse_filter_blockMethod · 0.95
fail_unknown_tagMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected