expressir 1.2.5-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/.cross_rubies +15 -0
  3. data/.github/workflows/rake.yml +300 -0
  4. data/.github/workflows/release.yml +120 -0
  5. data/.gitignore +23 -0
  6. data/.gitmodules +6 -0
  7. data/.hound.yml +3 -0
  8. data/.rspec +2 -0
  9. data/.rubocop.yml +17 -0
  10. data/.yardopts +11 -0
  11. data/Gemfile +4 -0
  12. data/README.adoc +147 -0
  13. data/Rakefile +17 -0
  14. data/bin/console +11 -0
  15. data/bin/rspec +29 -0
  16. data/bin/setup +8 -0
  17. data/docs/development.md +90 -0
  18. data/exe/expressir +22 -0
  19. data/exe/format +18 -0
  20. data/exe/format-test +81 -0
  21. data/exe/generate-parser +51 -0
  22. data/expressir.gemspec +48 -0
  23. data/lib/expressir/cli/ui.rb +36 -0
  24. data/lib/expressir/cli.rb +21 -0
  25. data/lib/expressir/config.rb +23 -0
  26. data/lib/expressir/express/3.1/express_parser.so +0 -0
  27. data/lib/expressir/express/cache.rb +51 -0
  28. data/lib/expressir/express/formatter.rb +1608 -0
  29. data/lib/expressir/express/hyperlink_formatter.rb +36 -0
  30. data/lib/expressir/express/model_visitor.rb +24 -0
  31. data/lib/expressir/express/parser.rb +84 -0
  32. data/lib/expressir/express/resolve_references_model_visitor.rb +31 -0
  33. data/lib/expressir/express/schema_head_formatter.rb +23 -0
  34. data/lib/expressir/express/visitor.rb +2578 -0
  35. data/lib/expressir/model/cache.rb +17 -0
  36. data/lib/expressir/model/data_type.rb +9 -0
  37. data/lib/expressir/model/data_types/aggregate.rb +31 -0
  38. data/lib/expressir/model/data_types/array.rb +31 -0
  39. data/lib/expressir/model/data_types/bag.rb +25 -0
  40. data/lib/expressir/model/data_types/binary.rb +22 -0
  41. data/lib/expressir/model/data_types/boolean.rb +10 -0
  42. data/lib/expressir/model/data_types/enumeration.rb +25 -0
  43. data/lib/expressir/model/data_types/enumeration_item.rb +26 -0
  44. data/lib/expressir/model/data_types/generic.rb +26 -0
  45. data/lib/expressir/model/data_types/generic_entity.rb +26 -0
  46. data/lib/expressir/model/data_types/integer.rb +10 -0
  47. data/lib/expressir/model/data_types/list.rb +28 -0
  48. data/lib/expressir/model/data_types/logical.rb +10 -0
  49. data/lib/expressir/model/data_types/number.rb +10 -0
  50. data/lib/expressir/model/data_types/real.rb +19 -0
  51. data/lib/expressir/model/data_types/select.rb +28 -0
  52. data/lib/expressir/model/data_types/set.rb +25 -0
  53. data/lib/expressir/model/data_types/string.rb +22 -0
  54. data/lib/expressir/model/declaration.rb +9 -0
  55. data/lib/expressir/model/declarations/attribute.rb +47 -0
  56. data/lib/expressir/model/declarations/constant.rb +34 -0
  57. data/lib/expressir/model/declarations/entity.rb +53 -0
  58. data/lib/expressir/model/declarations/function.rb +67 -0
  59. data/lib/expressir/model/declarations/interface.rb +28 -0
  60. data/lib/expressir/model/declarations/interface_item.rb +23 -0
  61. data/lib/expressir/model/declarations/interfaced_item.rb +37 -0
  62. data/lib/expressir/model/declarations/parameter.rb +34 -0
  63. data/lib/expressir/model/declarations/procedure.rb +64 -0
  64. data/lib/expressir/model/declarations/remark_item.rb +21 -0
  65. data/lib/expressir/model/declarations/rule.rb +71 -0
  66. data/lib/expressir/model/declarations/schema.rb +117 -0
  67. data/lib/expressir/model/declarations/schema_version.rb +22 -0
  68. data/lib/expressir/model/declarations/schema_version_item.rb +22 -0
  69. data/lib/expressir/model/declarations/subtype_constraint.rb +40 -0
  70. data/lib/expressir/model/declarations/type.rb +45 -0
  71. data/lib/expressir/model/declarations/unique_rule.rb +31 -0
  72. data/lib/expressir/model/declarations/variable.rb +34 -0
  73. data/lib/expressir/model/declarations/where_rule.rb +31 -0
  74. data/lib/expressir/model/expression.rb +9 -0
  75. data/lib/expressir/model/expressions/aggregate_initializer.rb +19 -0
  76. data/lib/expressir/model/expressions/aggregate_initializer_item.rb +22 -0
  77. data/lib/expressir/model/expressions/binary_expression.rb +53 -0
  78. data/lib/expressir/model/expressions/entity_constructor.rb +22 -0
  79. data/lib/expressir/model/expressions/function_call.rb +22 -0
  80. data/lib/expressir/model/expressions/interval.rb +34 -0
  81. data/lib/expressir/model/expressions/query_expression.rb +35 -0
  82. data/lib/expressir/model/expressions/unary_expression.rb +27 -0
  83. data/lib/expressir/model/identifier.rb +34 -0
  84. data/lib/expressir/model/literal.rb +9 -0
  85. data/lib/expressir/model/literals/binary.rb +19 -0
  86. data/lib/expressir/model/literals/integer.rb +19 -0
  87. data/lib/expressir/model/literals/logical.rb +23 -0
  88. data/lib/expressir/model/literals/real.rb +19 -0
  89. data/lib/expressir/model/literals/string.rb +22 -0
  90. data/lib/expressir/model/model_element.rb +208 -0
  91. data/lib/expressir/model/reference.rb +9 -0
  92. data/lib/expressir/model/references/attribute_reference.rb +22 -0
  93. data/lib/expressir/model/references/group_reference.rb +22 -0
  94. data/lib/expressir/model/references/index_reference.rb +27 -0
  95. data/lib/expressir/model/references/simple_reference.rb +24 -0
  96. data/lib/expressir/model/repository.rb +23 -0
  97. data/lib/expressir/model/statement.rb +9 -0
  98. data/lib/expressir/model/statements/alias.rb +35 -0
  99. data/lib/expressir/model/statements/assignment.rb +22 -0
  100. data/lib/expressir/model/statements/case.rb +25 -0
  101. data/lib/expressir/model/statements/case_action.rb +22 -0
  102. data/lib/expressir/model/statements/compound.rb +19 -0
  103. data/lib/expressir/model/statements/escape.rb +10 -0
  104. data/lib/expressir/model/statements/if.rb +25 -0
  105. data/lib/expressir/model/statements/null.rb +10 -0
  106. data/lib/expressir/model/statements/procedure_call.rb +22 -0
  107. data/lib/expressir/model/statements/repeat.rb +47 -0
  108. data/lib/expressir/model/statements/return.rb +19 -0
  109. data/lib/expressir/model/statements/skip.rb +10 -0
  110. data/lib/expressir/model/supertype_expression.rb +9 -0
  111. data/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +29 -0
  112. data/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +19 -0
  113. data/lib/expressir/model.rb +79 -0
  114. data/lib/expressir/version.rb +3 -0
  115. data/lib/expressir.rb +20 -0
  116. data/rakelib/antlr4-native.rake +63 -0
  117. data/rakelib/cross-ruby.rake +367 -0
  118. data/spec/acceptance/version_spec.rb +17 -0
  119. data/spec/expressir/express/cache_spec.rb +67 -0
  120. data/spec/expressir/express/formatter_spec.rb +135 -0
  121. data/spec/expressir/express/parser_spec.rb +104 -0
  122. data/spec/expressir/model/model_element_spec.rb +274 -0
  123. data/spec/spec_helper.rb +17 -0
  124. data/spec/support/console_helper.rb +29 -0
  125. data/spec/syntax/multiple.exp +23 -0
  126. data/spec/syntax/multiple.yaml +198 -0
  127. data/spec/syntax/multiple_formatted.exp +71 -0
  128. data/spec/syntax/multiple_hyperlink_formatted.exp +71 -0
  129. data/spec/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  130. data/spec/syntax/remark.exp +191 -0
  131. data/spec/syntax/remark.yaml +466 -0
  132. data/spec/syntax/remark_formatted.exp +227 -0
  133. data/spec/syntax/single.exp +4 -0
  134. data/spec/syntax/single.yaml +18 -0
  135. data/spec/syntax/single_formatted.exp +10 -0
  136. data/spec/syntax/single_formatted.yaml +36 -0
  137. data/spec/syntax/syntax.exp +333 -0
  138. data/spec/syntax/syntax.yaml +3509 -0
  139. data/spec/syntax/syntax_formatted.exp +902 -0
  140. data/spec/syntax/syntax_hyperlink_formatted.exp +902 -0
  141. data/spec/syntax/syntax_schema_head_formatted.exp +18 -0
  142. metadata +387 -0
