Class: Semantic::AttrEdge

Inherits:
AttrEdgeStruct show all
Defined in:
../lib/semantic_edges.rb

Overview

The instance of the semantic function defining a value of the node.attribute

Instance Attribute Summary

Attributes inherited from AttrEdgeStruct

#dependencies, #func, #result

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) create(parent_token, child_tokens, attr_fn)

Create the AttrEdge from parent_token, RuleAlt and the AttrFn description.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File '../lib/semantic_edges.rb', line 26

def AttrEdge.create( parent_token, child_tokens, attr_fn )
  tokens = [ parent_token ].concat( child_tokens )

  dependencies = attr_fn.args.map do |ref|
    if ref.attr_idx == AttrIndexText 
      tokens[ ref.node_idx ].data 
    else
      AttrKey.new( tokens[ ref.node_idx ].object_id, ref.attr_idx )
    end
  end

  result = AttrKey.new( tokens[ attr_fn.target.node_idx ].object_id, attr_fn.target.attr_idx )

  return AttrEdge.new( dependencies, result, attr_fn.func ) 
end

Instance Method Details

- (Object) exec_func

Execute the semanitic function.



20
21
22
23
# File '../lib/semantic_edges.rb', line 20

def exec_func
  # raise "Semantic::AttrEdge is_executable? check fails" unless is_executable?
  func.call( dependencies )
end

- (Boolean) is_executable?

Return true if the AttrEdge is ready for execution (all argument values are available).

Returns:

  • (Boolean)


15
16
17
# File '../lib/semantic_edges.rb', line 15

def is_executable? 
  ( dependencies.detect { |d| d.class == AttrKey } ).nil?
end

- (Object) substitute_deps(attr_hash)

Given the { AttrKey => value } hash, replace items in :dependencies array if posible



43
44
45
46
47
48
49
50
51
52
# File '../lib/semantic_edges.rb', line 43

def substitute_deps attr_hash
  dependencies.map! do |arg|
    if arg.class == AttrKey
      attr = attr_hash.fetch( arg, nil )
      attr.nil? ? arg : attr
    else
      arg
    end
  end
end