dtk-dsl 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.byebug_history +70 -0
- data/.gitignore +2 -0
- data/Gemfile +2 -0
- data/README.md +2 -0
- data/dtk-dsl.gemspec +16 -0
- data/lib/dsl/directory_generator.rb +27 -0
- data/lib/dsl/directory_parser/path_info.rb +62 -0
- data/lib/dsl/directory_parser.rb +33 -0
- data/lib/dsl/dsl_version.rb +36 -0
- data/lib/dsl/error/subclasses.rb +38 -0
- data/lib/dsl/error.rb +24 -0
- data/lib/dsl/file_generator/content_input/array.rb +31 -0
- data/lib/dsl/file_generator/content_input/hash.rb +53 -0
- data/lib/dsl/file_generator/content_input/mixin.rb +68 -0
- data/lib/dsl/file_generator/content_input/string.rb +31 -0
- data/lib/dsl/file_generator/content_input/tags.rb +87 -0
- data/lib/dsl/file_generator/content_input.rb +29 -0
- data/lib/dsl/file_generator/yaml_object.rb +24 -0
- data/lib/dsl/file_generator.rb +39 -0
- data/lib/dsl/file_obj.rb +119 -0
- data/lib/dsl/file_parser/input/array.rb +27 -0
- data/lib/dsl/file_parser/input/hash.rb +40 -0
- data/lib/dsl/file_parser/input.rb +29 -0
- data/lib/dsl/file_parser/output.rb +24 -0
- data/lib/dsl/file_parser.rb +71 -0
- data/lib/dsl/file_type.rb +79 -0
- data/lib/dsl/input_output_common/array.rb +43 -0
- data/lib/dsl/input_output_common/canonical/array.rb +27 -0
- data/lib/dsl/input_output_common/canonical/hash.rb +69 -0
- data/lib/dsl/input_output_common/canonical/hash_key.rb +54 -0
- data/lib/dsl/input_output_common/canonical.rb +28 -0
- data/lib/dsl/input_output_common/hash.rb +44 -0
- data/lib/dsl/input_output_common/output_class_mixin.rb +34 -0
- data/lib/dsl/input_output_common/semantic_parse/hash.rb +33 -0
- data/lib/dsl/input_output_common/semantic_parse/mixin.rb +44 -0
- data/lib/dsl/input_output_common/semantic_parse.rb +26 -0
- data/lib/dsl/input_output_common.rb +60 -0
- data/lib/dsl/qualified_key.rb +55 -0
- data/lib/dsl/template/constant_class_mixin.rb +91 -0
- data/lib/dsl/template/generation/class_mixin.rb +40 -0
- data/lib/dsl/template/generation/mixin.rb +134 -0
- data/lib/dsl/template/generation.rb +26 -0
- data/lib/dsl/template/loader.rb +66 -0
- data/lib/dsl/template/parsing/class_mixin.rb +67 -0
- data/lib/dsl/template/parsing/mixin.rb +214 -0
- data/lib/dsl/template/parsing/parent_key.rb +82 -0
- data/lib/dsl/template/parsing/parsing_error/subclasses.rb +62 -0
- data/lib/dsl/template/parsing/parsing_error.rb +52 -0
- data/lib/dsl/template/parsing.rb +29 -0
- data/lib/dsl/template/v1/assembly.rb +82 -0
- data/lib/dsl/template/v1/attribute/semantic_parse.rb +26 -0
- data/lib/dsl/template/v1/attribute.rb +75 -0
- data/lib/dsl/template/v1/common_module.rb +38 -0
- data/lib/dsl/template/v1/common_module_summary.rb +42 -0
- data/lib/dsl/template/v1/component/semantic_parse.rb +26 -0
- data/lib/dsl/template/v1/component.rb +121 -0
- data/lib/dsl/template/v1/dependency.rb +63 -0
- data/lib/dsl/template/v1/module_ref.rb +62 -0
- data/lib/dsl/template/v1/node/semantic_parse.rb +62 -0
- data/lib/dsl/template/v1/node.rb +72 -0
- data/lib/dsl/template/v1/node_attribute/semantic_parse.rb +26 -0
- data/lib/dsl/template/v1/node_attribute.rb +25 -0
- data/lib/dsl/template/v1/service_instance.rb +50 -0
- data/lib/dsl/template/v1/service_module_summary.rb +37 -0
- data/lib/dsl/template/v1/workflow/semantic_parse.rb +26 -0
- data/lib/dsl/template/v1/workflow.rb +65 -0
- data/lib/dsl/template/v1.rb +43 -0
- data/lib/dsl/template.rb +110 -0
- data/lib/dsl/version.rb +6 -0
- data/lib/dsl/yaml_helper.rb +56 -0
- data/lib/dtk_dsl.rb +36 -0
- metadata +114 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class Template
|
20
|
+
module Parsing
|
21
|
+
module ClassMixin
|
22
|
+
# Main template-specific parse call; Concrete classes overwrite this
|
23
|
+
def parse_elements(_input_elements, _parent_info)
|
24
|
+
raise Error::NoMethodForConcreteClass.new(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Indicates whether collection of elements to parse is a hash or array
|
28
|
+
# This can be overwritten
|
29
|
+
def elements_collection_type
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
|
36
|
+
# opts can have keys
|
37
|
+
# :index
|
38
|
+
def parse_element(input, parent_info, opts = {})
|
39
|
+
if input.nil?
|
40
|
+
nil
|
41
|
+
else
|
42
|
+
file_obj = parent_info.parent.file_obj
|
43
|
+
parent_key = ParentKey.parent_key(parent_info, opts[:index])
|
44
|
+
create_for_parsing(input, :file_obj => file_obj, :parent_key => parent_key).parse
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def file_parser_output_array
|
49
|
+
FileParser::Output.create(:output_type => :array)
|
50
|
+
end
|
51
|
+
|
52
|
+
def file_parser_output_hash
|
53
|
+
FileParser::Output.create(:output_type => :hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
def input_hash?(input)
|
57
|
+
input.kind_of?(FileParser::Input::Hash)
|
58
|
+
end
|
59
|
+
|
60
|
+
def input_array?(input)
|
61
|
+
input.kind_of?(FileParser::Input::Array)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class Template
|
20
|
+
module Parsing
|
21
|
+
module Mixin
|
22
|
+
# Main template-specific parse call; Concrete classes overwrite this
|
23
|
+
def parse!
|
24
|
+
raise Error::NoMethodForConcreteClass.new(self.class)
|
25
|
+
end
|
26
|
+
private :parse!
|
27
|
+
|
28
|
+
attr_reader :file_obj, :parent_key
|
29
|
+
|
30
|
+
# opts can have keys:
|
31
|
+
# :raw_input
|
32
|
+
# :file_obj
|
33
|
+
# :parent_key
|
34
|
+
def parsing_initialize(opts = {})
|
35
|
+
unless raw_input = opts[:raw_input]
|
36
|
+
raise Error, "Unexpected that opts[:raw_input] is nil"
|
37
|
+
end
|
38
|
+
parent_key = opts[:parent_key]
|
39
|
+
|
40
|
+
@input = FileParser::Input.create(raw_input)
|
41
|
+
@output = empty_parser_output(@input, parent_key)
|
42
|
+
@file_obj = opts[:file_obj]
|
43
|
+
@parent_key = parent_key
|
44
|
+
end
|
45
|
+
private :parsing_initialize
|
46
|
+
|
47
|
+
def parse
|
48
|
+
parse!
|
49
|
+
@output
|
50
|
+
end
|
51
|
+
|
52
|
+
# The method parser_output_type can be set on concrete class; it wil be set if input and output types are different
|
53
|
+
def parser_output_type
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def empty_parser_output(input, parent_key)
|
60
|
+
if self.class.const_defined? 'SemanticParse'
|
61
|
+
qualified_key = parent_key && parent_key.create_qualified_key
|
62
|
+
self.class::SemanticParse.new(FileParser::Output, :qualified_key => qualified_key)
|
63
|
+
elsif parser_output_type
|
64
|
+
FileParser::Output.create(:output_type => parser_output_type)
|
65
|
+
else
|
66
|
+
FileParser::Output.create(:input => input)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# opts can have key
|
71
|
+
# :key_type
|
72
|
+
def parse_child_elements(parse_template_type, key_constant, opts = {})
|
73
|
+
unless key_and_value = input_key_and_value?(key_constant, opts)
|
74
|
+
nil
|
75
|
+
else
|
76
|
+
template_class = template_class(parse_template_type)
|
77
|
+
input = check_type_and_ret_input(template_class, key_and_value)
|
78
|
+
key_type = opts[:key_type] || parse_template_type
|
79
|
+
template_class.parse_elements(input, ParentInfo.new(self, key_type))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def parse_child_elements?(parse_template_type, key_constant, opts = {})
|
84
|
+
ret = parse_child_elements(parse_template_type, key_constant, opts)
|
85
|
+
(ret.nil? or ret.empty?) ? nil : ret
|
86
|
+
end
|
87
|
+
|
88
|
+
# opts can have keys
|
89
|
+
# :parent_key
|
90
|
+
def parse_child(parse_template_type, input, opts = {})
|
91
|
+
if input.nil?
|
92
|
+
nil
|
93
|
+
else
|
94
|
+
template_class(parse_template_type).create_for_parsing(input, opts.merge(:file_obj => @file_obj)).parse
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# This cannot be used for an assignment that can have with nil values
|
99
|
+
# opts can have key
|
100
|
+
# :input_hash
|
101
|
+
def input_key_value(constant, opts = {})
|
102
|
+
ret = input_key_value?(constant, opts)
|
103
|
+
raise_missing_key_value(constant) if ret.nil?
|
104
|
+
ret
|
105
|
+
end
|
106
|
+
def input_key_value?(constant, opts = {})
|
107
|
+
input_hash = opts[:input_hash] || input_hash()
|
108
|
+
constant_class.matches?(input_hash, constant)
|
109
|
+
end
|
110
|
+
|
111
|
+
# returns nil or {key => value}
|
112
|
+
# opts can have keys
|
113
|
+
# :input_hash
|
114
|
+
def input_key_and_value?(constant, opts = {})
|
115
|
+
input_hash = opts[:input_hash] || input_hash()
|
116
|
+
constant_class.matching_key_and_value?(input_hash, constant)
|
117
|
+
end
|
118
|
+
|
119
|
+
def parsing_set(constant, val)
|
120
|
+
@output.set(constant, val)
|
121
|
+
end
|
122
|
+
|
123
|
+
def parsing_merge(hash)
|
124
|
+
@output.merge!(hash)
|
125
|
+
end
|
126
|
+
|
127
|
+
def parsing_add(array_element)
|
128
|
+
@output << array_element
|
129
|
+
end
|
130
|
+
|
131
|
+
def check_type_and_ret_input(template_class, key_and_value)
|
132
|
+
input = key_and_value.values.first
|
133
|
+
key = key_and_value.keys.first
|
134
|
+
|
135
|
+
case template_class.elements_collection_type
|
136
|
+
when :hash
|
137
|
+
raise_input_error(::Hash, :input => input, :key => key) unless input_hash?(input)
|
138
|
+
when :array
|
139
|
+
raise_input_error(::Array, :input => input, :key => key) unless input_array?(input)
|
140
|
+
end
|
141
|
+
input
|
142
|
+
end
|
143
|
+
|
144
|
+
def input_hash?(input = nil)
|
145
|
+
(input || @input).kind_of?(FileParser::Input::Hash)
|
146
|
+
end
|
147
|
+
|
148
|
+
def input_hash
|
149
|
+
@input_hash ||= input_hash? ? @input : raise_input_error(::Hash)
|
150
|
+
end
|
151
|
+
|
152
|
+
def input_array?(input = nil)
|
153
|
+
(input || @input).kind_of?(FileParser::Input::Array)
|
154
|
+
end
|
155
|
+
|
156
|
+
def input_array
|
157
|
+
@input_array ||= input_array? ? @input : raise_input_error(::Array)
|
158
|
+
end
|
159
|
+
|
160
|
+
def input_string?
|
161
|
+
@input.kind_of?(::String)
|
162
|
+
end
|
163
|
+
|
164
|
+
def input_string
|
165
|
+
@input_string ||= input_string? ? @input : raise_input_error(::String)
|
166
|
+
end
|
167
|
+
|
168
|
+
# opts can have keys
|
169
|
+
# :input
|
170
|
+
# :key
|
171
|
+
# correct_ruby_types can also be scalar
|
172
|
+
def raise_input_error(correct_ruby_types, opts = {})
|
173
|
+
input = opts[:input] || @input
|
174
|
+
raise parsing_error_with_opts([:WrongObjectType, input, correct_ruby_types], opts)
|
175
|
+
end
|
176
|
+
|
177
|
+
def raise_missing_key_value(constant)
|
178
|
+
key = canonical_key(constant)
|
179
|
+
raise parsing_error(:MissingKeyValue, key)
|
180
|
+
end
|
181
|
+
|
182
|
+
# args can have form
|
183
|
+
# (:ParsingErrorName,*parsing_error_params) or
|
184
|
+
# (*parsing_error_params)
|
185
|
+
def parsing_error(*args)
|
186
|
+
parsing_error_with_opts(args)
|
187
|
+
end
|
188
|
+
|
189
|
+
# opts can have keys
|
190
|
+
# :key
|
191
|
+
def parsing_error_with_opts(args, opts = {})
|
192
|
+
qualified_key = qualified_key(opts[:key])
|
193
|
+
if error_class = ParsingError.error_class?(args)
|
194
|
+
error_params = args[1..args.size-1]
|
195
|
+
error_class.new(*error_params, :file_obj => @file_obj, :qualified_key => qualified_key)
|
196
|
+
else
|
197
|
+
ParsingError.new(*args, :file_obj => @file_obj, :qualified_key => qualified_key)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def qualified_key(key = nil)
|
202
|
+
if key.nil?
|
203
|
+
@parent_key
|
204
|
+
else
|
205
|
+
# TODO: find common function that appends keys
|
206
|
+
@parent_key.nil? ? key : "#{@parent_key}/#{key}"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class Template
|
20
|
+
module Parsing
|
21
|
+
class ParentKey < ::String
|
22
|
+
DELIM = '/'
|
23
|
+
def self.parent_key(parent_info, index)
|
24
|
+
ret = new
|
25
|
+
ret << "#{parent_info.parent.parent_key}"
|
26
|
+
ret << DELIM unless ret.empty?
|
27
|
+
ret << parent_info.key_type.to_s
|
28
|
+
ret << Index.with_delims(index) unless index.nil?
|
29
|
+
ret
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_qualified_key
|
33
|
+
QualifiedKey.new(qualified_key_elements)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
UNKNOWN_INDEX = '*'
|
39
|
+
def qualified_key_elements
|
40
|
+
split(DELIM).map do |key_seqment|
|
41
|
+
type, index = Index.parse_segment(key_seqment)
|
42
|
+
QualifiedKey::Element.new(type, index || UNKNOWN_INDEX)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module Index
|
47
|
+
LEFT_DELIM = '['
|
48
|
+
RIGHT_DELIM = ']'
|
49
|
+
def self.with_delims(index)
|
50
|
+
"#{LEFT_DELIM}#{index}#{RIGHT_DELIM}"
|
51
|
+
end
|
52
|
+
|
53
|
+
# returns [type, index] where index can be nil
|
54
|
+
def self.parse_segment(key_seqment)
|
55
|
+
type = index = nil
|
56
|
+
split_on_left = key_seqment.split(LEFT_DELIM)
|
57
|
+
if split_on_left.size == 1
|
58
|
+
type = key_seqment
|
59
|
+
else
|
60
|
+
type = split_on_left.shift
|
61
|
+
|
62
|
+
# find index
|
63
|
+
# being robust if index has index symbols in it by looking for leftmost left deleim and rightmost right delim
|
64
|
+
rest = split_on_left.join(LEFT_DELIM)
|
65
|
+
split_on_right = rest.split(RIGHT_DELIM)
|
66
|
+
if split_on_right.size == 1
|
67
|
+
index = split_on_right.first
|
68
|
+
else
|
69
|
+
split_on_right.pop # get rid of end
|
70
|
+
index = split_on_right.join(RIGHT_DELIM)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
[type, index]
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL; class Template
|
19
|
+
module Parsing
|
20
|
+
class ParsingError
|
21
|
+
class MissingKeyValue < self
|
22
|
+
def initialize(key, opts = {})
|
23
|
+
error_msg = "Missing value for key '#{key}'"
|
24
|
+
super(error_msg, opts)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class WrongObjectType < self
|
29
|
+
def initialize(obj, correct_ruby_types, opts = {})
|
30
|
+
correct_ruby_types = [correct_ruby_types] unless correct_ruby_types.kind_of?(::Array)
|
31
|
+
error_msg =
|
32
|
+
if correct_ruby_types.size == 1
|
33
|
+
"The key's value should have type #{correct_ruby_types.first}"
|
34
|
+
else
|
35
|
+
"The key's value should be one of the types (#{correct_ruby_types.join(' ')})"
|
36
|
+
end
|
37
|
+
error_msg << ", but has type #{input_class_string(obj)}"
|
38
|
+
super(error_msg, opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def input_class_string(obj)
|
44
|
+
klass =
|
45
|
+
if obj.kind_of?(::Hash)
|
46
|
+
::Hash
|
47
|
+
elsif obj.kind_of?(::Array)
|
48
|
+
::Array
|
49
|
+
elsif obj.kind_of?(::String)
|
50
|
+
::String
|
51
|
+
else
|
52
|
+
obj.class
|
53
|
+
end
|
54
|
+
# demodularize
|
55
|
+
klass.to_s.split('::').last
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end; end
|
61
|
+
|
62
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class Template
|
20
|
+
module Parsing
|
21
|
+
class ParsingError < Error::Usage
|
22
|
+
|
23
|
+
require_relative('parsing_error/subclasses')
|
24
|
+
|
25
|
+
# opts can have keys
|
26
|
+
# :file_obj
|
27
|
+
# :qualified_key
|
28
|
+
def initialize(error_msg, opts = {})
|
29
|
+
@file_ref = FileParser.file_ref_in_error(opts[:file_obj])
|
30
|
+
@qualified_key = opts[:qualified_key]
|
31
|
+
# TODO: later enhancment can use @qualified_key to find line numbers in yaml file
|
32
|
+
key_ref = @qualified_key ? " under key '#{@qualified_key}'" : ''
|
33
|
+
super("DTK parsing error#{key_ref}#{@file_ref}:\n #{error_msg}")
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.error_class?(args)
|
37
|
+
if args.first.kind_of?(Symbol)
|
38
|
+
begin
|
39
|
+
const_get(args.first.to_s)
|
40
|
+
rescue
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
elsif args.first.kind_of?(self)
|
44
|
+
args.first
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class Template
|
20
|
+
module Parsing
|
21
|
+
require_relative('parsing/parsing_error')
|
22
|
+
require_relative('parsing/parent_key')
|
23
|
+
require_relative('parsing/class_mixin')
|
24
|
+
require_relative('parsing/mixin')
|
25
|
+
|
26
|
+
ParentInfo = Struct.new(:parent, :key_type)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
class DTK::DSL::Template
|
19
|
+
class V1
|
20
|
+
class Assembly < self
|
21
|
+
module Constant
|
22
|
+
module Variations
|
23
|
+
end
|
24
|
+
|
25
|
+
extend ClassMixin::Constant
|
26
|
+
Name = 'name'
|
27
|
+
Description = 'description'
|
28
|
+
Attributes = 'attributes'
|
29
|
+
Nodes = 'nodes'
|
30
|
+
Components = 'components'
|
31
|
+
|
32
|
+
Workflows = 'workflows'
|
33
|
+
Variations::Workflows = ['workflows', 'workflow']
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
### For parsing
|
38
|
+
|
39
|
+
def self.elements_collection_type
|
40
|
+
:hash
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.parse_elements(input_hash, parent_info)
|
44
|
+
ret = file_parser_output_array
|
45
|
+
input_hash.each do |name, content|
|
46
|
+
ret << parse_element(content.merge('name' => name), parent_info, :index => name)
|
47
|
+
end
|
48
|
+
ret
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse!
|
52
|
+
set :Name, input_key_value(:Name)
|
53
|
+
set? :Description, input_key_value?(:Description)
|
54
|
+
set? :Attributes, parse_child_elements?(:attribute, :Attributes)
|
55
|
+
set? :Nodes, parse_child_elements?(:node, :Nodes)
|
56
|
+
set? :Components, parse_child_elements?(:component, :Components)
|
57
|
+
set? :Workflows, parse_child_elements?(:workflow, :Workflows)
|
58
|
+
|
59
|
+
# TODO: This is a catchall that removes ones we so far are parsing and then has catch all
|
60
|
+
input_hash.delete('name')
|
61
|
+
input_hash.delete('description')
|
62
|
+
input_hash.delete('attributes')
|
63
|
+
input_hash.delete('nodes')
|
64
|
+
input_hash.delete('components')
|
65
|
+
input_hash.delete('workflow')
|
66
|
+
input_hash.delete('workflows')
|
67
|
+
merge input_hash
|
68
|
+
end
|
69
|
+
|
70
|
+
### For generation
|
71
|
+
def generate!
|
72
|
+
# TODO: add attributes
|
73
|
+
set :Description, val(:Description)
|
74
|
+
set :Components, generate_child_elements(:component, val(:Components))
|
75
|
+
set :Nodes, generate_child_elements(:node, val(:Nodes))
|
76
|
+
set :Workflows, generate_child_elements(:workflow, val(:Workflows))
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class Template::V1
|
20
|
+
class Attribute
|
21
|
+
class SemanticParse < InputOutputCommon::SemanticParse::Hash
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
class DTK::DSL::Template
|
19
|
+
class V1
|
20
|
+
class Attribute < self
|
21
|
+
require_relative('attribute/semantic_parse')
|
22
|
+
|
23
|
+
module Constant
|
24
|
+
module Variations
|
25
|
+
end
|
26
|
+
|
27
|
+
extend ClassMixin::Constant
|
28
|
+
Value = 'value'
|
29
|
+
end
|
30
|
+
|
31
|
+
### For parsing
|
32
|
+
def parser_output_type
|
33
|
+
:hash
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.elements_collection_type
|
37
|
+
:hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.parse_elements(input_hash, parent_info)
|
41
|
+
input_hash.inject(file_parser_output_hash) do |h, (name, value)|
|
42
|
+
h.merge(name => parse_element({ 'value' => value}, parent_info, :index => name))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse!
|
47
|
+
# using 'input_key_value?' (i.e., with '?') in case null value
|
48
|
+
set :Value, input_key_value?(:Value)
|
49
|
+
end
|
50
|
+
|
51
|
+
### For generation
|
52
|
+
def self.generate_elements(attributes_content, parent)
|
53
|
+
attributes_content.inject({}) do |h, (attribute_name, attribute)|
|
54
|
+
attribute.set(:Name, attribute_name)
|
55
|
+
element = generate_element?(attribute, parent)
|
56
|
+
element.nil? ? h : h.merge(element)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate!
|
61
|
+
value = val(:Value)
|
62
|
+
unless value.nil?
|
63
|
+
merge(req(:Name) => val(:Value))
|
64
|
+
self
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate?
|
69
|
+
generate! unless skip_for_generation?
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|