@@ -0,0 +1,53 @@
1
+ module Expressir
2
+ module Model
3
+ module Expressions
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.1 Arithmetic operators
6
+ # - section 12.2 Relational operators
7
+ # - section 12.3 Binary operators
8
+ # - section 12.4 Logical operators
9
+ # - section 12.5 String operators
10
+ # - section 12.6 Aggregate operators
11
+ # - section 12.10 Complex entity instance construction operator
12
+ class BinaryExpression < Expression
13
+ ADDITION = :ADDITION
14
+ AND = :AND
15
+ COMBINE = :COMBINE
16
+ EQUAL = :EQUAL
17
+ EXPONENTIATION = :EXPONENTIATION
18
+ GREATER_THAN = :GREATER_THAN
19
+ GREATER_THAN_OR_EQUAL = :GREATER_THAN_OR_EQUAL
20
+ IN = :IN
21
+ INSTANCE_EQUAL = :INSTANCE_EQUAL
22
+ INSTANCE_NOT_EQUAL = :INSTANCE_NOT_EQUAL
23
+ INTEGER_DIVISION = :INTEGER_DIVISION
24
+ LESS_THAN = :LESS_THAN
25
+ LESS_THAN_OR_EQUAL = :LESS_THAN_OR_EQUAL
26
+ LIKE = :LIKE
27
+ MODULO = :MODULO
28
+ MULTIPLICATION = :MULTIPLICATION
29
+ NOT_EQUAL = :NOT_EQUAL
30
+ OR = :OR
31
+ REAL_DIVISION = :REAL_DIVISION
32
+ SUBTRACTION = :SUBTRACTION
33
+ XOR = :XOR
34
+
35
+ model_attr_accessor :operator, ':ADDITION, :AND, :COMBINE, :EQUAL, :EXPONENTIATION, :GREATER_THAN, :GREATER_THAN_OR_EQUAL, :IN, :INSTANCE_EQUAL, :INSTANCE_NOT_EQUAL, :INTEGER_DIVISION, :LESS_THAN, :LESS_THAN_OR_EQUAL, :LIKE, :MODULO, :MULTIPLICATION, :NOT_EQUAL, :OR, :REAL_DIVISION, :SUBTRACTION, :XOR'
36
+ model_attr_accessor :operand1, 'Expression'
37
+ model_attr_accessor :operand2, 'Expression'
38
+
39
+ # @param [Hash] options
40
+ # @option options [:ADDITION, :AND, :COMBINE, :EQUAL, :EXPONENTIATION, :GREATER_THAN, :GREATER_THAN_OR_EQUAL, :IN, :INSTANCE_EQUAL, :INSTANCE_NOT_EQUAL, :INTEGER_DIVISION, :LESS_THAN, :LESS_THAN_OR_EQUAL, :LIKE, :MODULO, :MULTIPLICATION, :NOT_EQUAL, :OR, :REAL_DIVISION, :SUBTRACTION, :XOR] :operator
41
+ # @option options [Expression] :operand1
42
+ # @option options [Expression] :operand2
43
+ def initialize(options = {})
44
+ @operator = options[:operator]
45
+ @operand1 = options[:operand1]
46
+ @operand2 = options[:operand2]
47
+
48
+ super
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ module Expressir
2
+ module Model
3
+ module Expressions
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 9.2.6 Implicit declarations
6
+ class EntityConstructor < Expression
7
+ model_attr_accessor :entity, 'Reference'
8
+ model_attr_accessor :parameters, 'Array<Expression>'
9
+
10
+ # @param [Hash] options
11
+ # @option options [Reference] :entity
12
+ # @option options [Array<Expression>] :parameters
13
+ def initialize(options = {})
14
+ @entity = options[:entity]
15
+ @parameters = options[:parameters] || []
16
+
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Expressir
2
+ module Model
3
+ module Expressions
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.8 Function call
6
+ class FunctionCall < Expression
7
+ model_attr_accessor :function, 'Reference'
8
+ model_attr_accessor :parameters, 'Array<Expression>'
9
+
10
+ # @param [Hash] options
11
+ # @option options [Reference] :function
12
+ # @option options [Array<Expression>] :parameters
13
+ def initialize(options = {})
14
+ @function = options[:function]
15
+ @parameters = options[:parameters] || []
16
+
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ module Expressir
2
+ module Model
3
+ module Expressions
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.2.4 Interval expressions
6
+ class Interval < Expression
7
+ LESS_THAN = :LESS_THAN
8
+ LESS_THAN_OR_EQUAL = :LESS_THAN_OR_EQUAL
9
+
10
+ model_attr_accessor :low, 'Expression'
11
+ model_attr_accessor :operator1, ':LESS_THAN, :LESS_THAN_OR_EQUAL'
12
+ model_attr_accessor :item, 'Reference'
13
+ model_attr_accessor :operator2, ':LESS_THAN, :LESS_THAN_OR_EQUAL'
14
+ model_attr_accessor :high, 'Expression'
15
+
16
+ # @param [Hash] options
17
+ # @option options [Expression] :low
18
+ # @option options [:LESS_THAN, :LESS_THAN_OR_EQUAL] :operator1
19
+ # @option options [Reference] :item
20
+ # @option options [:LESS_THAN, :LESS_THAN_OR_EQUAL] :operator2
21
+ # @option options [Expression] :high
22
+ def initialize(options = {})
23
+ @low = options[:low]
24
+ @operator1 = options[:operator1]
25
+ @item = options[:item]
26
+ @operator2 = options[:operator2]
27
+ @high = options[:high]
28
+
29
+ super
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ module Expressir
2
+ module Model
3
+ module Expressions
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.6.7 Query expression
6
+ class QueryExpression < Expression
7
+ include Identifier
8
+
9
+ model_attr_accessor :aggregate_source, 'Reference'
10
+ model_attr_accessor :expression, 'Expression'
11
+
12
+ # @param [Hash] options
13
+ # @option (see Identifier#initialize_identifier)
14
+ # @option options [Reference] :aggregace_source
15
+ # @option options [Expression] :expression
16
+ def initialize(options = {})
17
+ initialize_identifier(options)
18
+
19
+ @aggregate_source = options[:aggregate_source]
20
+ @expression = options[:expression]
21
+
22
+ super
23
+ end
24
+
25
+ # @return [Array<Declaration>]
26
+ def children
27
+ [
28
+ self,
29
+ *remark_items
30
+ ]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ module Expressir
2
+ module Model
3
+ module Expressions
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.1 Arithmetic operators
6
+ # - section 12.4.1 NOT operator
7
+ class UnaryExpression < Expression
8
+ MINUS = :MINUS
9
+ NOT = :NOT
10
+ PLUS = :PLUS
11
+
12
+ model_attr_accessor :operator, ':MINUS, :NOT, :PLUS'
13
+ model_attr_accessor :operand, 'Expression'
14
+
15
+ # @param [Hash] options
16
+ # @option options [:MINUS, :NOT, :PLUS] :operator
17
+ # @option options [Expression] :operand
18
+ def initialize(options = {})
19
+ @operator = options[:operator]
20
+ @operand = options[:operand]
21
+
22
+ super
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ module Expressir
2
+ module Model
3
+ module Identifier
4
+ # @!attribute id
5
+ # @return [::String]
6
+ # @!attribute remarks
7
+ # @return [::Array<::String>]
8
+ # @!attribute remark_items
9
+ # @return [::Array<RemarkItem>]
10
+ # @!attribute source
11
+ # @return [::String]
12
+ # @!visibility private
13
+ def self.included(mod)
14
+ mod.model_attr_accessor :id, '::String'
15
+ mod.model_attr_accessor :remarks, '::Array<::String>'
16
+ mod.model_attr_accessor :remark_items, '::Array<RemarkItem>'
17
+ mod.model_attr_accessor :source, '::String'
18
+ end
19
+
20
+ # @param [Hash] options
21
+ # @option options [::String] :id
22
+ # @option options [::Array<::String>] :remarks
23
+ # @option options [::Array<RemarkItem>] :remark_items
24
+ # @option options [::String] :source
25
+ # @!visibility private
26
+ def initialize_identifier(options = {})
27
+ @id = options[:id]
28
+ @remarks = options[:remarks] || []
29
+ @remark_items = options[:remark_items] || []
30
+ @source = options[:source]
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ module Expressir
2
+ module Model
3
+ # Specified in ISO 10303-11:2004
4
+ # - section 7.5 Literals
5
+ # @abstract
6
+ class Literal < ModelElement
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Expressir
2
+ module Model
3
+ module Literals
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 7.5.1 Binary literal
6
+ class Binary < Literal
7
+ model_attr_accessor :value, '::String'
8
+
9
+ # @param [Hash] options
10
+ # @option options [::String] :value
11
+ def initialize(options = {})
12
+ @value = options[:value]
13
+
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Expressir
2
+ module Model
3
+ module Literals
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 7.5.2 Integer literal
6
+ class Integer < Literal
7
+ model_attr_accessor :value, '::String'
8
+
9
+ # @param [Hash] options
10
+ # @option options [::String] :value
11
+ def initialize(options = {})
12
+ @value = options[:value]
13
+
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Expressir
2
+ module Model
3
+ module Literals
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 7.5.5 Logical literal
6
+ class Logical < Literal
7
+ TRUE = :TRUE
8
+ FALSE = :FALSE
9
+ UNKNOWN = :UNKNOWN
10
+
11
+ model_attr_accessor :value, ':TRUE, :FALSE, :UNKNOWN'
12
+
13
+ # @param [Hash] options
14
+ # @option options [:TRUE, :FALSE, :UNKNOWN] :value
15
+ def initialize(options = {})
16
+ @value = options[:value]
17
+
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ module Expressir
2
+ module Model
3
+ module Literals
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 7.5.3 Real literal
6
+ class Real < Literal
7
+ model_attr_accessor :value, '::String'
8
+
9
+ # @param [Hash] options
10
+ # @option options [::String] :value
11
+ def initialize(options = {})
12
+ @value = options[:value]
13
+
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Expressir
2
+ module Model
3
+ module Literals
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 7.5.4 String literal
6
+ class String < Literal
7
+ model_attr_accessor :value, '::String'
8
+ model_attr_accessor :encoded, '::Boolean'
9
+
10
+ # @param [Hash] options
11
+ # @option options [::String] :value
12
+ # @option options [::Boolean] :encoded
13
+ def initialize(options = {})
14
+ @value = options[:value]
15
+ @encoded = options[:encoded]
16
+
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,208 @@
1
+ require 'pathname'
2
+
3
+ module Expressir
4
+ module Model
5
+ # Base model element
6
+ class ModelElement
7
+ CLASS_KEY = '_class'
8
+ FILE_KEY = 'file'
9
+ SOURCE_KEY = 'source'
10
+
11
+ private_constant :CLASS_KEY
12
+ private_constant :FILE_KEY
13
+ private_constant :SOURCE_KEY
14
+
15
+ # @return [ModelElement]
16
+ attr_accessor :parent
17
+
18
+ # @param [Hash] options
19
+ def initialize(options = {})
20
+ attach_parent_to_children
21
+ end
22
+
23
+ # @return [String]
24
+ def path
25
+ # this creates an implicit scope
26
+ return if is_a? Statements::Alias or is_a? Statements::Repeat or is_a? Expressions::QueryExpression
27
+
28
+ current_node = self
29
+ path_parts = []
30
+ loop do
31
+ if current_node.class.method_defined? :id and !(current_node.is_a? References::SimpleReference)
32
+ path_parts << current_node.id
33
+ end
34
+
35
+ current_node = current_node.parent
36
+ break unless current_node
37
+ end
38
+
39
+ return if path_parts.empty?
40
+
41
+ path_parts.reverse.join(".")
42
+ end
43
+
44
+ # @param [String] path
45
+ # @return [ModelElement]
46
+ def find(path)
47
+ return self if path.empty?
48
+
49
+ path_parts = path.downcase.split(/\./).map do |current_path|
50
+ _, _, current_path = current_path.rpartition(":") # ignore prefix
51
+ current_path
52
+ end
53
+
54
+ current_scope = self
55
+ target_node = nil
56
+ loop do
57
+ # find in current scope
58
+ current_node = current_scope
59
+ path_parts.each do |current_path|
60
+ current_node = current_node.children_by_id[current_path]
61
+ break unless current_node
62
+ end
63
+ target_node = current_node
64
+ break if target_node
65
+
66
+ # retry search in parent scope
67
+ current_scope = current_scope.parent
68
+ break unless current_scope
69
+ end
70
+
71
+ if target_node.is_a? Model::Declarations::InterfacedItem
72
+ target_node = target_node.base_item
73
+ end
74
+
75
+ target_node
76
+ end
77
+
78
+ # @return [Array<Declaration>]
79
+ def children
80
+ []
81
+ end
82
+
83
+ # @return [Hash<String, Declaration>]
84
+ def children_by_id
85
+ @children_by_id ||= children.select{|x| x.id}.map{|x| [x.id.downcase, x]}.to_h
86
+ end
87
+
88
+ # @return [nil]
89
+ def reset_children_by_id
90
+ @children_by_id = nil
91
+ nil
92
+ end
93
+
94
+ # @param [String] root_path
95
+ # @param [Express::Formatter] formatter
96
+ # @param [Boolean] include_empty
97
+ # @return [Hash]
98
+ def to_hash(root_path: nil, formatter: nil, include_empty: nil)
99
+ hash = {}
100
+ hash[CLASS_KEY] = self.class.name
101
+
102
+ self.class.model_attrs.each do |variable|
103
+ value = self.send(variable)
104
+ empty = value.nil? || (value.is_a?(Array) && value.count == 0)
105
+
106
+ # skip empty values
107
+ if !empty or include_empty
108
+ hash[variable.to_s] = if value.is_a? Array
109
+ value.map do |value|
110
+ if value.is_a? ModelElement
111
+ value.to_hash(root_path: root_path, formatter: formatter, include_empty: include_empty)
112
+ else
113
+ value
114
+ end
115
+ end
116
+ elsif value.is_a? ModelElement
117
+ value.to_hash(root_path: root_path, formatter: formatter, include_empty: include_empty)
118
+ else
119
+ value
120
+ end
121
+ end
122
+ end
123
+
124
+ if self.is_a? Declarations::Schema and file
125
+ hash[FILE_KEY] = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : file
126
+ end
127
+
128
+ if self.class.method_defined? :source and formatter
129
+ hash[SOURCE_KEY] = formatter.format(self)
130
+ end
131
+
132
+ hash
133
+ end
134
+
135
+ # @param [Hash] hash
136
+ # @param [String] root_path
137
+ # @return [ModelElement]
138
+ def self.from_hash(hash, root_path: nil)
139
+ node_class = Object.const_get(hash[CLASS_KEY])
140
+ node_options = {}
141
+
142
+ node_class.model_attrs.each do |variable|
143
+ value = hash[variable.to_s]
144
+
145
+ node_options[variable] = if value.is_a? Array
146
+ value.map do |value|
147
+ if value.is_a? Hash
148
+ self.from_hash(value, root_path: root_path)
149
+ else
150
+ value
151
+ end
152
+ end
153
+ elsif value.is_a? Hash
154
+ self.from_hash(value, root_path: root_path)
155
+ else
156
+ value
157
+ end
158
+ end
159
+
160
+ if node_class == Declarations::Schema and hash[FILE_KEY]
161
+ node_options[FILE_KEY.to_sym] = root_path ? File.expand_path("#{root_path}/#{hash[FILE_KEY]}") : hash[FILE_KEY]
162
+ end
163
+
164
+ node = node_class.new(node_options)
165
+
166
+ node
167
+ end
168
+
169
+ # @return [Array<Symbol>]
170
+ def self.model_attrs
171
+ @model_attrs ||= []
172
+ end
173
+
174
+ # Define a new model attribute
175
+ # @param attr_name [Symbol] attribute name
176
+ # @param attr_type [Symbol] attribute type
177
+ # @!macro [attach] model_attr_accessor
178
+ # @!attribute $1
179
+ # @return [$2]
180
+ def self.model_attr_accessor(attr_name, attr_type = nil)
181
+ @model_attrs ||= []
182
+ @model_attrs << attr_name
183
+
184
+ attr_accessor attr_name
185
+ end
186
+
187
+ private
188
+
189
+ # @return [nil]
190
+ def attach_parent_to_children
191
+ self.class.model_attrs.each do |variable|
192
+ value = self.send(variable)
193
+
194
+ if value.is_a? Array
195
+ value.each do |value|
196
+ if value.is_a? ModelElement
197
+ value.parent = self
198
+ end
199
+ end
200
+ elsif value.is_a? ModelElement
201
+ value.parent = self
202
+ end
203
+ end
204
+ nil
205
+ end
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,9 @@
1
+ module Expressir
2
+ module Model
3
+ # Specified in ISO 10303-11:2004
4
+ # - section 12.7 References
5
+ # @abstract
6
+ class Reference < ModelElement
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module Expressir
2
+ module Model
3
+ module References
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.7.3 Attribute references
6
+ class AttributeReference < Reference
7
+ model_attr_accessor :ref, 'Reference'
8
+ model_attr_accessor :attribute, 'Reference'
9
+
10
+ # @param [Hash] options
11
+ # @option options [Reference] :ref
12
+ # @option options [Reference] :attribute
13
+ def initialize(options = {})
14
+ @ref = options[:ref]
15
+ @attribute = options[:attribute]
16
+
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Expressir
2
+ module Model
3
+ module References
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.7.4 Group references
6
+ class GroupReference < Reference
7
+ model_attr_accessor :ref, 'Reference'
8
+ model_attr_accessor :entity, 'Reference'
9
+
10
+ # @param [Hash] options
11
+ # @option options [Reference] :ref
12
+ # @option options [Reference] :entity
13
+ def initialize(options = {})
14
+ @ref = options[:ref]
15
+ @entity = options[:entity]
16
+
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module Expressir
2
+ module Model
3
+ module References
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.3.1 Binary indexing
6
+ # - section 12.5.1 String indexing
7
+ # - section 12.6.1 Aggregate indexing
8
+ class IndexReference < Reference
9
+ model_attr_accessor :ref, 'Reference'
10
+ model_attr_accessor :index1, 'Expression'
11
+ model_attr_accessor :index2, 'Expression'
12
+
13
+ # @param [Hash] options
14
+ # @option options [Reference] :ref
15
+ # @option options [Expression] :index1
16
+ # @option options [Expression] :index2
17
+ def initialize(options = {})
18
+ @ref = options[:ref]
19
+ @index1 = options[:index1]
20
+ @index2 = options[:index2]
21
+
22
+ super
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ module Expressir
2
+ module Model
3
+ module References
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.7.1 Simple references
6
+ class SimpleReference < Reference
7
+ model_attr_accessor :id, 'String'
8
+
9
+ model_attr_accessor :base_path, 'String'
10
+
11
+ # @param [Hash] options
12
+ # @option options [String] :id
13
+ # @option options [String] :base_path
14
+ def initialize(options = {})
15
+ @id = options[:id]
16
+
17
+ @base_path = options[:base_path]
18
+
19
+ super
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module Expressir
2
+ module Model
3
+ # Multi-schema global scope
4
+ class Repository < ModelElement
5
+ model_attr_accessor :schemas, 'Array<Declarations::Schema>'
6
+
7
+ # @param [Hash] options
8
+ # @option options [Array<Declarations::Schema>] :schemas
9
+ def initialize(options = {})
10
+ @schemas = options[:schemas] || []
11
+
12
+ super
13
+ end
14
+
15
+ # @return [Array<Declaration>]
16
+ def children
17
+ [
18
+ *schemas
19
+ ]
20
+ end
21
+ end
22
+ end
23
+ end