module Sfp::SfpLangHelper
Attributes
arrays[R]
conformant[R]
constraint_next_id[RW]
home_dir[RW]
root[R]
root_dir[RW]
used_classes[R]
Public Instance Methods
create_constraint(name, type='and')
click to toggle source
# File lib/sfp/Sfplib.rb, line 42 def create_constraint(name, type='and') return { '_self' => name, '_context' => 'constraint', '_type' => type, '_parent' => @now } end
deep_clone(value)
click to toggle source
# File lib/sfp/Sfplib.rb, line 108 def deep_clone(value) Sfp::Helper.deep_clone(value) end
expand_class(c)
click to toggle source
# File lib/sfp/Sfplib.rb, line 85 def expand_class(c) sclass = @root.at?(c['_extends']) c.inherits( sclass ) c['_super'] = (sclass.has_key?('_super') ? sclass['_super'].clone : Array.new) c['_super'] << c['_extends'] if sclass['_finals'].is_a?(Array) if c['_finals'].is_a?(Array) c['_finals'].concat(sclass['_finals']) else c['_finals'] = sclass['_finals'] end end end
expand_classes()
click to toggle source
# File lib/sfp/Sfplib.rb, line 99 def expand_classes @unexpanded_classes.each { |c| expand_class(c) } end
expand_object(obj)
click to toggle source
# File lib/sfp/Sfplib.rb, line 103 def expand_object(obj) return false if not Sfp::Helper.expand_object(obj, @root) @used_classes = @used_classes.concat(obj['_classes']).uniq end
finalize()
click to toggle source
# File lib/sfp/Sfplib.rb, line 16 def finalize #@root.keys.each { |k| # next if k[0,1] == '_' or !@root[k].is_a?(Hash) # @root.delete(k) if @root[k]['_context'] == 'abstract' #} end
goto_parent(remove_parent=false)
click to toggle source
# File lib/sfp/Sfplib.rb, line 78 def goto_parent(remove_parent=false) n = @now @now = @now['_parent'] n.delete('_parent') if remove_parent return n end
init()
click to toggle source
# File lib/sfp/Sfplib.rb, line 6 def init @root = Hash.new @now = @root @root['Object'] = { '_self' => 'Object', '_context' => 'class', '_parent' => @root } @unexpanded_classes = Array.new @used_classes = Array.new @arrays = Hash.new @conformant = false end
next_id()
click to toggle source
# File lib/sfp/Sfplib.rb, line 23 def next_id nid = "c#{@constraint_next_id}" @constraint_next_id += 1 return nid end
null_value(isa=nil)
click to toggle source
# File lib/sfp/Sfplib.rb, line 29 def null_value(isa=nil) return { '_context' => 'null', '_isa' => isa } end
process_file(file)
click to toggle source
# File lib/sfp/Sfplib.rb, line 50 def process_file(file) filepath = file filepath = @root_dir + "/" + file if not @root_dir.nil? and file[0,1] != '/' filepath = @home_dir + "/" + file if not @home_dir.nil? and not File.exist?(filepath) raise Exception, 'File not found: ' + file if not File.exist?(filepath) parser = Sfp::Parser.new({ :root_dir => @root_dir, :home_dir => File.expand_path(File.dirname(filepath)), :constraint_next_id => @constraint_next_id }) parser.parse(File.read(filepath), {:keep_abstract => true}) parser.root.each_pair do |key,val| if val.is_a?(Hash) if val['_context'] == 'state' and @root.has_key?(key) and @root[key]['_context'] == 'state' val.each_pair { |k2,v2| @root[key][k2] = v2 if k2[0,1] != '_' } elsif val['_context'] == 'constraint' and @root.has_key?(key) and @root[key]['_context'] == 'constraint' val.each_pair { |k2,v2| @root[key][k2] = v2 if k2[0,1] != '_' } else @root[key] = val val['_parent'] = @root if val['_context'] != 'state' end else @root[key] = val end end @constraint_next_id = parser.constraint_next_id end
to_ref(path)
click to toggle source
# File lib/sfp/Sfplib.rb, line 33 def to_ref(path) ref = "$." + path return ref end
to_sfp()
click to toggle source
# File lib/sfp/Sfplib.rb, line 38 def to_sfp return @root end