Module: Jade::Frontend::ForwardDeclaration::FunctionDeclaration

Extended by:
FunctionDeclaration, Helper
Included in:
FunctionDeclaration
Defined in:
lib/jade/frontend/forward_declaration/function_declaration.rb

Instance Method Summary collapse

Methods included from Helper

deep_declare_node, figure_out_type, shallow_declare_node

Instance Method Details

#deep(node, entry, _) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jade/frontend/forward_declaration/function_declaration.rb', line 17

def deep(node, entry, _)
  node => AST::FunctionDeclaration(name:, params:, return_type:, range:)

  params
    .map { |param| param.type.then { figure_out_type(entry, it) }.map { [param.name, it] } }
    .then { Results.sequence(it) }
    .map(&:to_h)
    .and_then { |params_types| figure_out_type(entry, return_type).map { [params_types, it] } }
    .map { |params_types, return_type_type| Symbol.function(name, params_types, return_type_type, range) }
    .map { entry.define(it) }
    .then { to_declaration_result(entry, it) }
end

#shallow(node, registry, entry) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/jade/frontend/forward_declaration/function_declaration.rb', line 8

def shallow(node, registry, entry)
  node => AST::FunctionDeclaration(name:, range:)

  Symbol
    .predeclared_function(name, range)
    .then { entry.define(it) }
    .then { Result[it, []] }
end