5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/interscript/dsl.rb', line 5
def self.parse(map_name, reverse: true)
return @cache[map_name] if @cache[map_name]
if map_name.include? "|"
map_parts = map_name.split("|").map(&:strip)
doc = Interscript::DSL::Document.new(map_name) do
map_parts.each_with_index do |i, idx|
dependency i, as: :"part#{idx}"
end
stage {
map_parts.each_with_index do |i, idx|
run map[:"part#{idx}"].stage.main
end
}
end.node
return @cache[map_name] = doc
end
path = begin
Interscript.locate(map_name)
rescue Interscript::MapNotFoundError => e
begin
raise e if reverse == false reverse_name = Interscript::Node::Document.reverse_name(map_name)
return @cache[map_name] = parse(reverse_name, reverse: false).reverse
rescue Interscript::MapNotFoundError
raise e
end
end
library = path.end_with?(".iml")
map_name = File.basename(path, ".imp")
map_name = File.basename(map_name, ".iml")
ruby = []
yaml = []
file = File.read(path).split("\n")
exc_fname = File.expand_path(path, Dir.pwd)
md_reading = false
md_indent = nil
md_inner_indent = nil
file.each do |l|
if md_reading && l =~ /\A#{md_indent}\}\s*\z/
md_reading = false
elsif md_reading
ruby << ""
yaml << l
elsif l =~ /\A(\s*)metadata\s*\{\z/
md_indent = $1
md_reading = true
else
yaml << ""
ruby << l
end
end
raise ArgumentError, "metadata stage isn't terminated" if md_reading
ruby, yaml = ruby.join("\n"), yaml.join("\n")
obj = Interscript::DSL::Document.new(map_name)
obj.instance_eval ruby, exc_fname, 1
yaml = if yaml =~ /\A\s*\z/
{}
else
YAML.load(yaml, exc_fname)
end
md = Interscript::DSL::Metadata.new(yaml: true, map_name: map_name, library: library) do
yaml.each do |k,v|
public_send(k.to_sym, v)
end
end
obj.node.metadata = md.node
@cache[map_name] = obj.node
end
|