expressir 1.0.0-arm64-darwin → 1.2.1-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.cross_rubies +6 -18
  3. data/.github/workflows/rake.yml +50 -5
  4. data/.github/workflows/release.yml +11 -3
  5. data/.hound.yml +3 -0
  6. data/.rubocop.yml +6 -506
  7. data/.yardopts +11 -0
  8. data/Rakefile +3 -0
  9. data/expressir.gemspec +4 -1
  10. data/lib/expressir/express/2.7/express_parser.bundle +0 -0
  11. data/lib/expressir/express/3.0/express_parser.bundle +0 -0
  12. data/lib/expressir/express/3.1/express_parser.bundle +0 -0
  13. data/lib/expressir/express/cache.rb +16 -10
  14. data/lib/expressir/express/formatter.rb +231 -180
  15. data/lib/expressir/express/hyperlink_formatter.rb +15 -1
  16. data/lib/expressir/express/model_visitor.rb +1 -0
  17. data/lib/expressir/express/parser.rb +16 -10
  18. data/lib/expressir/express/resolve_references_model_visitor.rb +7 -5
  19. data/lib/expressir/express/schema_head_formatter.rb +16 -2
  20. data/lib/expressir/express/visitor.rb +280 -254
  21. data/lib/expressir/model/cache.rb +6 -2
  22. data/lib/expressir/model/data_type.rb +9 -0
  23. data/lib/expressir/model/data_types/aggregate.rb +31 -0
  24. data/lib/expressir/model/data_types/array.rb +31 -0
  25. data/lib/expressir/model/data_types/bag.rb +25 -0
  26. data/lib/expressir/model/data_types/binary.rb +22 -0
  27. data/lib/expressir/model/data_types/boolean.rb +10 -0
  28. data/lib/expressir/model/data_types/enumeration.rb +25 -0
  29. data/lib/expressir/model/data_types/enumeration_item.rb +26 -0
  30. data/lib/expressir/model/data_types/generic.rb +26 -0
  31. data/lib/expressir/model/data_types/generic_entity.rb +26 -0
  32. data/lib/expressir/model/data_types/integer.rb +10 -0
  33. data/lib/expressir/model/data_types/list.rb +28 -0
  34. data/lib/expressir/model/data_types/logical.rb +10 -0
  35. data/lib/expressir/model/data_types/number.rb +10 -0
  36. data/lib/expressir/model/data_types/real.rb +19 -0
  37. data/lib/expressir/model/data_types/select.rb +28 -0
  38. data/lib/expressir/model/data_types/set.rb +25 -0
  39. data/lib/expressir/model/data_types/string.rb +22 -0
  40. data/lib/expressir/model/declaration.rb +9 -0
  41. data/lib/expressir/model/declarations/attribute.rb +47 -0
  42. data/lib/expressir/model/declarations/constant.rb +34 -0
  43. data/lib/expressir/model/declarations/entity.rb +53 -0
  44. data/lib/expressir/model/declarations/function.rb +67 -0
  45. data/lib/expressir/model/declarations/interface.rb +28 -0
  46. data/lib/expressir/model/declarations/interface_item.rb +23 -0
  47. data/lib/expressir/model/declarations/interfaced_item.rb +37 -0
  48. data/lib/expressir/model/declarations/parameter.rb +34 -0
  49. data/lib/expressir/model/declarations/procedure.rb +64 -0
  50. data/lib/expressir/model/declarations/remark_item.rb +21 -0
  51. data/lib/expressir/model/declarations/rule.rb +71 -0
  52. data/lib/expressir/model/declarations/schema.rb +117 -0
  53. data/lib/expressir/model/declarations/schema_version.rb +22 -0
  54. data/lib/expressir/model/declarations/schema_version_item.rb +22 -0
  55. data/lib/expressir/model/declarations/subtype_constraint.rb +40 -0
  56. data/lib/expressir/model/declarations/type.rb +45 -0
  57. data/lib/expressir/model/declarations/unique_rule.rb +31 -0
  58. data/lib/expressir/model/declarations/variable.rb +34 -0
  59. data/lib/expressir/model/declarations/where_rule.rb +31 -0
  60. data/lib/expressir/model/expression.rb +9 -0
  61. data/lib/expressir/model/expressions/aggregate_initializer.rb +6 -2
  62. data/lib/expressir/model/expressions/aggregate_initializer_item.rb +22 -0
  63. data/lib/expressir/model/expressions/binary_expression.rb +16 -5
  64. data/lib/expressir/model/expressions/entity_constructor.rb +8 -3
  65. data/lib/expressir/model/expressions/function_call.rb +22 -0
  66. data/lib/expressir/model/expressions/interval.rb +17 -6
  67. data/lib/expressir/model/expressions/query_expression.rb +11 -7
  68. data/lib/expressir/model/expressions/unary_expression.rb +9 -3
  69. data/lib/expressir/model/identifier.rb +26 -4
  70. data/lib/expressir/model/literal.rb +9 -0
  71. data/lib/expressir/model/literals/binary.rb +6 -2
  72. data/lib/expressir/model/literals/integer.rb +6 -2
  73. data/lib/expressir/model/literals/logical.rb +6 -2
  74. data/lib/expressir/model/literals/real.rb +6 -2
  75. data/lib/expressir/model/literals/string.rb +8 -3
  76. data/lib/expressir/model/model_element.rb +63 -37
  77. data/lib/expressir/model/reference.rb +9 -0
  78. data/lib/expressir/model/references/attribute_reference.rb +22 -0
  79. data/lib/expressir/model/references/group_reference.rb +22 -0
  80. data/lib/expressir/model/references/index_reference.rb +27 -0
  81. data/lib/expressir/model/references/simple_reference.rb +24 -0
  82. data/lib/expressir/model/repository.rb +5 -1
  83. data/lib/expressir/model/statement.rb +9 -0
  84. data/lib/expressir/model/statements/alias.rb +11 -7
  85. data/lib/expressir/model/statements/assignment.rb +8 -3
  86. data/lib/expressir/model/statements/case.rb +10 -4
  87. data/lib/expressir/model/statements/case_action.rb +7 -2
  88. data/lib/expressir/model/statements/compound.rb +6 -2
  89. data/lib/expressir/model/statements/escape.rb +3 -1
  90. data/lib/expressir/model/statements/if.rb +10 -4
  91. data/lib/expressir/model/statements/null.rb +3 -1
  92. data/lib/expressir/model/statements/procedure_call.rb +22 -0
  93. data/lib/expressir/model/statements/repeat.rb +19 -11
  94. data/lib/expressir/model/statements/return.rb +6 -2
  95. data/lib/expressir/model/statements/skip.rb +3 -1
  96. data/lib/expressir/model/supertype_expression.rb +9 -0
  97. data/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +29 -0
  98. data/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +19 -0
  99. data/lib/expressir/model.rb +52 -45
  100. data/lib/expressir/version.rb +1 -1
  101. data/spec/expressir/model/model_element_spec.rb +131 -131
  102. data/spec/syntax/multiple.yaml +68 -68
  103. data/spec/syntax/remark.yaml +64 -64
  104. data/spec/syntax/single.yaml +5 -5
  105. data/spec/syntax/single_formatted.yaml +5 -5
  106. data/spec/syntax/syntax.yaml +1003 -1030
  107. metadata +105 -54
  108. data/lib/expressir/express/2.4/express_parser.bundle +0 -0
  109. data/lib/expressir/express/2.5/express_parser.bundle +0 -0
  110. data/lib/expressir/express/2.6/express_parser.bundle +0 -0
  111. data/lib/expressir/model/attribute.rb +0 -38
  112. data/lib/expressir/model/constant.rb +0 -28
  113. data/lib/expressir/model/entity.rb +0 -42
  114. data/lib/expressir/model/enumeration_item.rb +0 -22
  115. data/lib/expressir/model/expressions/aggregate_item.rb +0 -17
  116. data/lib/expressir/model/expressions/attribute_reference.rb +0 -17
  117. data/lib/expressir/model/expressions/call.rb +0 -17
  118. data/lib/expressir/model/expressions/group_reference.rb +0 -17
  119. data/lib/expressir/model/expressions/index_reference.rb +0 -19
  120. data/lib/expressir/model/expressions/simple_reference.rb +0 -19
  121. data/lib/expressir/model/function.rb +0 -57
  122. data/lib/expressir/model/interface.rb +0 -20
  123. data/lib/expressir/model/interface_item.rb +0 -15
  124. data/lib/expressir/model/interfaced_item.rb +0 -27
  125. data/lib/expressir/model/parameter.rb +0 -28
  126. data/lib/expressir/model/procedure.rb +0 -55
  127. data/lib/expressir/model/remark_item.rb +0 -15
  128. data/lib/expressir/model/rule.rb +0 -60
  129. data/lib/expressir/model/schema.rb +0 -100
  130. data/lib/expressir/model/schema_version.rb +0 -15
  131. data/lib/expressir/model/schema_version_item.rb +0 -15
  132. data/lib/expressir/model/statements/call.rb +0 -17
  133. data/lib/expressir/model/subtype_constraint.rb +0 -32
  134. data/lib/expressir/model/type.rb +0 -37
  135. data/lib/expressir/model/types/aggregate.rb +0 -28
  136. data/lib/expressir/model/types/array.rb +0 -23
  137. data/lib/expressir/model/types/bag.rb +0 -19
  138. data/lib/expressir/model/types/binary.rb +0 -17
  139. data/lib/expressir/model/types/boolean.rb +0 -8
  140. data/lib/expressir/model/types/enumeration.rb +0 -19
  141. data/lib/expressir/model/types/generic.rb +0 -24
  142. data/lib/expressir/model/types/generic_entity.rb +0 -24
  143. data/lib/expressir/model/types/integer.rb +0 -8
  144. data/lib/expressir/model/types/list.rb +0 -21
  145. data/lib/expressir/model/types/logical.rb +0 -8
  146. data/lib/expressir/model/types/number.rb +0 -8
  147. data/lib/expressir/model/types/real.rb +0 -15
  148. data/lib/expressir/model/types/select.rb +0 -21
  149. data/lib/expressir/model/types/set.rb +0 -19
  150. data/lib/expressir/model/types/string.rb +0 -17
  151. data/lib/expressir/model/unique_rule.rb +0 -26
  152. data/lib/expressir/model/variable.rb +0 -28
  153. data/lib/expressir/model/where_rule.rb +0 -26
