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

Method parse_if

src/jinja2/parser.py:255–271  ·  view source on GitHub ↗

Parse an if construct.

(self)

Source from the content-addressed store, hash-verified

253 return nodes.For(target, iter, body, else_, test, recursive, lineno=lineno)
254
255 def parse_if(self) -> nodes.If:
256 """Parse an if construct."""
257 node = result = nodes.If(lineno=self.stream.expect("name:if").lineno)
258 while True:
259 node.test = self.parse_tuple(with_condexpr=False)
260 node.body = self.parse_statements(("name:elif", "name:else", "name:endif"))
261 node.elif_ = []
262 node.else_ = []
263 token = next(self.stream)
264 if token.test("name:elif"):
265 node = nodes.If(lineno=self.stream.current.lineno)
266 result.elif_.append(node)
267 continue
268 elif token.test("name:else"):
269 result.else_ = self.parse_statements(("name:endif",), drop_needle=True)
270 break
271 return result
272
273 def parse_with(self) -> nodes.With:
274 node = nodes.With(lineno=next(self.stream).lineno)

Callers

nothing calls this directly

Calls 4

parse_tupleMethod · 0.95
parse_statementsMethod · 0.95
expectMethod · 0.80
testMethod · 0.45

Tested by

no test coverage detected