Collect the expression contexts from a list of compiled expression. This returns a list of the expression contexts, and the sum of the Result objects passed as arguments.
(self, exprs, with_kwargs=False, dict_display=False)
| 415 | raise HySyntaxError(message, expr, self.filename, self.source) |
| 416 | |
| 417 | def _compile_collect(self, exprs, with_kwargs=False, dict_display=False): |
| 418 | """Collect the expression contexts from a list of compiled expression. |
| 419 | |
| 420 | This returns a list of the expression contexts, and the sum of the |
| 421 | Result objects passed as arguments. |
| 422 | |
| 423 | """ |
| 424 | compiled_exprs = [] |
| 425 | ret = Result() |
| 426 | keywords = [] |
| 427 | |
| 428 | exprs_iter = iter(exprs) |
| 429 | for expr in exprs_iter: |
| 430 | |
| 431 | if is_unpack("mapping", expr): |
| 432 | ret += self.compile(expr[1]) |
| 433 | if dict_display: |
| 434 | compiled_exprs.append(None) |
| 435 | compiled_exprs.append(ret.force_expr) |
| 436 | elif with_kwargs: |
| 437 | keywords.append(asty.keyword(expr, arg=None, value=ret.force_expr)) |
| 438 | |
| 439 | elif with_kwargs and isinstance(expr, Keyword): |
| 440 | try: |
| 441 | value = next(exprs_iter) |
| 442 | except StopIteration: |
| 443 | raise self._syntax_error( |
| 444 | expr, "Keyword argument {kw} needs a value.".format(kw=expr) |
| 445 | ) |
| 446 | |
| 447 | if not expr: |
| 448 | raise self._syntax_error( |
| 449 | expr, "Can't call a function with the empty keyword" |
| 450 | ) |
| 451 | |
| 452 | compiled_value = self.compile(value) |
| 453 | ret += compiled_value |
| 454 | |
| 455 | arg = str(expr)[1:] |
| 456 | keywords.append( |
| 457 | asty.keyword(expr, arg=mangle(arg), value=compiled_value.force_expr) |
| 458 | ) |
| 459 | |
| 460 | else: |
| 461 | ret += self.compile(expr) |
| 462 | compiled_exprs.append(ret.force_expr) |
| 463 | |
| 464 | return compiled_exprs, ret, keywords |
| 465 | |
| 466 | @builds_model(Lazy) |
| 467 | def _compile_branch(self, exprs): |
no test coverage detected