Module: Jade::Frontend::Desugaring::Placeholder

Extended by:
Codegen::Helpers, Placeholder
Included in:
Placeholder
Defined in:
lib/jade/frontend/desugaring/placeholder.rb

Constant Summary

Constants included from Codegen::Helpers

Codegen::Helpers::NATIVE_RUBY_CLASSES

Instance Method Summary collapse

Methods included from Codegen::Helpers

data_define, dict_constraints, dict_synthetic_name, fn_constraints, fn_impl_synthetic_name, generate_many, generate_node, impl_synthetic_name, param_synthetic_name, resolve_callee_symbol, ruby_classes_for_type, to_qualified

Instance Method Details

#lift(call) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jade/frontend/desugaring/placeholder.rb', line 10

def lift(call)
  return call unless call.args.any?(AST::Placeholder)

  filled_args, names = call
    .args
    .reduce([[], []]) do |(args, names), arg|
      case arg
      in AST::Placeholder
        param_synthetic_name(names.size)
          .then { [args + [AST::VariableReference[it, nil]], names + [it]] }

      else
        [args + [arg], names]
      end
  end

  names
    .reverse
    .reduce(call.with(args: filled_args)) do |body, name|
      AST::Lambda[
        [AST::Pattern::Binding[name, nil]],
        AST::Body[[body], nil],
        call.range,
      ]
    end
end