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

Method parse_statements

src/jinja2/parser.py:196–223  ·  view source on GitHub ↗

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

(
        self, end_tokens: t.Tuple[str, ...], drop_needle: bool = False
    )

Source from the content-addressed store, hash-verified

194 self._tag_stack.pop()
195
196 def parse_statements(
197 self, end_tokens: t.Tuple[str, ...], drop_needle: bool = False
198 ) -> t.List[nodes.Node]:
199 """Parse multiple statements into a list until one of the end tokens
200 is reached. This is used to parse the body of statements as it also
201 parses template data if appropriate. The parser checks first if the
202 current token is a colon and skips it if there is one. Then it checks
203 for the block end and parses until if one of the `end_tokens` is
204 reached. Per default the active token in the stream at the end of
205 the call is the matched end token. If this is not wanted `drop_needle`
206 can be set to `True` and the end token is removed.
207 """
208 # the first token may be a colon for python compatibility
209 self.stream.skip_if("colon")
210
211 # in the future it would be possible to add whole code sections
212 # by adding some sort of end of statement token and parsing those here.
213 self.stream.expect("block_end")
214 result = self.subparse(end_tokens)
215
216 # we reached the end of the template too early, the subparser
217 # does not check for this, so we do that now
218 if self.stream.current.type == "eof":
219 self.fail_eof(end_tokens)
220
221 if drop_needle:
222 next(self.stream)
223 return result
224
225 def parse_set(self) -> t.Union[nodes.Assign, nodes.AssignBlock]:
226 """Parse an assign statement."""

Callers 12

parse_setMethod · 0.95
parse_forMethod · 0.95
parse_ifMethod · 0.95
parse_withMethod · 0.95
parse_autoescapeMethod · 0.95
parse_blockMethod · 0.95
parse_call_blockMethod · 0.95
parse_filter_blockMethod · 0.95
parse_macroMethod · 0.95
parseMethod · 0.80
parseMethod · 0.80
parseMethod · 0.80

Calls 4

subparseMethod · 0.95
fail_eofMethod · 0.95
skip_ifMethod · 0.80
expectMethod · 0.80

Tested by 2

parseMethod · 0.64
parseMethod · 0.64