@@ -1,10 +1,17 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Expressions
4
- class BinaryExpression < ModelElement
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
5
13
  ADDITION = :ADDITION
6
14
  AND = :AND
7
- ANDOR = :ANDOR
8
15
  COMBINE = :COMBINE
9
16
  EQUAL = :EQUAL
10
17
  EXPONENTIATION = :EXPONENTIATION
@@ -25,10 +32,14 @@ module Expressir
25
32
  SUBTRACTION = :SUBTRACTION
26
33
  XOR = :XOR
27
34
 
28
- model_attr_accessor :operator
29
- model_attr_accessor :operand1
30
- model_attr_accessor :operand2
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'
31
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
32
43
  def initialize(options = {})
33
44
  @operator = options[:operator]
34
45
  @operand1 = options[:operand1]
@@ -1,10 +1,15 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Expressions
4
- class EntityConstructor < ModelElement
5
- model_attr_accessor :entity
6
- model_attr_accessor :parameters
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>'
7
9
 
10
+ # @param [Hash] options
11
+ # @option options [Reference] :entity
12
+ # @option options [Array<Expression>] :parameters
8
13
  def initialize(options = {})
9
14
  @entity = options[:entity]
10
15
  @parameters = options[:parameters] || []
@@ -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
@@ -1,13 +1,24 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Expressions
4
- class Interval < ModelElement
5
- model_attr_accessor :low
6
- model_attr_accessor :operator1
7
- model_attr_accessor :item
8
- model_attr_accessor :operator2
9
- model_attr_accessor :high
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
10
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
11
22
  def initialize(options = {})
