lutaml-lml 0.3.6 → 0.3.8
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 +4 -4
- data/lib/lutaml-lml.rb +5 -0
- data/lib/lutaml_lml/version.rb +6 -0
- metadata +14 -166
- data/exe/lutaml-lml +0 -6
- data/exe/lutaml-lml-lsp +0 -11
- data/lib/lutaml/lml/association_label_resolver.rb +0 -52
- data/lib/lutaml/lml/cli.rb +0 -489
- data/lib/lutaml/lml/data_processor/attribute_processing.rb +0 -133
- data/lib/lutaml/lml/data_processor/collection_processing.rb +0 -37
- data/lib/lutaml/lml/data_processor/instance_processing.rb +0 -77
- data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +0 -70
- data/lib/lutaml/lml/data_processor/value_processing.rb +0 -103
- data/lib/lutaml/lml/data_processor/view_processing.rb +0 -26
- data/lib/lutaml/lml/data_processor.rb +0 -59
- data/lib/lutaml/lml/diagnostic.rb +0 -149
- data/lib/lutaml/lml/document_builder.rb +0 -481
- data/lib/lutaml/lml/entity_types.rb +0 -30
- data/lib/lutaml/lml/executor/adapter_helpers.rb +0 -45
- data/lib/lutaml/lml/executor/condition_evaluator.rb +0 -169
- data/lib/lutaml/lml/executor/csv_adapter.rb +0 -88
- data/lib/lutaml/lml/executor/format_adapter.rb +0 -54
- data/lib/lutaml/lml/executor/xml_adapter.rb +0 -102
- data/lib/lutaml/lml/executor.rb +0 -96
- data/lib/lutaml/lml/format/adapter/document.rb +0 -11
- data/lib/lutaml/lml/format/adapter/mapping.rb +0 -31
- data/lib/lutaml/lml/format/adapter/standard_adapter.rb +0 -162
- data/lib/lutaml/lml/format/adapter/transform.rb +0 -11
- data/lib/lutaml/lml/format.rb +0 -29
- data/lib/lutaml/lml/formatter/base.rb +0 -79
- data/lib/lutaml/lml/formatter/canonical.rb +0 -736
- data/lib/lutaml/lml/formatter/elk.rb +0 -45
- data/lib/lutaml/lml/formatter/graphviz/document_formatter.rb +0 -89
- data/lib/lutaml/lml/formatter/graphviz/html_builder.rb +0 -72
- data/lib/lutaml/lml/formatter/graphviz/node_formatter.rb +0 -89
- data/lib/lutaml/lml/formatter/graphviz/relationship_formatter.rb +0 -130
- data/lib/lutaml/lml/formatter/graphviz.rb +0 -90
- data/lib/lutaml/lml/formatter/svg_pdf/path_parser.rb +0 -134
- data/lib/lutaml/lml/formatter/svg_pdf.rb +0 -285
- data/lib/lutaml/lml/formatter.rb +0 -12
- data/lib/lutaml/lml/grammar/lml.artifact.json +0 -14993
- data/lib/lutaml/lml/grammar/lml.parg +0 -389
- data/lib/lutaml/lml/grammar.rb +0 -60
- data/lib/lutaml/lml/has_attributes.rb +0 -14
- data/lib/lutaml/lml/import_resolver.rb +0 -96
- data/lib/lutaml/lml/layout/elk_engine.rb +0 -15
- data/lib/lutaml/lml/layout/elk_graph_builder.rb +0 -129
- data/lib/lutaml/lml/layout/elk_svg_markers.rb +0 -45
- data/lib/lutaml/lml/layout/elk_svg_renderer.rb +0 -119
- data/lib/lutaml/lml/layout/engine.rb +0 -17
- data/lib/lutaml/lml/layout/graph_viz_engine.rb +0 -19
- data/lib/lutaml/lml/layout.rb +0 -12
- data/lib/lutaml/lml/literal_value.rb +0 -32
- data/lib/lutaml/lml/lsp/conversions.rb +0 -78
- data/lib/lutaml/lml/lsp/keywords.rb +0 -43
- data/lib/lutaml/lml/lsp/server.rb +0 -378
- data/lib/lutaml/lml/lsp/store.rb +0 -68
- data/lib/lutaml/lml/lsp/transport.rb +0 -53
- data/lib/lutaml/lml/lsp.rb +0 -16
- data/lib/lutaml/lml/model_compiler/enums.rb +0 -172
- data/lib/lutaml/lml/model_compiler/hydration.rb +0 -123
- data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +0 -188
- data/lib/lutaml/lml/model_compiler/string_formats.rb +0 -42
- data/lib/lutaml/lml/model_compiler/validation.rb +0 -65
- data/lib/lutaml/lml/model_compiler.rb +0 -323
- data/lib/lutaml/lml/models/action.rb +0 -10
- data/lib/lutaml/lml/models/association.rb +0 -29
- data/lib/lutaml/lml/models/cardinality.rb +0 -10
- data/lib/lutaml/lml/models/collection.rb +0 -11
- data/lib/lutaml/lml/models/constraint.rb +0 -23
- data/lib/lutaml/lml/models/data_type.rb +0 -41
- data/lib/lutaml/lml/models/derived_field.rb +0 -14
- data/lib/lutaml/lml/models/diagram.rb +0 -20
- data/lib/lutaml/lml/models/document.rb +0 -84
- data/lib/lutaml/lml/models/enum.rb +0 -38
- data/lib/lutaml/lml/models/fidelity.rb +0 -10
- data/lib/lutaml/lml/models/group.rb +0 -11
- data/lib/lutaml/lml/models/instance.rb +0 -26
- data/lib/lutaml/lml/models/instance_collection.rb +0 -16
- data/lib/lutaml/lml/models/instances_export.rb +0 -10
- data/lib/lutaml/lml/models/instances_import.rb +0 -11
- data/lib/lutaml/lml/models/mapping.rb +0 -15
- data/lib/lutaml/lml/models/mapping_rule.rb +0 -16
- data/lib/lutaml/lml/models/member_field.rb +0 -14
- data/lib/lutaml/lml/models/namespace.rb +0 -16
- data/lib/lutaml/lml/models/operation.rb +0 -26
- data/lib/lutaml/lml/models/operation_parameter.rb +0 -12
- data/lib/lutaml/lml/models/package.rb +0 -26
- data/lib/lutaml/lml/models/primitive_type.rb +0 -33
- data/lib/lutaml/lml/models/reference.rb +0 -23
- data/lib/lutaml/lml/models/serialization_mapping.rb +0 -19
- data/lib/lutaml/lml/models/string_format.rb +0 -16
- data/lib/lutaml/lml/models/top_element_attribute.rb +0 -116
- data/lib/lutaml/lml/models/uml_class.rb +0 -85
- data/lib/lutaml/lml/models/value.rb +0 -15
- data/lib/lutaml/lml/models/view_filter.rb +0 -11
- data/lib/lutaml/lml/models/view_import.rb +0 -11
- data/lib/lutaml/lml/parser.rb +0 -19
- data/lib/lutaml/lml/pipeline.rb +0 -73
- data/lib/lutaml/lml/positioned.rb +0 -13
- data/lib/lutaml/lml/preprocessor.rb +0 -130
- data/lib/lutaml/lml/quoting.rb +0 -60
- data/lib/lutaml/lml/source.rb +0 -49
- data/lib/lutaml/lml/source_position.rb +0 -20
- data/lib/lutaml/lml/symbol_index.rb +0 -200
- data/lib/lutaml/lml/transform.rb +0 -119
- data/lib/lutaml/lml/types/text_type.rb +0 -28
- data/lib/lutaml/lml/types.rb +0 -10
- data/lib/lutaml/lml/validator.rb +0 -458
- data/lib/lutaml/lml/version.rb +0 -7
- data/lib/lutaml/lml/view_resolution.rb +0 -32
- data/lib/lutaml/lml/view_resolver.rb +0 -48
- data/lib/lutaml/lml/yaml_parser.rb +0 -17
- data/lib/lutaml/lml.rb +0 -130
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Lml
|
|
5
|
-
class DataProcessor
|
|
6
|
-
module InstanceProcessing
|
|
7
|
-
INSTANCE_KEY_HANDLERS = {
|
|
8
|
-
instance: :process_instance,
|
|
9
|
-
collections: :process_collections,
|
|
10
|
-
imports: :process_imports,
|
|
11
|
-
exports: :process_exports
|
|
12
|
-
}.freeze
|
|
13
|
-
|
|
14
|
-
INSTANCE_FIELD_HANDLERS = {
|
|
15
|
-
instance_type: :handle_instance_type,
|
|
16
|
-
isa: :handle_instance_isa,
|
|
17
|
-
instance: :handle_instance_nested,
|
|
18
|
-
attributes: :handle_instance_attributes,
|
|
19
|
-
template: :handle_instance_template
|
|
20
|
-
}.freeze
|
|
21
|
-
|
|
22
|
-
def process_instances(obj)
|
|
23
|
-
return [] unless obj.is_a?(Array)
|
|
24
|
-
|
|
25
|
-
obj.each_with_object({}) do |instance, acc|
|
|
26
|
-
acc[:instances] ||= []
|
|
27
|
-
key = INSTANCE_KEY_HANDLERS.keys.find { |k| instance.key?(k) }
|
|
28
|
-
next unless key
|
|
29
|
-
|
|
30
|
-
append_result(acc, key, public_send(INSTANCE_KEY_HANDLERS[key], instance[key]))
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def process_instance(hash)
|
|
35
|
-
hash.each_with_object({}) do |(key, value), result|
|
|
36
|
-
handler = INSTANCE_FIELD_HANDLERS[key]
|
|
37
|
-
if handler
|
|
38
|
-
public_send(handler, value, result)
|
|
39
|
-
else
|
|
40
|
-
result[key] = process_value(value).last
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def handle_instance_type(value, result)
|
|
46
|
-
result[:type] = process_value(value).last
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def handle_instance_isa(value, result)
|
|
50
|
-
result[:isa] = process_value(value).last
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def handle_instance_nested(value, result)
|
|
54
|
-
result[:instance] = process_instance(value)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def handle_instance_attributes(value, result)
|
|
58
|
-
result[:attributes] = process_attributes(value)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def handle_instance_template(value, result)
|
|
62
|
-
result[:template] = process_attributes(value[:attributes])
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
private
|
|
66
|
-
|
|
67
|
-
def append_result(acc, key, result)
|
|
68
|
-
case key
|
|
69
|
-
when :instance then acc[:instances] << result
|
|
70
|
-
when :collections then (acc[:collections] ||= []) << result
|
|
71
|
-
else (acc[key] ||= []).concat(result)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Lml
|
|
5
|
-
class DataProcessor
|
|
6
|
-
# RS 3001 §Value/§Attribute argument normalization: the canonical
|
|
7
|
-
# `value` construct and the attribute `values` argument.
|
|
8
|
-
module ValueDeclarationProcessing
|
|
9
|
-
# `value <name> { block }` is the canonical enum member; the bare
|
|
10
|
-
# identifier member is its documented shortcut. Normalize into the
|
|
11
|
-
# member shape the shortcut produces: the value block's `definition`
|
|
12
|
-
# lines become the member description and its attribute pairs become
|
|
13
|
-
# member payload properties.
|
|
14
|
-
def process_value_declaration(decl)
|
|
15
|
-
inner = { name: unwrap_string(decl[:value_name]) }
|
|
16
|
-
inner[:position] = decl[:position] if decl[:position]
|
|
17
|
-
Array(decl[:members]).each do |member|
|
|
18
|
-
normalize_value_member(inner, member)
|
|
19
|
-
end
|
|
20
|
-
{ attributes: inner }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# `values <enum>` types the attribute with the named enum;
|
|
24
|
-
# `values { v1, v2 }` carries an inline value set that the compiler
|
|
25
|
-
# expands into an anonymous enum.
|
|
26
|
-
def translate_values_argument(result)
|
|
27
|
-
if result.key?(:value_set_ref)
|
|
28
|
-
ref = unwrap_string(result.delete(:value_set_ref))
|
|
29
|
-
result[:type] = ref unless result[:type]
|
|
30
|
-
end
|
|
31
|
-
return unless result.key?(:value_set)
|
|
32
|
-
|
|
33
|
-
result[:value_set] = Array(result[:value_set][:items]).map { |item| unwrap_data_value(item[:item]) }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
def normalize_value_member(inner, member)
|
|
39
|
-
if member.key?(:definition)
|
|
40
|
-
(inner[:attributes] ||= []) << { name: 'description', type: unwrap_string(member[:definition]) }
|
|
41
|
-
elsif member.key?(:instance)
|
|
42
|
-
# The bare `instance { ... }` capture is the instance-body
|
|
43
|
-
# hash; it must go through instance processing so its
|
|
44
|
-
# members become attribute entries, not raw pairs.
|
|
45
|
-
bodies = member[:instance].is_a?(Hash) ? [member[:instance]] : Array(member[:instance])
|
|
46
|
-
bodies.each do |body|
|
|
47
|
-
entry = body.is_a?(Hash) ? process_instance(body) : body
|
|
48
|
-
(inner[:instances] ||= []) << entry
|
|
49
|
-
end
|
|
50
|
-
elsif member.key?(:attributes)
|
|
51
|
-
(inner[:properties] ||= []) << member[:attributes]
|
|
52
|
-
elsif member.key?(:key)
|
|
53
|
-
(inner[:properties] ||= []) << extract_name_and_value(member)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def unwrap_data_value(item)
|
|
58
|
-
return item unless item.is_a?(Hash)
|
|
59
|
-
|
|
60
|
-
item[:string] || item[:number] || item[:float] ||
|
|
61
|
-
item[:boolean] || item[:name] || item
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def unwrap_string(value)
|
|
65
|
-
value.is_a?(Hash) && value.key?(:string) ? value[:string] : value
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Lml
|
|
5
|
-
class DataProcessor
|
|
6
|
-
module ValueProcessing
|
|
7
|
-
VALUE_TYPE_KEYS = %i[instance list string boolean null key_value_map number float condition require].freeze
|
|
8
|
-
|
|
9
|
-
VALUE_TYPE_HANDLERS = {
|
|
10
|
-
instance: :handle_instance_value,
|
|
11
|
-
list: :handle_list_value,
|
|
12
|
-
string: :handle_string_value,
|
|
13
|
-
boolean: :handle_boolean_value,
|
|
14
|
-
null: :handle_null_value,
|
|
15
|
-
key_value_map: :handle_key_value_map,
|
|
16
|
-
number: :handle_number_value,
|
|
17
|
-
float: :handle_float_value,
|
|
18
|
-
condition: :handle_delegate_value,
|
|
19
|
-
require: :handle_delegate_value
|
|
20
|
-
}.freeze
|
|
21
|
-
|
|
22
|
-
def process_value(value)
|
|
23
|
-
return [] if value.nil?
|
|
24
|
-
return process_hash_value(value) if value.is_a?(Hash)
|
|
25
|
-
return process_array_value(value) if value.is_a?(Array)
|
|
26
|
-
|
|
27
|
-
[value.class.to_s, value]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def process_list_value(list)
|
|
31
|
-
process_typed_sequence(list)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def process_array_value(value)
|
|
35
|
-
process_typed_sequence(value)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def handle_instance_value(_key, value)
|
|
39
|
-
['Instance', process_instance(value[:instance])]
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def handle_list_value(_key, value)
|
|
43
|
-
process_typed_sequence(value[:list])
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def handle_string_value(_key, value)
|
|
47
|
-
['String', value[:string]]
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def handle_boolean_value(_key, value)
|
|
51
|
-
['Boolean', value[:boolean] == 'true']
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def handle_null_value(_key, _value)
|
|
55
|
-
['Null', nil]
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def handle_key_value_map(_key, value)
|
|
59
|
-
process_key_value_map(value[:key_value_map])
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def handle_number_value(_key, value)
|
|
63
|
-
['Number', value[:number].to_i]
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def handle_float_value(_key, value)
|
|
67
|
-
['Float', value[:float].to_f]
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def handle_delegate_value(key, value)
|
|
71
|
-
process_value(value[key])
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
private
|
|
75
|
-
|
|
76
|
-
def process_hash_value(value)
|
|
77
|
-
type_key = VALUE_TYPE_KEYS.find { |k| value.key?(k) }
|
|
78
|
-
return ['Hash', value] unless type_key
|
|
79
|
-
|
|
80
|
-
public_send(VALUE_TYPE_HANDLERS[type_key], type_key, value)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def process_typed_sequence(items)
|
|
84
|
-
type = 'String'
|
|
85
|
-
values = items.map do |item|
|
|
86
|
-
item_type, item_value = process_value(item)
|
|
87
|
-
type = item_type
|
|
88
|
-
item_value
|
|
89
|
-
end
|
|
90
|
-
["#{type}[]", values]
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def process_key_value_map(kv_map)
|
|
94
|
-
result = kv_map.each_with_object({}) do |kv, h|
|
|
95
|
-
key, value = kv.values_at(:key, :value)
|
|
96
|
-
h[key.to_sym] = process_value(value).last
|
|
97
|
-
end
|
|
98
|
-
['Hash', result]
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Lml
|
|
5
|
-
class DataProcessor
|
|
6
|
-
module ViewProcessing
|
|
7
|
-
# entity_name_list parses to a Hash (one name) or an Array of
|
|
8
|
-
# Hashes (several); normalize both to one list of strings.
|
|
9
|
-
def process_show_list(data)
|
|
10
|
-
entity_names_from(data)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def process_hide_list(data)
|
|
14
|
-
entity_names_from(data)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def entity_names_from(data)
|
|
20
|
-
entries = data.is_a?(Array) ? data : [data]
|
|
21
|
-
entries.map { |entry| entry[:entity_name].to_s }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Lml
|
|
5
|
-
# Post-transform normalization: turns parse captures into the flat
|
|
6
|
-
# member hashes the document builder consumes.
|
|
7
|
-
class DataProcessor
|
|
8
|
-
autoload :ValueProcessing, "lutaml/lml/data_processor/value_processing"
|
|
9
|
-
autoload :AttributeProcessing, "lutaml/lml/data_processor/attribute_processing"
|
|
10
|
-
autoload :ValueDeclarationProcessing, "lutaml/lml/data_processor/value_declaration_processing"
|
|
11
|
-
autoload :InstanceProcessing, "lutaml/lml/data_processor/instance_processing"
|
|
12
|
-
autoload :CollectionProcessing, "lutaml/lml/data_processor/collection_processing"
|
|
13
|
-
autoload :ViewProcessing, "lutaml/lml/data_processor/view_processing"
|
|
14
|
-
|
|
15
|
-
include ValueProcessing
|
|
16
|
-
include AttributeProcessing
|
|
17
|
-
include ValueDeclarationProcessing
|
|
18
|
-
include InstanceProcessing
|
|
19
|
-
include CollectionProcessing
|
|
20
|
-
include ViewProcessing
|
|
21
|
-
|
|
22
|
-
KEY_HANDLERS = {
|
|
23
|
-
lml_version: :process_lml_version,
|
|
24
|
-
requires: :process_requires,
|
|
25
|
-
instances: :process_instances,
|
|
26
|
-
instance: :process_instance,
|
|
27
|
-
attributes: :process_attributes,
|
|
28
|
-
value_decl: :process_value_declaration,
|
|
29
|
-
show_list: :process_show_list,
|
|
30
|
-
hide_list: :process_hide_list,
|
|
31
|
-
}.freeze
|
|
32
|
-
|
|
33
|
-
def self.process(obj)
|
|
34
|
-
new.process_data(obj)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def process_data(obj)
|
|
38
|
-
return obj unless obj.is_a?(Hash) || obj.is_a?(Array)
|
|
39
|
-
|
|
40
|
-
obj.is_a?(Array) ? obj.map { |item| process_data(item) } : process_hash(obj)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def process_hash(obj)
|
|
44
|
-
obj.each_with_object({}) do |(key, value), result|
|
|
45
|
-
handler = KEY_HANDLERS[key]
|
|
46
|
-
result[key] = handler ? public_send(handler, value) : process_data(value)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def process_requires(obj)
|
|
51
|
-
obj.map { |req| process_value(req).last }
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def process_lml_version(value)
|
|
55
|
-
value.is_a?(Hash) ? value[:string] : value
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "lutaml/model"
|
|
4
|
-
|
|
5
|
-
module Lutaml
|
|
6
|
-
module Lml
|
|
7
|
-
# One diagnostic record: a code, severity, source location, message,
|
|
8
|
-
# and a remedy. Codes are namespaced by stage (parse/validation/
|
|
9
|
-
# hydration/contract) and listed in CODES, the single source of
|
|
10
|
-
# truth also documented in the README.
|
|
11
|
-
class Diagnostic < Lutaml::Model::Serializable
|
|
12
|
-
CODES = {
|
|
13
|
-
'parse/LML-001' => {
|
|
14
|
-
severity: 'error',
|
|
15
|
-
remedy: 'Fix the syntax at the reported position.',
|
|
16
|
-
},
|
|
17
|
-
'parse/LML-002' => {
|
|
18
|
-
severity: 'error',
|
|
19
|
-
remedy: 'Terminate the block comment with */.',
|
|
20
|
-
},
|
|
21
|
-
'parse/LML-003' => {
|
|
22
|
-
severity: 'error',
|
|
23
|
-
remedy: 'Check the include path and the included file.',
|
|
24
|
-
},
|
|
25
|
-
'validation/LML-V01' => {
|
|
26
|
-
severity: 'error',
|
|
27
|
-
remedy: 'Rename or remove the duplicate definition.',
|
|
28
|
-
},
|
|
29
|
-
'validation/LML-V02' => {
|
|
30
|
-
severity: 'error',
|
|
31
|
-
remedy: 'Rename or remove the duplicate attribute.',
|
|
32
|
-
},
|
|
33
|
-
'validation/LML-V03' => {
|
|
34
|
-
severity: 'error',
|
|
35
|
-
remedy: 'Populate the mandatory attribute on the instance.',
|
|
36
|
-
},
|
|
37
|
-
'validation/LML-V04' => {
|
|
38
|
-
severity: 'error',
|
|
39
|
-
remedy: 'Use a value matching the declared primitive type.',
|
|
40
|
-
},
|
|
41
|
-
'validation/LML-V05' => {
|
|
42
|
-
severity: 'error',
|
|
43
|
-
remedy: 'Use one of the values declared for the attribute.',
|
|
44
|
-
},
|
|
45
|
-
'validation/LML-V06' => {
|
|
46
|
-
severity: 'error',
|
|
47
|
-
remedy: 'Declare the attribute or remove it from the instance.',
|
|
48
|
-
},
|
|
49
|
-
'validation/LML-V07' => {
|
|
50
|
-
severity: 'error',
|
|
51
|
-
remedy: 'Point the reference at an existing instance or attribute.',
|
|
52
|
-
},
|
|
53
|
-
'validation/LML-V08' => {
|
|
54
|
-
severity: 'error',
|
|
55
|
-
remedy: 'Break the reference cycle.',
|
|
56
|
-
},
|
|
57
|
-
'validation/LML-V09' => {
|
|
58
|
-
severity: 'error',
|
|
59
|
-
remedy: 'Use a value matching the attribute pattern.',
|
|
60
|
-
},
|
|
61
|
-
'validation/LML-V10' => {
|
|
62
|
-
severity: 'error',
|
|
63
|
-
remedy: 'Fix the attribute pattern so that it compiles.',
|
|
64
|
-
},
|
|
65
|
-
'hydration/LML-H01' => {
|
|
66
|
-
severity: 'error',
|
|
67
|
-
remedy: 'Check the instance data against the compiled model.',
|
|
68
|
-
},
|
|
69
|
-
'contract/LML-C01' => {
|
|
70
|
-
severity: 'error',
|
|
71
|
-
remedy: 'Check the path of the input file.',
|
|
72
|
-
},
|
|
73
|
-
'contract/LML-C02' => {
|
|
74
|
-
severity: 'error',
|
|
75
|
-
remedy: 'Use one of the supported input formats.',
|
|
76
|
-
},
|
|
77
|
-
'contract/LML-C03' => {
|
|
78
|
-
severity: 'error',
|
|
79
|
-
remedy: 'Check the input file and its format.',
|
|
80
|
-
},
|
|
81
|
-
'contract/LML-C04' => {
|
|
82
|
-
severity: 'error',
|
|
83
|
-
remedy: 'Use a cardinality token such as 1, 0..1, or 0..n.',
|
|
84
|
-
},
|
|
85
|
-
'contract/LML-C05' => {
|
|
86
|
-
severity: 'error',
|
|
87
|
-
remedy: 'Check the imported view path and the imported files.',
|
|
88
|
-
},
|
|
89
|
-
'contract/LML-C06' => {
|
|
90
|
-
severity: 'warning',
|
|
91
|
-
remedy: 'Use a supported language version or upgrade lutaml-lml.',
|
|
92
|
-
},
|
|
93
|
-
}.freeze
|
|
94
|
-
|
|
95
|
-
attribute :code, :string
|
|
96
|
-
attribute :severity, :string, default: 'error'
|
|
97
|
-
attribute :file, :string
|
|
98
|
-
attribute :line, :integer
|
|
99
|
-
attribute :column, :integer
|
|
100
|
-
attribute :length, :integer
|
|
101
|
-
attribute :message, :string
|
|
102
|
-
attribute :remedy, :string
|
|
103
|
-
|
|
104
|
-
key_value do
|
|
105
|
-
map 'code', to: :code
|
|
106
|
-
map 'severity', to: :severity
|
|
107
|
-
map 'file', to: :file
|
|
108
|
-
map 'line', to: :line
|
|
109
|
-
map 'column', to: :column
|
|
110
|
-
map 'length', to: :length
|
|
111
|
-
map 'message', to: :message
|
|
112
|
-
map 'remedy', to: :remedy
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def self.build(code, message:, file: nil, line: nil, column: nil,
|
|
116
|
-
length: nil, severity: nil, remedy: nil)
|
|
117
|
-
entry = CODES.fetch(code)
|
|
118
|
-
new(
|
|
119
|
-
code: code,
|
|
120
|
-
severity: severity || entry[:severity],
|
|
121
|
-
file: file,
|
|
122
|
-
line: line,
|
|
123
|
-
column: column,
|
|
124
|
-
length: length,
|
|
125
|
-
message: message,
|
|
126
|
-
remedy: remedy || entry[:remedy],
|
|
127
|
-
)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
# Human rendering: `path:line:col: [CODE] message`, then the
|
|
131
|
-
# remedy. Position segments are omitted when the parser could not
|
|
132
|
-
# attach them.
|
|
133
|
-
def to_s
|
|
134
|
-
"#{location}[#{code}] #{message}#{remedy_suffix}"
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def location
|
|
138
|
-
parts = [file, line, column].compact
|
|
139
|
-
parts.empty? ? '' : "#{parts.join(':')}: "
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
private
|
|
143
|
-
|
|
144
|
-
def remedy_suffix
|
|
145
|
-
remedy.to_s.empty? ? '' : "\n remedy: #{remedy}"
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|