emf_jruby 0.1.1-java → 0.1.2-java
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/emf/emf_nav.rb +52 -0
- metadata +2 -1
data/lib/emf/emf_nav.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module JSON
|
2
|
+
def self.load_file(path,max_nesting=100)
|
3
|
+
parse(File.read(path),{max_nesting: max_nesting})
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module EMF
|
8
|
+
|
9
|
+
def self.rel_conts(root)
|
10
|
+
root.keys.select {|k| k.start_with? 'relcont_'}
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.rel_non_conts(root)
|
14
|
+
root.keys.select {|k| k.start_with? 'relcont_'}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.attrs(root)
|
18
|
+
root.keys.select {|k| k.start_with? 'attr_'}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.values(root,feat)
|
22
|
+
raw = root[feat]
|
23
|
+
return raw if raw.is_a? Array
|
24
|
+
return [raw]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.traverse(root,depth=0,&op)
|
28
|
+
op.call(root,depth)
|
29
|
+
return unless root
|
30
|
+
rel_conts(root).each do |r|
|
31
|
+
if root[r].is_a? Array
|
32
|
+
root[r].each do |c|
|
33
|
+
raise "expected an object but it is a #{c.class} (relation: #{r})" unless c.is_a? Hash
|
34
|
+
traverse(c,depth+1,&op)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
traverse(root[r],depth+1,&op)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.print_tree(root,depth=0)
|
43
|
+
traverse(root) do |n,d|
|
44
|
+
s = ""
|
45
|
+
d.times { s = s + " " }
|
46
|
+
s = s + n['type'] if n
|
47
|
+
s = s + '<NIL>' unless n
|
48
|
+
puts s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: emf_jruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.2
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Federico Tomassetti
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- lib/emf_jruby.rb
|
21
21
|
- lib/emf/emf_to_json.rb
|
22
|
+
- lib/emf/emf_nav.rb
|
22
23
|
- lib/emf/ast_serialization.rb
|
23
24
|
- lib/jars/org.antlr.runtime_3.0.0.v200803061811.jar
|
24
25
|
- lib/jars/org.eclipse.emf.common_2.8.0.v20130125-0546.jar
|