12
23
  @low = options[:low]
13
24
  @operator1 = options[:operator1]
@@ -1,17 +1,20 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Expressions
4
- class QueryExpression < ModelElement
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.6.7 Query expression
6
+ class QueryExpression < Expression
5
7
  include Identifier
6
8
 
7
- model_attr_accessor :aggregate_source
8
- model_attr_accessor :expression
9
+ model_attr_accessor :aggregate_source, 'Reference'
10
+ model_attr_accessor :expression, 'Expression'
9
11
 
12
+ # @param [Hash] options
13
+ # @option (see Identifier#initialize_identifier)
14
+ # @option options [Reference] :aggregace_source
15
+ # @option options [Expression] :expression
10
16
  def initialize(options = {})
11
- @id = options[:id]
12
- @remarks = options[:remarks] || []
13
- @remark_items = options[:remark_items] || []
14
- @source = options[:source]
17
+ initialize_identifier(options)
15
18
 
16
19
  @aggregate_source = options[:aggregate_source]
17
20
  @expression = options[:expression]
@@ -19,6 +22,7 @@ module Expressir
19
22
  super
20
23
  end
21
24
 
25
+ # @return [Array<Declaration>]
22
26
  def children
23
27
  [
24
28
  self,
@@ -1,14 +1,20 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Expressions
4
- class UnaryExpression < ModelElement
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.1 Arithmetic operators
6
+ # - section 12.4.1 NOT operator
7
+ class UnaryExpression < Expression
5
8
  MINUS = :MINUS
6
9
  NOT = :NOT
7
10
  PLUS = :PLUS
8
11
 
9
- model_attr_accessor :operator
10
- model_attr_accessor :operand
12
+ model_attr_accessor :operator, ':MINUS, :NOT, :PLUS'
13
+ model_attr_accessor :operand, 'Expression'
11
14
 
15
+ # @param [Hash] options
16
+ # @option options [:MINUS, :NOT, :PLUS] :operator
17
+ # @option options [Expression] :operand
12
18
  def initialize(options = {})
13
19
  @operator = options[:operator]
14
20
  @operand = options[:operand]
@@ -1,11 +1,33 @@
1
1
  module Expressir
2
2
  module Model
3
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
4
13
  def self.included(mod)
5
- mod.model_attr_accessor :id
6
- mod.model_attr_accessor :remarks
7
- mod.model_attr_accessor :remark_items
8
- mod.model_attr_accessor :source
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]
9
31
  end
