Module: Jade::Frontend::SemanticAnalysis::PatternList

Extended by:
Helper, PatternList
Included in:
PatternList
Defined in:
lib/jade/frontend/semantic_analysis/pattern_list.rb

Instance Method Summary collapse

Methods included from Helper

analyze_duplicate_fields, analyze_in_parallel, analyze_in_sequence, analyze_node, bind, collect_vars, lookup, validate_type_symbol

Instance Method Details

#analyze(node, registry, scope, entry) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jade/frontend/semantic_analysis/pattern_list.rb', line 8

def analyze(node, registry, scope, entry)
  node => AST::Pattern::List(patterns:, rest:)

  patterns_r = analyze_in_sequence(patterns, registry, scope, entry)

  rest_scope, rest_errors =
    case rest
    in AST::Pattern::Binding(name:)
      bind_r = bind(patterns_r.scope, Symbol.var(name, node.range), entry)
      [bind_r.scope, bind_r.errors]

    in AST::Pattern::Wildcard | nil
      [patterns_r.scope, []]

    else
      [patterns_r.scope, [Error::InvalidListRestPattern.new(entry.name, rest.range)]]
    end

  Result
    .combine(node, scope: rest_scope, patterns: patterns_r)
    .add_errors(rest_errors)
end