Class: Jade::Frontend::SemanticAnalysis::Result

Inherits:
Data
  • Object
show all
Defined in:
lib/jade/frontend/semantic_analysis.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.combine(node, scope:, **children) ⇒ Object

Combine a fixed set of child Results into a parent Result. ‘children` keys must match the parent node’s ‘with` field names. Errors are unioned; the parent’s ‘scope:` is whatever the caller decides (usually the input scope or a child’s).



121
122
123
124
125
126
127
# File 'lib/jade/frontend/semantic_analysis.rb', line 121

def self.combine(node, scope:, **children)
  new(
    node: node.with(**children.transform_values(&:node)),
    errors: children.values.flat_map(&:errors),
    scope:,
  )
end

.init(node, scope) ⇒ Object



113
114
115
# File 'lib/jade/frontend/semantic_analysis.rb', line 113

def self.init(node, scope)
  new(node:, errors: [], scope:)
end

Instance Method Details

#add_errors(more) ⇒ Object



129
130
131
# File 'lib/jade/frontend/semantic_analysis.rb', line 129

def add_errors(more)
  with(errors: errors + more)
end

#map_nodeObject



133
134
135
# File 'lib/jade/frontend/semantic_analysis.rb', line 133

def map_node
  with(node: yield(node))
end

#to_resultObject



141
142
143
# File 'lib/jade/frontend/semantic_analysis.rb', line 141

def to_result
  errors.any? ? Err[errors] : Ok[node]
end

#with_scope(s) ⇒ Object



137
138
139
# File 'lib/jade/frontend/semantic_analysis.rb', line 137

def with_scope(s)
  with(scope: s)
end