10
32
  end
11
33
  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
@@ -1,9 +1,13 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Literals
4
- class Binary < ModelElement
5
- model_attr_accessor :value
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 7.5.1 Binary literal
6
+ class Binary < Literal
7
+ model_attr_accessor :value, '::String'
6
8
 
9
+ # @param [Hash] options
10
+ # @option options [::String] :value
7
11
  def initialize(options = {})
8
12
  @value = options[:value]
9
13
 
@@ -1,9 +1,13 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Literals
4
- class Integer < ModelElement
5
- model_attr_accessor :value
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 7.5.2 Integer literal
6
+ class Integer < Literal
7
+ model_attr_accessor :value, '::String'
6
8
 
9
+ # @param [Hash] options
10
+ # @option options [::String] :value
7
11
  def initialize(options = {})
8
12
  @value = options[:value]
9
13
 
@@ -1,13 +1,17 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Literals
4
- class Logical < ModelElement
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 7.5.5 Logical literal
6
+ class Logical < Literal
5
7
  TRUE = :TRUE
6
8
  FALSE = :FALSE
7
9
  UNKNOWN = :UNKNOWN
8
10
 
9
- model_attr_accessor :value
11
+ model_attr_accessor :value, ':TRUE, :FALSE, :UNKNOWN'
10
12
 
