MCPcopy Index your code
hub / github.com/nodejs/node / parse_block

Method parse_block

deps/v8/third_party/jinja2/parser.py:294–322  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

292 return nodes.Scope([node])
293
294 def parse_block(self) -> nodes.Block:
295 node = nodes.Block(lineno=next(self.stream).lineno)
296 node.name = self.stream.expect("name").value
297 node.scoped = self.stream.skip_if("name:scoped")
298 node.required = self.stream.skip_if("name:required")
299
300 # common problem people encounter when switching from django
301 # to jinja. we do not support hyphens in block names, so let's
302 # raise a nicer error message in that case.
303 if self.stream.current.type == "sub":
304 self.fail(
305 "Block names in Jinja have to be valid Python identifiers and may not"
306 " contain hyphens, use an underscore instead."
307 )
308
309 node.body = self.parse_statements(("name:endblock",), drop_needle=True)
310
311 # enforce that required blocks only contain whitespace or comments
312 # by asserting that the body, if not empty, is just TemplateData nodes
313 # with whitespace data
314 if node.required and not all(
315 isinstance(child, nodes.TemplateData) and child.data.isspace()
316 for body in node.body
317 for child in body.nodes # type: ignore
318 ):
319 self.fail("Required blocks can only contain comments or whitespace")
320
321 self.stream.skip_if("name:" + node.name)
322 return node
323
324 def parse_extends(self) -> nodes.Extends:
325 node = nodes.Extends(lineno=next(self.stream).lineno)

Callers

nothing calls this directly

Calls 5

failMethod · 0.95
parse_statementsMethod · 0.95
nextFunction · 0.50
expectMethod · 0.45
skip_ifMethod · 0.45

Tested by

no test coverage detected