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

View File

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

View File

@ -4,13 +4,18 @@ module Sof
#abstract base class for nodes in the tree
# may be referenced (should be a simple name or number)
class Node
def initialize referenced
@referenced = referenced
end
include Util
def initialize ref
@referenced = ref
end
# must be able to output to a stream
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
attr_reader :referenced
end
@ -22,7 +27,7 @@ module Sof
end
attr_reader :data
def out io , level
super
super(io,level)
io.write(data)
end
end

View File

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

View File

@ -42,7 +42,7 @@ module Sof
atts[a] = to_sof_node(val , level + 1)
end
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 )
node = ObjectNode.new(head , ref)
extended.each do |a , val|