13
+ # @param [Hash] options
14
+ # @option options [:TRUE, :FALSE, :UNKNOWN] :value
11
15
  def initialize(options = {})
12
16
  @value = options[:value]
13
17
 
@@ -1,9 +1,13 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Literals
4
- class Real < ModelElement
5
- model_attr_accessor :value
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 7.5.3 Real literal
6
+ class Real < Literal
7
+ model_attr_accessor :value, '::String'
6
8
 
9
+ # @param [Hash] options
10
+ # @option options [::String] :value
7
11
  def initialize(options = {})
8
12
  @value = options[:value]
9
13
 
@@ -1,10 +1,15 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Literals
4
- class String < ModelElement
5
- model_attr_accessor :value
6
- model_attr_accessor :encoded
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'
7
9
 
10
+ # @param [Hash] options
11
+ # @option options [::String] :value
12
+ # @option options [::Boolean] :encoded
8
13
  def initialize(options = {})
9
14
  @value = options[:value]
10
15
  @encoded = options[:encoded]
@@ -2,17 +2,25 @@ require 'pathname'
2
2
 
3
3
  module Expressir
4
4
  module Model
5
+ # Base model element
5
6
  class ModelElement
6
7
  CLASS_KEY = '_class'
7
8
  FILE_KEY = 'file'
8
9
  SOURCE_KEY = 'source'
9
10
 
11
+ private_constant :CLASS_KEY
12
+ private_constant :FILE_KEY
13
+ private_constant :SOURCE_KEY
14
+
15
+ # @return [ModelElement]
10
16
  attr_accessor :parent
11
17
 
18
+ # @param [Hash] options
12
19
  def initialize(options = {})
13
20
  attach_parent_to_children
14
21
  end
15
22
 
23
+ # @return [String]
16
24
  def path
17
25
  # this creates an implicit scope
18
26
  return if is_a? Statements::Alias or is_a? Statements::Repeat or is_a? Expressions::QueryExpression
@@ -20,7 +28,7 @@ module Expressir
20
28
  current_node = self
21
29
  path_parts = []
22
30
  loop do
23
- if current_node.class.method_defined? :id and !(current_node.is_a? Expressions::SimpleReference)
31
+ if current_node.class.method_defined? :id and !(current_node.is_a? References::SimpleReference)
24
32
  path_parts << current_node.id
25
33
  end
26
34
 
@@ -33,22 +41,8 @@ module Expressir
33
41
  path_parts.reverse.join(".")
34
42
  end
35
43
 
36
- def attach_parent_to_children
37
- self.class.model_attrs.each do |variable|
38
- value = self.send(variable)
39
-
40
- if value.is_a? Array
41
- value.each do |value|
42
- if value.is_a? ModelElement
43
- value.parent = self
44
- end
45
- end
46
- elsif value.is_a? ModelElement
47
- value.parent = self
48
- end
49
- end
50
- end
51
-
44
+ # @param [String] path
45
+ # @return [ModelElement]
52
46
  def find(path)
53
47
  return self if path.empty?
54
48
 
@@ -74,30 +68,34 @@ module Expressir
74
68
  break unless current_scope
75
69
  end
76
70
 
77
- if target_node.is_a? Model::InterfacedItem
71
+ if target_node.is_a? Model::Declarations::InterfacedItem
78
72
  target_node = target_node.base_item
79
73
  end
80
74
 
81
75
  target_node
82
76
  end
83
77
 
78
+ # @return [Array<Declaration>]
84
79
  def children
85
80
  []
86
81
  end
87
82
 
83
+ # @return [Hash<String, Declaration>]
88
84
  def children_by_id
89
85
  @children_by_id ||= children.select{|x| x.id}.map{|x| [x.id.downcase, x]}.to_h
90
86
  end
91
87
 
88
+ # @return [nil]
92
89
  def reset_children_by_id
93
90
  @children_by_id = nil
91
+ nil
94
92
  end
95
-
96
- def to_hash(options = {})
97
- root_path = options[:root_path]
98
- formatter = options[:formatter]
99
- include_empty = options[:include_empty]
100
-
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)
101
99
  hash = {}
