fix the missing reference bug on class

This commit is contained in:
Torsten Ruger 2014-08-21 15:35:55 +03:00
parent 0677069fc0
commit 3915f5b7f9
4 changed files with 18 additions and 9 deletions

@ -21,7 +21,7 @@ module Sof
end end
unless occurence.referenced unless occurence.referenced
#puts "referencing #{@counter} , at level #{level}/#{occurence.level} " #puts "referencing #{@counter} , at level #{level}/#{occurence.level} "
occurence.referenced = @counter occurence.set_reference(@counter)
@counter = @counter + 1 @counter = @counter + 1
end end
return return

@ -4,13 +4,18 @@ module Sof
#abstract base class for nodes in the tree #abstract base class for nodes in the tree
# may be referenced (should be a simple name or number) # may be referenced (should be a simple name or number)
class Node class Node
def initialize referenced
@referenced = referenced
end
include Util include Util
def initialize ref
@referenced = ref
end
# must be able to output to a stream # must be able to output to a stream
def out io ,level def out io ,level
io.write "&#{referenced} " if referenced io.write "&#{@referenced} " if @referenced
end
def as_string(level)
io = StringIO.new
out(io,level)
io.string
end end
attr_reader :referenced attr_reader :referenced
end end
@ -22,7 +27,7 @@ module Sof
end end
attr_reader :data attr_reader :data
def out io , level def out io , level
super super(io,level)
io.write(data) io.write(data)
end end
end end

@ -4,9 +4,13 @@ module Sof
def initialize object , level def initialize object , level
@object = object @object = object
@level = level @level = level
@referenced = nil
end end
attr_reader :object def set_reference r
attr_accessor :level , :referenced @referenced = r
end
attr_reader :object , :referenced
attr_accessor :level
end end
end end

@ -42,7 +42,7 @@ module Sof
atts[a] = to_sof_node(val , level + 1) atts[a] = to_sof_node(val , level + 1)
end end
immediate , extended = atts.partition {|a,val| val.is_a?(SimpleNode) } immediate , extended = atts.partition {|a,val| val.is_a?(SimpleNode) }
head += immediate.collect {|a,val| "#{a.to_sof()} => #{val.data}"}.join(", ") + ")" head += immediate.collect {|a,val| "#{a.to_sof()} => #{val.as_string(level)}"}.join(", ") + ")"
return SimpleNode.new(head) if( ref.nil? and extended.empty? and head.length < 30 ) return SimpleNode.new(head) if( ref.nil? and extended.empty? and head.length < 30 )
node = ObjectNode.new(head , ref) node = ObjectNode.new(head , ref)
extended.each do |a , val| extended.each do |a , val|