MCPcopy
hub / github.com/hylang/hy / _compile_collect

Method _compile_collect

hy/compiler.py:417–464  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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):

Callers 13

compile_expressionMethod · 0.95
compile_fcomponentMethod · 0.95
compile_fstringMethod · 0.95
compile_listMethod · 0.95
compile_dictMethod · 0.95
compile_tupleMethod · 0.95
compile_index_expressionFunction · 0.80
compile_attribute_accessFunction · 0.80
compile_try_expressionFunction · 0.80
compile_function_defFunction · 0.80

Calls 6

compileMethod · 0.95
_syntax_errorMethod · 0.95
is_unpackFunction · 0.90
mangleFunction · 0.90
ResultClass · 0.85
keywordMethod · 0.80

Tested by

no test coverage detected