Module: Sfp::SfpLangHelper

Included in:
SfpLang::Parser
Defined in:
lib/sfp/Sfplib.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#arraysObject (readonly)

Returns the value of attribute arrays.



4
5
6
# File 'lib/sfp/Sfplib.rb', line 4

def arrays
  @arrays
end

#conformantObject (readonly)

Returns the value of attribute conformant.



4
5
6
# File 'lib/sfp/Sfplib.rb', line 4

def conformant
  @conformant
end

#constraint_next_idObject

Returns the value of attribute constraint_next_id.



3
4
5
# File 'lib/sfp/Sfplib.rb', line 3

def constraint_next_id
  @constraint_next_id
end

#home_dirObject

Returns the value of attribute home_dir.



3
4
5
# File 'lib/sfp/Sfplib.rb', line 3

def home_dir
  @home_dir
end

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/sfp/Sfplib.rb', line 4

def root
  @root
end

#root_dirObject

Returns the value of attribute root_dir.



3
4
5
# File 'lib/sfp/Sfplib.rb', line 3

def root_dir
  @root_dir
end

#used_classesObject (readonly)

Returns the value of attribute used_classes.



4
5
6
# File 'lib/sfp/Sfplib.rb', line 4

def used_classes
  @used_classes
end

Instance Method Details

#create_constraint(name, type = 'and') ⇒ Object



42
43
44
45
46
47
48
# 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) ⇒ Object



108
109
110
# File 'lib/sfp/Sfplib.rb', line 108

def deep_clone(value)
	Sfp::Helper.deep_clone(value)
end

#expand_class(c) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# 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_classesObject



99
100
101
# File 'lib/sfp/Sfplib.rb', line 99

def expand_classes
	@unexpanded_classes.each { |c| expand_class(c) }
end

#expand_object(obj) ⇒ Object



103
104
105
106
# 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

#finalizeObject



16
17
18
19
20
21
# 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) ⇒ Object



78
79
80
81
82
83
# 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

#initObject



6
7
8
9
10
11
12
13
14
# 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_idObject



23
24
25
26
27
# 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) ⇒ Object



29
30
31
# File 'lib/sfp/Sfplib.rb', line 29

def null_value(isa=nil)
	return { '_context' => 'null', '_isa' => isa }
end

#process_file(file) ⇒ Object

Raises:

  • (Exception)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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) ⇒ Object



33
34
35
36
# File 'lib/sfp/Sfplib.rb', line 33

def to_ref(path)
	ref = "$." + path
	return ref
end

#to_sfpObject



38
39
40
# File 'lib/sfp/Sfplib.rb', line 38

def to_sfp
	return @root
end