lutaml-lml 0.1.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/lib/lutaml/lml/association_label_resolver.rb +52 -0
- data/lib/lutaml/lml/cli.rb +262 -0
- data/lib/lutaml/lml/data_processor/attribute_processing.rb +81 -0
- data/lib/lutaml/lml/data_processor/collection_processing.rb +37 -0
- data/lib/lutaml/lml/data_processor/instance_processing.rb +63 -0
- data/lib/lutaml/lml/data_processor/value_processing.rb +98 -0
- data/lib/lutaml/lml/data_processor/view_processing.rb +25 -0
- data/lib/lutaml/lml/data_processor.rb +49 -0
- data/lib/lutaml/lml/document_builder.rb +139 -0
- data/lib/lutaml/lml/executor/adapter_helpers.rb +45 -0
- data/lib/lutaml/lml/executor/condition_evaluator.rb +169 -0
- data/lib/lutaml/lml/executor/csv_adapter.rb +88 -0
- data/lib/lutaml/lml/executor/format_adapter.rb +54 -0
- data/lib/lutaml/lml/executor/xml_adapter.rb +102 -0
- data/lib/lutaml/lml/executor.rb +89 -0
- data/lib/lutaml/lml/format/adapter/document.rb +11 -0
- data/lib/lutaml/lml/format/adapter/mapping.rb +19 -0
- data/lib/lutaml/lml/format/adapter/standard_adapter.rb +127 -0
- data/lib/lutaml/lml/format/adapter/transform.rb +11 -0
- data/lib/lutaml/lml/format.rb +29 -0
- data/lib/lutaml/lml/formatter/base.rb +79 -0
- data/lib/lutaml/lml/formatter/graphviz/document_formatter.rb +89 -0
- data/lib/lutaml/lml/formatter/graphviz/html_builder.rb +72 -0
- data/lib/lutaml/lml/formatter/graphviz/node_formatter.rb +74 -0
- data/lib/lutaml/lml/formatter/graphviz/relationship_formatter.rb +130 -0
- data/lib/lutaml/lml/formatter/graphviz.rb +90 -0
- data/lib/lutaml/lml/formatter.rb +8 -0
- data/lib/lutaml/lml/grammar/concerns/associations.rb +76 -0
- data/lib/lutaml/lml/grammar/concerns/attributes.rb +126 -0
- data/lib/lutaml/lml/grammar/concerns/data_structures.rb +84 -0
- data/lib/lutaml/lml/grammar/concerns/definitions.rb +222 -0
- data/lib/lutaml/lml/grammar/concerns/instance_rules.rb +59 -0
- data/lib/lutaml/lml/grammar/concerns/primitives.rb +89 -0
- data/lib/lutaml/lml/grammar/concerns/view_rules.rb +34 -0
- data/lib/lutaml/lml/grammar/concerns.rb +17 -0
- data/lib/lutaml/lml/grammar/core.rb +71 -0
- data/lib/lutaml/lml/grammar/full.rb +12 -0
- data/lib/lutaml/lml/grammar/instances.rb +38 -0
- data/lib/lutaml/lml/grammar.rb +12 -0
- data/lib/lutaml/lml/has_attributes.rb +14 -0
- data/lib/lutaml/lml/import_resolver.rb +89 -0
- data/lib/lutaml/lml/layout/engine.rb +17 -0
- data/lib/lutaml/lml/layout/graph_viz_engine.rb +19 -0
- data/lib/lutaml/lml/layout.rb +8 -0
- data/lib/lutaml/lml/model_compiler.rb +325 -0
- data/lib/lutaml/lml/models/action.rb +10 -0
- data/lib/lutaml/lml/models/association.rb +26 -0
- data/lib/lutaml/lml/models/cardinality.rb +10 -0
- data/lib/lutaml/lml/models/collection.rb +11 -0
- data/lib/lutaml/lml/models/constraint.rb +20 -0
- data/lib/lutaml/lml/models/data_type.rb +31 -0
- data/lib/lutaml/lml/models/diagram.rb +17 -0
- data/lib/lutaml/lml/models/document.rb +45 -0
- data/lib/lutaml/lml/models/enum.rb +28 -0
- data/lib/lutaml/lml/models/fidelity.rb +10 -0
- data/lib/lutaml/lml/models/group.rb +11 -0
- data/lib/lutaml/lml/models/instance.rb +13 -0
- data/lib/lutaml/lml/models/instance_collection.rb +12 -0
- data/lib/lutaml/lml/models/instances_export.rb +10 -0
- data/lib/lutaml/lml/models/instances_import.rb +11 -0
- data/lib/lutaml/lml/models/operation.rb +23 -0
- data/lib/lutaml/lml/models/operation_parameter.rb +11 -0
- data/lib/lutaml/lml/models/package.rb +22 -0
- data/lib/lutaml/lml/models/primitive_type.rb +26 -0
- data/lib/lutaml/lml/models/top_element_attribute.rb +31 -0
- data/lib/lutaml/lml/models/uml_class.rb +84 -0
- data/lib/lutaml/lml/models/value.rb +12 -0
- data/lib/lutaml/lml/models/view_filter.rb +11 -0
- data/lib/lutaml/lml/models/view_import.rb +11 -0
- data/lib/lutaml/lml/parser.rb +22 -0
- data/lib/lutaml/lml/pipeline.rb +64 -0
- data/lib/lutaml/lml/preprocessor.rb +56 -0
- data/lib/lutaml/lml/transform.rb +20 -0
- data/lib/lutaml/lml/version.rb +7 -0
- data/lib/lutaml/lml/view_resolver.rb +48 -0
- data/lib/lutaml/lml/yaml_parser.rb +17 -0
- data/lib/lutaml/lml.rb +67 -0
- metadata +178 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'open3'
|
|
4
|
+
require 'set'
|
|
5
|
+
|
|
6
|
+
module Lutaml
|
|
7
|
+
module Formatter
|
|
8
|
+
class Graphviz < Base
|
|
9
|
+
autoload :HtmlBuilder, "lutaml/lml/formatter/graphviz/html_builder"
|
|
10
|
+
autoload :NodeFormatter, "lutaml/lml/formatter/graphviz/node_formatter"
|
|
11
|
+
autoload :RelationshipFormatter, "lutaml/lml/formatter/graphviz/relationship_formatter"
|
|
12
|
+
autoload :DocumentFormatter, "lutaml/lml/formatter/graphviz/document_formatter"
|
|
13
|
+
|
|
14
|
+
include HtmlBuilder
|
|
15
|
+
include NodeFormatter
|
|
16
|
+
include RelationshipFormatter
|
|
17
|
+
include DocumentFormatter
|
|
18
|
+
|
|
19
|
+
class Attributes < Hash
|
|
20
|
+
def to_s
|
|
21
|
+
to_a
|
|
22
|
+
.reject { |(_k, val)| val.nil? }
|
|
23
|
+
.map { |(a, b)| "#{a}=#{b.inspect}" }
|
|
24
|
+
.join(' ')
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
DEFAULT_CLASS_FONT = 'Helvetica'
|
|
29
|
+
|
|
30
|
+
VALID_TYPES = %i[
|
|
31
|
+
dot xdot ps pdf svg svgz fig png gif jpg jpeg json imap cmapx
|
|
32
|
+
].freeze
|
|
33
|
+
|
|
34
|
+
def initialize(attributes = {})
|
|
35
|
+
super
|
|
36
|
+
setup_default_attributes
|
|
37
|
+
@type = :dot
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
attr_reader :graph, :edge, :node
|
|
41
|
+
|
|
42
|
+
def type=(value)
|
|
43
|
+
super
|
|
44
|
+
@type = :dot unless VALID_TYPES.include?(@type)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def format(node)
|
|
48
|
+
dot = super.lines.map(&:rstrip).join("\n")
|
|
49
|
+
generate_from_dot(dot)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def setup_default_attributes
|
|
53
|
+
@graph = build_graph_attrs
|
|
54
|
+
@edge = build_edge_attrs
|
|
55
|
+
@node = build_node_attrs
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def build_graph_attrs
|
|
59
|
+
Attributes.new.tap do |g|
|
|
60
|
+
g['splines'] = 'ortho'
|
|
61
|
+
g['pad'] = '0.5'
|
|
62
|
+
g['ranksep'] = '1.2'
|
|
63
|
+
g['nodesep'] = '1.2'
|
|
64
|
+
g['rankdir'] = 'BT'
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def build_edge_attrs
|
|
69
|
+
Attributes.new.tap { |e| e['color'] = 'gray50' }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def build_node_attrs
|
|
73
|
+
Attributes.new.tap { |n| n['shape'] = 'box' }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private :setup_default_attributes, :build_graph_attrs,
|
|
77
|
+
:build_edge_attrs, :build_node_attrs
|
|
78
|
+
|
|
79
|
+
protected
|
|
80
|
+
|
|
81
|
+
def generate_from_dot(input)
|
|
82
|
+
Lutaml::Layout::GraphVizEngine.new(input: input).render(@type)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def generate_graph_name(name)
|
|
86
|
+
name.gsub(/[^0-9a-zA-Z]/i, '')
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
module Grammar
|
|
6
|
+
module Concerns
|
|
7
|
+
module Associations
|
|
8
|
+
include Parslet
|
|
9
|
+
|
|
10
|
+
rule(:association_keyword) { kw_association >> spaces }
|
|
11
|
+
|
|
12
|
+
%w[owner member].each do |association_end_type|
|
|
13
|
+
rule("#{association_end_type}_cardinality") do
|
|
14
|
+
spaces? >>
|
|
15
|
+
str("[") >>
|
|
16
|
+
cardinality_body_definition
|
|
17
|
+
.as("#{association_end_type}_end_cardinality") >>
|
|
18
|
+
str("]")
|
|
19
|
+
end
|
|
20
|
+
rule("#{association_end_type}_cardinality?") do
|
|
21
|
+
public_send(:"#{association_end_type}_cardinality").maybe
|
|
22
|
+
end
|
|
23
|
+
rule("#{association_end_type}_attribute_name") do
|
|
24
|
+
str("#") >>
|
|
25
|
+
visibility? >>
|
|
26
|
+
spaces? >>
|
|
27
|
+
variable.as("#{association_end_type}_end_attribute_name") >>
|
|
28
|
+
spaces?
|
|
29
|
+
end
|
|
30
|
+
rule("#{association_end_type}_attribute_name?") do
|
|
31
|
+
public_send(:"#{association_end_type}_attribute_name").maybe
|
|
32
|
+
end
|
|
33
|
+
rule("#{association_end_type}_definition") do
|
|
34
|
+
public_send(:"kw_#{association_end_type}") >>
|
|
35
|
+
spaces >>
|
|
36
|
+
variable.as("#{association_end_type}_end") >>
|
|
37
|
+
public_send(:"#{association_end_type}_attribute_name?") >>
|
|
38
|
+
public_send(:"#{association_end_type}_cardinality?")
|
|
39
|
+
end
|
|
40
|
+
rule("#{association_end_type}_type") do
|
|
41
|
+
public_send(:"kw_#{association_end_type}_type") >>
|
|
42
|
+
spaces >>
|
|
43
|
+
variable.as("#{association_end_type}_end_type")
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
rule(:association_inner_definitions) do
|
|
48
|
+
owner_type |
|
|
49
|
+
member_type |
|
|
50
|
+
owner_definition |
|
|
51
|
+
member_definition |
|
|
52
|
+
comment_definition |
|
|
53
|
+
comment_multiline_definition
|
|
54
|
+
end
|
|
55
|
+
rule(:association_inner_definition) do
|
|
56
|
+
association_inner_definitions >> whitespace?
|
|
57
|
+
end
|
|
58
|
+
rule(:association_body) do
|
|
59
|
+
spaces? >>
|
|
60
|
+
str("{") >>
|
|
61
|
+
whitespace? >>
|
|
62
|
+
association_inner_definition.repeat.as(:members) >>
|
|
63
|
+
str("}")
|
|
64
|
+
end
|
|
65
|
+
rule(:association_definition) do
|
|
66
|
+
association_keyword >>
|
|
67
|
+
spaces? >>
|
|
68
|
+
variable.as(:name).maybe >>
|
|
69
|
+
spaces? >>
|
|
70
|
+
association_body
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
module Grammar
|
|
6
|
+
module Concerns
|
|
7
|
+
module Attributes
|
|
8
|
+
include Parslet
|
|
9
|
+
|
|
10
|
+
rule(:attribute) do
|
|
11
|
+
comment_definition |
|
|
12
|
+
variable.as(:key) >> spaces? >> str("+").as(:add).maybe >> str("=").maybe >> spaces? >> attribute_value.as(:value)
|
|
13
|
+
end
|
|
14
|
+
rule(:attributes) do
|
|
15
|
+
(
|
|
16
|
+
attribute_line | whitespace
|
|
17
|
+
).repeat.as(:attributes)
|
|
18
|
+
end
|
|
19
|
+
rule(:attribute_line) do
|
|
20
|
+
spaces? >> attribute >> (str(",").maybe >> whitespace).maybe
|
|
21
|
+
end
|
|
22
|
+
rule(:member_static) { (kw_static.as(:static) >> spaces).maybe }
|
|
23
|
+
rule(:visibility) do
|
|
24
|
+
kw_visibility_modifier.as(:visibility_modifier)
|
|
25
|
+
end
|
|
26
|
+
rule(:visibility?) { visibility.maybe }
|
|
27
|
+
|
|
28
|
+
rule(:method_abstract) { (kw_abstract.as(:abstract) >> spaces).maybe }
|
|
29
|
+
rule(:attribute_keyword) do
|
|
30
|
+
str("<<") >>
|
|
31
|
+
match['a-zA-Z0-9_\-\/'].repeat(1).as(:keyword) >>
|
|
32
|
+
str(">>")
|
|
33
|
+
end
|
|
34
|
+
rule(:attribute_keyword?) { attribute_keyword.maybe }
|
|
35
|
+
rule(:attribute_type) do
|
|
36
|
+
(str(":").maybe >>
|
|
37
|
+
spaces? >>
|
|
38
|
+
attribute_keyword? >>
|
|
39
|
+
spaces? >>
|
|
40
|
+
quotes? >>
|
|
41
|
+
match['a-zA-Z0-9_\- \/\+'].repeat(1).as(:type) >>
|
|
42
|
+
quotes? >>
|
|
43
|
+
spaces?
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
rule(:attribute_type?) do
|
|
47
|
+
attribute_type.maybe
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
rule(:attribute_name) { match['a-zA-Z0-9_\-\/\+'].repeat(1).as(:name) }
|
|
51
|
+
rule(:attribute_definition_name) do
|
|
52
|
+
(quotes >> match['a-zA-Z0-9_\- \/\+'].repeat(1).as(:name) >> quotes) |
|
|
53
|
+
attribute_name
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
rule(:attribute_definition) do
|
|
57
|
+
(visibility?.as(:visibility) >>
|
|
58
|
+
spaces? >>
|
|
59
|
+
attribute_definition_name >>
|
|
60
|
+
spaces? >>
|
|
61
|
+
attribute_type? >>
|
|
62
|
+
cardinality? >>
|
|
63
|
+
class_body?)
|
|
64
|
+
.as(:attributes)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
rule(:keyword_type_argument) do
|
|
68
|
+
(
|
|
69
|
+
str("type") >>
|
|
70
|
+
spaces? >>
|
|
71
|
+
match["[^\s\n\r]"].repeat(1).as(:type) >>
|
|
72
|
+
whitespace?
|
|
73
|
+
)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
rule(:keyword_cardinality_argument) do
|
|
77
|
+
(
|
|
78
|
+
str("cardinality") >>
|
|
79
|
+
spaces? >>
|
|
80
|
+
cardinality_body_definition.as(:cardinality) >>
|
|
81
|
+
whitespace?
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
rule(:keyword_any_argument) do
|
|
86
|
+
(
|
|
87
|
+
spaces? >>
|
|
88
|
+
match("[^\s\n\r]").repeat(1).as(:name) >>
|
|
89
|
+
spaces >>
|
|
90
|
+
str("=").maybe >>
|
|
91
|
+
spaces? >>
|
|
92
|
+
attribute_value.as(:value) >>
|
|
93
|
+
whitespace?
|
|
94
|
+
)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
rule(:keyword_attribute_options) do
|
|
98
|
+
(
|
|
99
|
+
keyword_type_argument |
|
|
100
|
+
keyword_cardinality_argument |
|
|
101
|
+
keyword_any_argument.as(:properties)
|
|
102
|
+
).repeat
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
rule(:keyword_attribute_body) do
|
|
106
|
+
str("{") >>
|
|
107
|
+
whitespace? >>
|
|
108
|
+
keyword_attribute_options >>
|
|
109
|
+
whitespace? >>
|
|
110
|
+
str("}")
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
rule(:keyword_attribute_definition) do
|
|
114
|
+
(
|
|
115
|
+
str("attribute") >>
|
|
116
|
+
spaces >>
|
|
117
|
+
attribute_name >>
|
|
118
|
+
spaces? >>
|
|
119
|
+
keyword_attribute_body
|
|
120
|
+
).as(:attributes)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
module Grammar
|
|
6
|
+
module Concerns
|
|
7
|
+
module DataStructures
|
|
8
|
+
include Parslet
|
|
9
|
+
|
|
10
|
+
rule(:attribute_value) { instance | list | key_value_map | value | match("[^\n]").repeat(1) }
|
|
11
|
+
|
|
12
|
+
rule(:list_item) { instance | value }
|
|
13
|
+
rule(:list) do
|
|
14
|
+
str("[") >> whitespace? >>
|
|
15
|
+
(list_item >> spaces? >> str(",").maybe >> whitespace?).repeat.as(:list) >> whitespace? >>
|
|
16
|
+
str("]")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
rule(:collection) do
|
|
20
|
+
kw_collection >> spaces >> quoted_string.as(:name) >> spaces? >>
|
|
21
|
+
str("{") >> whitespace? >>
|
|
22
|
+
includes.maybe >> whitespace? >>
|
|
23
|
+
validation.maybe >> whitespace? >>
|
|
24
|
+
str("}") >> whitespace?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
rule(:includes) do
|
|
28
|
+
kw_includes >> spaces? >> list.as(:includes)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
rule(:validation) do
|
|
32
|
+
kw_validation >> spaces? >> str("{") >> whitespace? >>
|
|
33
|
+
condition.repeat.as(:validations) >>
|
|
34
|
+
str("}")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
rule(:condition) do
|
|
38
|
+
kw_condition >> spaces >> quoted_string.as(:condition) >> whitespace?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
rule(:import) do
|
|
42
|
+
kw_import >> spaces? >> str("{") >> whitespace? >>
|
|
43
|
+
import_definition.repeat.as(:imports) >>
|
|
44
|
+
str("}") >> whitespace?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
rule(:import_definition) do
|
|
48
|
+
match("[^\s\n\r]").repeat(1).as(:format_type) >> spaces? >> quoted_string.as(:file) >> whitespace? >>
|
|
49
|
+
str("{") >> whitespace? >>
|
|
50
|
+
attributes >> whitespace? >>
|
|
51
|
+
str("}") >> whitespace?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
rule(:instances) do
|
|
55
|
+
kw_instances >> whitespace? >>
|
|
56
|
+
str("{") >> whitespace? >>
|
|
57
|
+
instances_body.maybe >>
|
|
58
|
+
str("}") >> whitespace?
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
rule(:instances_body) do
|
|
62
|
+
(instances_member >> whitespace?).repeat.as(:instances)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
rule(:instances_member) do
|
|
66
|
+
import | collection.as(:collections) | export | instance
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
rule(:export) do
|
|
70
|
+
kw_export >> whitespace? >> str("{") >> whitespace? >>
|
|
71
|
+
(export_format >> whitespace?).repeat.as(:exports) >>
|
|
72
|
+
str("}") >> whitespace?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
rule(:export_format) do
|
|
76
|
+
kw_format >> spaces >> variable.as(:format_type) >> whitespace? >> str("{") >> whitespace? >>
|
|
77
|
+
attributes >>
|
|
78
|
+
str("}") >> whitespace?
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
module Grammar
|
|
6
|
+
module Concerns
|
|
7
|
+
module Definitions
|
|
8
|
+
include Parslet
|
|
9
|
+
|
|
10
|
+
# -- Class
|
|
11
|
+
rule(:kw_class_modifier) { kw_abstract | kw_interface }
|
|
12
|
+
|
|
13
|
+
rule(:class_modifier) do
|
|
14
|
+
(kw_class_modifier.as(:modifier) >> spaces).maybe
|
|
15
|
+
end
|
|
16
|
+
rule(:class_keyword) { kw_class >> spaces }
|
|
17
|
+
rule(:class_inner_definitions) do
|
|
18
|
+
definition_body |
|
|
19
|
+
((str("attribute") >> spaces).absent? >> attribute_definition) |
|
|
20
|
+
keyword_attribute_definition |
|
|
21
|
+
comment_definition |
|
|
22
|
+
comment_multiline_definition
|
|
23
|
+
end
|
|
24
|
+
rule(:class_inner_definition) do
|
|
25
|
+
class_inner_definitions >> whitespace?
|
|
26
|
+
end
|
|
27
|
+
rule(:class_body) do
|
|
28
|
+
spaces? >>
|
|
29
|
+
str("{") >>
|
|
30
|
+
whitespace? >>
|
|
31
|
+
class_inner_definition.repeat.as(:members) >>
|
|
32
|
+
str("}")
|
|
33
|
+
end
|
|
34
|
+
rule(:class_body?) { class_body.maybe }
|
|
35
|
+
|
|
36
|
+
rule(:parent_class) do
|
|
37
|
+
spaces? >> str("<") >> spaces? >> class_name_chars.as(:parent_class)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
rule(:class_definition) do
|
|
41
|
+
class_modifier >>
|
|
42
|
+
class_keyword >>
|
|
43
|
+
class_name.as(:name) >>
|
|
44
|
+
parent_class.maybe >>
|
|
45
|
+
spaces? >>
|
|
46
|
+
attribute_keyword? >>
|
|
47
|
+
class_body?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# -- Definition
|
|
51
|
+
rule(:definition_body) do
|
|
52
|
+
spaces? >>
|
|
53
|
+
str("definition") >>
|
|
54
|
+
whitespace? >>
|
|
55
|
+
str("{") >>
|
|
56
|
+
((str("\\") >> any) | (str("}").absent? >> any))
|
|
57
|
+
.repeat.maybe.as(:definition) >>
|
|
58
|
+
str("}")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# -- Enum
|
|
62
|
+
rule(:enum_keyword) { kw_enum >> spaces }
|
|
63
|
+
rule(:enum_inner_definitions) do
|
|
64
|
+
definition_body |
|
|
65
|
+
attribute_definition |
|
|
66
|
+
comment_definition |
|
|
67
|
+
comment_multiline_definition
|
|
68
|
+
end
|
|
69
|
+
rule(:enum_inner_definition) do
|
|
70
|
+
enum_inner_definitions >> whitespace?
|
|
71
|
+
end
|
|
72
|
+
rule(:enum_body) do
|
|
73
|
+
spaces? >>
|
|
74
|
+
str("{") >>
|
|
75
|
+
whitespace? >>
|
|
76
|
+
enum_inner_definition.repeat.as(:members) >>
|
|
77
|
+
str("}")
|
|
78
|
+
end
|
|
79
|
+
rule(:enum_body?) { enum_body.maybe }
|
|
80
|
+
rule(:enum_definition) do
|
|
81
|
+
enum_keyword >>
|
|
82
|
+
quotes? >>
|
|
83
|
+
class_name.as(:name) >>
|
|
84
|
+
quotes? >>
|
|
85
|
+
attribute_keyword? >>
|
|
86
|
+
enum_body?
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# -- data_type
|
|
90
|
+
rule(:data_type_keyword) { kw_data_type >> spaces }
|
|
91
|
+
rule(:data_type_inner_definitions) do
|
|
92
|
+
definition_body |
|
|
93
|
+
attribute_definition |
|
|
94
|
+
comment_definition |
|
|
95
|
+
comment_multiline_definition
|
|
96
|
+
end
|
|
97
|
+
rule(:data_type_inner_definition) do
|
|
98
|
+
data_type_inner_definitions >> whitespace?
|
|
99
|
+
end
|
|
100
|
+
rule(:data_type_body) do
|
|
101
|
+
spaces? >>
|
|
102
|
+
str("{") >>
|
|
103
|
+
whitespace? >>
|
|
104
|
+
data_type_inner_definition.repeat.as(:members) >>
|
|
105
|
+
str("}")
|
|
106
|
+
end
|
|
107
|
+
rule(:data_type_body?) { data_type_body.maybe }
|
|
108
|
+
rule(:data_type_definition) do
|
|
109
|
+
data_type_keyword >>
|
|
110
|
+
quotes? >>
|
|
111
|
+
class_name.as(:name) >>
|
|
112
|
+
quotes? >>
|
|
113
|
+
attribute_keyword? >>
|
|
114
|
+
data_type_body?
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# -- primitive
|
|
118
|
+
rule(:primitive_keyword) { kw_primitive >> spaces }
|
|
119
|
+
rule(:primitive_definition) do
|
|
120
|
+
primitive_keyword >>
|
|
121
|
+
quotes? >>
|
|
122
|
+
class_name.as(:name) >>
|
|
123
|
+
quotes?
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# -- Diagram
|
|
127
|
+
rule(:diagram_keyword) { kw_diagram >> spaces? }
|
|
128
|
+
rule(:diagram_inner_definitions) do
|
|
129
|
+
title_definition |
|
|
130
|
+
caption_definition |
|
|
131
|
+
fontname_definition |
|
|
132
|
+
class_definition.as(:classes) |
|
|
133
|
+
enum_definition.as(:enums) |
|
|
134
|
+
primitive_definition.as(:primitives) |
|
|
135
|
+
data_type_definition.as(:data_types) |
|
|
136
|
+
association_definition.as(:associations) |
|
|
137
|
+
comment_definition |
|
|
138
|
+
comment_multiline_definition
|
|
139
|
+
end
|
|
140
|
+
rule(:diagram_inner_definition) do
|
|
141
|
+
diagram_inner_definitions >> whitespace?
|
|
142
|
+
end
|
|
143
|
+
rule(:diagram_body) do
|
|
144
|
+
spaces? >>
|
|
145
|
+
str("{") >>
|
|
146
|
+
whitespace? >>
|
|
147
|
+
diagram_inner_definition.repeat.as(:members) >>
|
|
148
|
+
str("}")
|
|
149
|
+
end
|
|
150
|
+
rule(:diagram_definition) do
|
|
151
|
+
diagram_keyword >>
|
|
152
|
+
spaces? >>
|
|
153
|
+
class_name.as(:name) >>
|
|
154
|
+
diagram_body >>
|
|
155
|
+
whitespace?
|
|
156
|
+
end
|
|
157
|
+
rule(:diagram_definitions) { diagram_definition >> whitespace? }
|
|
158
|
+
|
|
159
|
+
# -- View (extends diagram with import/show/hide)
|
|
160
|
+
rule(:view_keyword) { kw_view >> spaces? }
|
|
161
|
+
rule(:view_inner_definitions) do
|
|
162
|
+
title_definition |
|
|
163
|
+
caption_definition |
|
|
164
|
+
fontname_definition |
|
|
165
|
+
view_import.as(:view_imports) |
|
|
166
|
+
show_directive |
|
|
167
|
+
hide_directive |
|
|
168
|
+
class_definition.as(:classes) |
|
|
169
|
+
enum_definition.as(:enums) |
|
|
170
|
+
primitive_definition.as(:primitives) |
|
|
171
|
+
data_type_definition.as(:data_types) |
|
|
172
|
+
association_definition.as(:associations) |
|
|
173
|
+
comment_definition |
|
|
174
|
+
comment_multiline_definition
|
|
175
|
+
end
|
|
176
|
+
rule(:view_inner_definition) do
|
|
177
|
+
view_inner_definitions >> whitespace?
|
|
178
|
+
end
|
|
179
|
+
rule(:view_body) do
|
|
180
|
+
spaces? >>
|
|
181
|
+
str("{") >>
|
|
182
|
+
whitespace? >>
|
|
183
|
+
view_inner_definition.repeat.as(:members) >>
|
|
184
|
+
str("}")
|
|
185
|
+
end
|
|
186
|
+
rule(:view_definition) do
|
|
187
|
+
view_keyword >>
|
|
188
|
+
spaces? >>
|
|
189
|
+
class_name.as(:name) >>
|
|
190
|
+
view_body >>
|
|
191
|
+
whitespace?
|
|
192
|
+
end
|
|
193
|
+
rule(:view_definitions) { view_definition >> whitespace? }
|
|
194
|
+
|
|
195
|
+
# -- Metadata
|
|
196
|
+
rule(:title_keyword) { kw_title >> spaces }
|
|
197
|
+
rule(:title_text) do
|
|
198
|
+
quotes? >>
|
|
199
|
+
match['a-zA-Z0-9_\- ,.:;'].repeat(1).as(:title) >>
|
|
200
|
+
quotes?
|
|
201
|
+
end
|
|
202
|
+
rule(:title_definition) { title_keyword >> title_text }
|
|
203
|
+
rule(:caption_keyword) { kw_caption >> spaces }
|
|
204
|
+
rule(:caption_text) do
|
|
205
|
+
quotes? >>
|
|
206
|
+
match['a-zA-Z0-9_\- ,.:;'].repeat(1).as(:caption) >>
|
|
207
|
+
quotes?
|
|
208
|
+
end
|
|
209
|
+
rule(:caption_definition) { caption_keyword >> caption_text }
|
|
210
|
+
|
|
211
|
+
rule(:fontname_keyword) { kw_fontname >> spaces }
|
|
212
|
+
rule(:fontname_text) do
|
|
213
|
+
quotes? >>
|
|
214
|
+
match['a-zA-Z0-9_\- '].repeat(1).as(:fontname) >>
|
|
215
|
+
quotes?
|
|
216
|
+
end
|
|
217
|
+
rule(:fontname_definition) { fontname_keyword >> fontname_text }
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
module Grammar
|
|
6
|
+
module Concerns
|
|
7
|
+
module InstanceRules
|
|
8
|
+
include Parslet
|
|
9
|
+
|
|
10
|
+
rule(:instance) do
|
|
11
|
+
keyword_instance | class_instance
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
rule(:keyword_instance) do
|
|
15
|
+
(
|
|
16
|
+
kw_instance >> (spaces >> namespaced_identifier.as(:instance_type)).maybe >> spaces? >>
|
|
17
|
+
str("{") >> whitespace? >>
|
|
18
|
+
((spaces? >> instance) | attributes) >>
|
|
19
|
+
str("}")
|
|
20
|
+
).as(:instance) >> whitespace?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
rule(:class_instance) do
|
|
24
|
+
(variable.as(:instance_type) >> whitespace? >> quoted_string.as(:name) >> whitespace? >>
|
|
25
|
+
(kw_extends >> whitespace? >> quoted_string.as(:parent) >> whitespace?).maybe >>
|
|
26
|
+
str("{") >> whitespace? >>
|
|
27
|
+
lml_instance_body.maybe >>
|
|
28
|
+
str("}")).as(:instance) >> whitespace?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
rule(:lml_instance_body) do
|
|
32
|
+
(lml_instance_members >> whitespace?)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
rule(:instance_template) do
|
|
36
|
+
kw_template >> whitespace? >> str("{") >> whitespace? >>
|
|
37
|
+
attributes >> whitespace? >>
|
|
38
|
+
str("}") >> whitespace?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
rule(:lml_instance_members) do
|
|
42
|
+
instance_template.as(:template) | attributes
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
rule(:models) do
|
|
46
|
+
kw_models >> whitespace? >>
|
|
47
|
+
variable.as(:name) >> whitespace? >> str("{") >>
|
|
48
|
+
model_body.repeat.as(:members) >>
|
|
49
|
+
str("}") >> whitespace?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
rule(:model_body) do
|
|
53
|
+
(class_definition.as(:classes) | enum_definition.as(:enums)) >> whitespace?
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|