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
)
| 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.""" |