102
100
  hash[CLASS_KEY] = self.class.name
103
101
 
@@ -110,20 +108,20 @@ module Expressir
110
108
  hash[variable.to_s] = if value.is_a? Array
111
109
  value.map do |value|
112
110
  if value.is_a? ModelElement
113
- value.to_hash(options)
111
+ value.to_hash(root_path: root_path, formatter: formatter, include_empty: include_empty)
114
112
  else
115
113
  value
116
114
  end
117
115
  end
118
116
  elsif value.is_a? ModelElement
119
- value.to_hash(options)
117
+ value.to_hash(root_path: root_path, formatter: formatter, include_empty: include_empty)
120
118
  else
121
119
  value
122
120
  end
123
121
  end
124
122
  end
125
123
 
126
- if self.is_a? Schema and file
124
+ if self.is_a? Declarations::Schema and file
127
125
  hash[FILE_KEY] = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : file
128
126
  end
129
127
 
@@ -133,10 +131,11 @@ module Expressir
133
131
 
134
132
  hash
135
133
  end
136
-
137
- def self.from_hash(hash, options = {})
138
- root_path = options[:root_path]
139
-
134
+
135
+ # @param [Hash] hash
136
+ # @param [String] root_path
137
+ # @return [ModelElement]
138
+ def self.from_hash(hash, root_path: nil)
140
139
  node_class = Object.const_get(hash[CLASS_KEY])
141
140
  node_options = {}
142
141
 
@@ -146,19 +145,19 @@ module Expressir
146
145
  node_options[variable] = if value.is_a? Array
147
146
  value.map do |value|
148
147
  if value.is_a? Hash
149
- self.from_hash(value, options)
148
+ self.from_hash(value, root_path: root_path)
150
149
  else
151
150
  value
152
151
  end
153
152
  end
154
153
  elsif value.is_a? Hash
155
- self.from_hash(value, options)
154
+ self.from_hash(value, root_path: root_path)
156
155
  else
157
156
  value
158
157
  end
159
158
  end
160
159
 
161
- if node_class == Schema and hash[FILE_KEY]
160
+ if node_class == Declarations::Schema and hash[FILE_KEY]
162
161
  node_options[FILE_KEY.to_sym] = root_path ? File.expand_path("#{root_path}/#{hash[FILE_KEY]}") : hash[FILE_KEY]
163
162
  end
164
163
 
@@ -167,15 +166,42 @@ module Expressir
167
166
  node
168
167
  end
169
168
 
169
+ # @return [Array<Symbol>]
170
170
  def self.model_attrs
171
171
  @model_attrs ||= []
172
172
  end
173
173
 
174
- def self.model_attr_accessor(*vars)
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)
175
181
  @model_attrs ||= []
176
- @model_attrs.concat(vars)
182
+ @model_attrs << attr_name
183
+
184
+ attr_accessor attr_name
185
+ end
186
+
187
+ private
177
188
 
178
- attr_accessor *vars
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
179
205
  end
180
206
  end
181
207
  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
@@ -1,14 +1,18 @@
1
1
  module Expressir
2
2
  module Model
3
+ # Multi-schema global scope
3
4
  class Repository < ModelElement
4
- model_attr_accessor :schemas
5
+ model_attr_accessor :schemas, 'Array<Declarations::Schema>'
5
6
 
7
+ # @param [Hash] options
8
+ # @option options [Array<Declarations::Schema>] :schemas
6
9
  def initialize(options = {})
7
10
  @schemas = options[:schemas] || []
8
11
 
9
12
  super
10
13
  end
11
14
 
15
+ # @return [Array<Declaration>]
12
16
  def children
13
17
  [
14
18
  *schemas
@@ -0,0 +1,9 @@
1
+ module Expressir
2
+ module Model
3
+ # Specified in ISO 10303-11:2004
4
+ # - section 13 Executable statements
5
+ # @abstract
6
+ class Statement < ModelElement
7
+ end
8
+ end
9
+ end