expressir 0.2.24-x64-mingw32 → 1.1.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +7 -6
  3. data/.gitignore +2 -2
  4. data/.yardopts +11 -0
  5. data/Rakefile +3 -0
  6. data/demo.rb +5 -5
  7. data/exe/format +10 -73
  8. data/exe/format-test +81 -0
  9. data/expressir.gemspec +3 -1
  10. data/lib/expressir.rb +0 -1
  11. data/lib/expressir/cli.rb +0 -6
  12. data/lib/expressir/{express_exp → express}/2.4/express_parser.so +0 -0
  13. data/lib/expressir/{express_exp → express}/2.5/express_parser.so +0 -0
  14. data/lib/expressir/{express_exp → express}/2.6/express_parser.so +0 -0
  15. data/lib/expressir/{express_exp → express}/2.7/express_parser.so +0 -0
  16. data/lib/expressir/{express_exp → express}/3.0/express_parser.so +0 -0
  17. data/lib/expressir/express/cache.rb +51 -0
  18. data/lib/expressir/{express_exp → express}/formatter.rb +306 -239
  19. data/lib/expressir/express/hyperlink_formatter.rb +36 -0
  20. data/lib/expressir/express/model_visitor.rb +24 -0
  21. data/lib/expressir/express/parser.rb +81 -0
  22. data/lib/expressir/express/resolve_references_model_visitor.rb +31 -0
  23. data/lib/expressir/express/schema_head_formatter.rb +23 -0
  24. data/lib/expressir/{express_exp → express}/visitor.rb +318 -270
  25. data/lib/expressir/model.rb +52 -43
  26. data/lib/expressir/model/cache.rb +6 -2
  27. data/lib/expressir/model/data_type.rb +9 -0
  28. data/lib/expressir/model/data_types/aggregate.rb +31 -0
  29. data/lib/expressir/model/data_types/array.rb +31 -0
  30. data/lib/expressir/model/data_types/bag.rb +25 -0
  31. data/lib/expressir/model/data_types/binary.rb +22 -0
  32. data/lib/expressir/model/data_types/boolean.rb +10 -0
  33. data/lib/expressir/model/data_types/enumeration.rb +25 -0
  34. data/lib/expressir/model/data_types/enumeration_item.rb +26 -0
  35. data/lib/expressir/model/data_types/generic.rb +26 -0
  36. data/lib/expressir/model/data_types/generic_entity.rb +26 -0
  37. data/lib/expressir/model/data_types/integer.rb +10 -0
  38. data/lib/expressir/model/data_types/list.rb +28 -0
  39. data/lib/expressir/model/data_types/logical.rb +10 -0
  40. data/lib/expressir/model/data_types/number.rb +10 -0
  41. data/lib/expressir/model/data_types/real.rb +19 -0
  42. data/lib/expressir/model/data_types/select.rb +28 -0
  43. data/lib/expressir/model/data_types/set.rb +25 -0
  44. data/lib/expressir/model/data_types/string.rb +22 -0
  45. data/lib/expressir/model/declaration.rb +9 -0
  46. data/lib/expressir/model/declarations/attribute.rb +47 -0
  47. data/lib/expressir/model/declarations/constant.rb +34 -0
  48. data/lib/expressir/model/declarations/entity.rb +53 -0
  49. data/lib/expressir/model/declarations/function.rb +67 -0
  50. data/lib/expressir/model/declarations/interface.rb +28 -0
  51. data/lib/expressir/model/declarations/interface_item.rb +23 -0
  52. data/lib/expressir/model/declarations/interfaced_item.rb +37 -0
  53. data/lib/expressir/model/declarations/parameter.rb +34 -0
  54. data/lib/expressir/model/declarations/procedure.rb +64 -0
  55. data/lib/expressir/model/declarations/remark_item.rb +21 -0
  56. data/lib/expressir/model/declarations/rule.rb +71 -0
  57. data/lib/expressir/model/declarations/schema.rb +117 -0
  58. data/lib/expressir/model/declarations/schema_version.rb +22 -0
  59. data/lib/expressir/model/declarations/schema_version_item.rb +22 -0
  60. data/lib/expressir/model/declarations/subtype_constraint.rb +40 -0
  61. data/lib/expressir/model/declarations/type.rb +45 -0
  62. data/lib/expressir/model/declarations/unique_rule.rb +31 -0
  63. data/lib/expressir/model/declarations/variable.rb +34 -0
  64. data/lib/expressir/model/declarations/where_rule.rb +31 -0
  65. data/lib/expressir/model/expression.rb +9 -0
  66. data/lib/expressir/model/expressions/aggregate_initializer.rb +7 -3
  67. data/lib/expressir/model/expressions/aggregate_initializer_item.rb +22 -0
  68. data/lib/expressir/model/expressions/binary_expression.rb +16 -5
  69. data/lib/expressir/model/expressions/entity_constructor.rb +9 -4
  70. data/lib/expressir/model/expressions/function_call.rb +22 -0
  71. data/lib/expressir/model/expressions/interval.rb +17 -6
  72. data/lib/expressir/model/expressions/query_expression.rb +11 -7
  73. data/lib/expressir/model/expressions/unary_expression.rb +9 -3
  74. data/lib/expressir/model/identifier.rb +26 -4
  75. data/lib/expressir/model/literal.rb +9 -0
  76. data/lib/expressir/model/literals/binary.rb +6 -2
  77. data/lib/expressir/model/literals/integer.rb +6 -2
  78. data/lib/expressir/model/literals/logical.rb +6 -2
  79. data/lib/expressir/model/literals/real.rb +6 -2
  80. data/lib/expressir/model/literals/string.rb +8 -3
  81. data/lib/expressir/model/model_element.rb +70 -37
  82. data/lib/expressir/model/reference.rb +9 -0
  83. data/lib/expressir/model/references/attribute_reference.rb +22 -0
  84. data/lib/expressir/model/references/group_reference.rb +22 -0
  85. data/lib/expressir/model/references/index_reference.rb +27 -0
  86. data/lib/expressir/model/references/simple_reference.rb +24 -0
  87. data/lib/expressir/model/repository.rb +8 -2
  88. data/lib/expressir/model/statement.rb +9 -0
  89. data/lib/expressir/model/statements/alias.rb +12 -8
  90. data/lib/expressir/model/statements/assignment.rb +8 -3
  91. data/lib/expressir/model/statements/case.rb +11 -5
  92. data/lib/expressir/model/statements/case_action.rb +8 -3
  93. data/lib/expressir/model/statements/compound.rb +7 -3
  94. data/lib/expressir/model/statements/escape.rb +3 -1
  95. data/lib/expressir/model/statements/if.rb +12 -6
  96. data/lib/expressir/model/statements/null.rb +3 -1
  97. data/lib/expressir/model/statements/procedure_call.rb +22 -0
  98. data/lib/expressir/model/statements/repeat.rb +20 -12
  99. data/lib/expressir/model/statements/return.rb +6 -2
  100. data/lib/expressir/model/statements/skip.rb +3 -1
  101. data/lib/expressir/model/supertype_expression.rb +9 -0
  102. data/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +29 -0
  103. data/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +19 -0
  104. data/lib/expressir/version.rb +1 -1
  105. data/rakelib/cross-ruby.rake +1 -1
  106. data/spec/expressir/{express_exp → express}/cache_spec.rb +9 -9
  107. data/spec/expressir/express/formatter_spec.rb +127 -0
  108. data/spec/expressir/{express_exp → express}/parser_spec.rb +24 -24
  109. data/spec/expressir/model/model_element_spec.rb +181 -129
  110. data/{original/examples → spec}/syntax/multiple.exp +1 -1
  111. data/spec/syntax/multiple.yaml +198 -0
  112. data/{original/examples → spec}/syntax/multiple_formatted.exp +1 -1
  113. data/{original/examples → spec}/syntax/multiple_hyperlink_formatted.exp +4 -4
  114. data/{original/examples → spec}/syntax/multiple_schema_head_hyperlink_formatted.exp +1 -1
  115. data/{original/examples → spec}/syntax/remark.exp +0 -0
  116. data/{original/examples → spec}/syntax/remark.yaml +87 -73
  117. data/{original/examples → spec}/syntax/remark_formatted.exp +0 -0
  118. data/spec/syntax/single.exp +4 -0
  119. data/spec/syntax/single.yaml +18 -0
  120. data/spec/syntax/single_formatted.exp +10 -0
  121. data/spec/syntax/single_formatted.yaml +36 -0
  122. data/{original/examples → spec}/syntax/syntax.exp +11 -11
  123. data/{original/examples → spec}/syntax/syntax.yaml +1181 -1111
  124. data/{original/examples → spec}/syntax/syntax_formatted.exp +11 -11
  125. data/spec/syntax/syntax_hyperlink_formatted.exp +902 -0
  126. data/{original/examples → spec}/syntax/syntax_schema_head_formatted.exp +1 -1
  127. metadata +124 -114
  128. data/lib/expressir/express.rb +0 -11
  129. data/lib/expressir/express/aggregate_dimension.rb +0 -38
  130. data/lib/expressir/express/attribute.rb +0 -15
  131. data/lib/expressir/express/comment.rb +0 -7
  132. data/lib/expressir/express/defined_type.rb +0 -36
  133. data/lib/expressir/express/derived.rb +0 -65
  134. data/lib/expressir/express/derived_aggregate.rb +0 -43
  135. data/lib/expressir/express/entity.rb +0 -137
  136. data/lib/expressir/express/explicit.rb +0 -70
  137. data/lib/expressir/express/explicit_aggregate.rb +0 -46
  138. data/lib/expressir/express/explicit_or_derived.rb +0 -16
  139. data/lib/expressir/express/global_rule.rb +0 -44
  140. data/lib/expressir/express/interface_specification.rb +0 -51
  141. data/lib/expressir/express/interfaced_item.rb +0 -38
  142. data/lib/expressir/express/inverse.rb +0 -46
  143. data/lib/expressir/express/inverse_aggregate.rb +0 -37
  144. data/lib/expressir/express/model_element.rb +0 -7
  145. data/lib/expressir/express/named_type.rb +0 -19
  146. data/lib/expressir/express/remark.rb +0 -8
  147. data/lib/expressir/express/repository.rb +0 -306
  148. data/lib/expressir/express/schema_definition.rb +0 -96
  149. data/lib/expressir/express/subtype_constraint.rb +0 -14
  150. data/lib/expressir/express/type.rb +0 -26
  151. data/lib/expressir/express/type_aggregate.rb +0 -42
  152. data/lib/expressir/express/type_enum.rb +0 -29
  153. data/lib/expressir/express/type_parser.rb +0 -45
  154. data/lib/expressir/express/type_select.rb +0 -82
  155. data/lib/expressir/express/unique_rule.rb +0 -35
  156. data/lib/expressir/express/where_rule.rb +0 -32
  157. data/lib/expressir/express_exp/cache.rb +0 -48
  158. data/lib/expressir/express_exp/hyperlink_formatter.rb +0 -27
  159. data/lib/expressir/express_exp/parser.rb +0 -64
  160. data/lib/expressir/express_exp/schema_head_formatter.rb +0 -9
  161. data/lib/expressir/express_parser.rb +0 -30
  162. data/lib/expressir/model/attribute.rb +0 -38
  163. data/lib/expressir/model/constant.rb +0 -28
  164. data/lib/expressir/model/entity.rb +0 -42
  165. data/lib/expressir/model/enumeration_item.rb +0 -22
  166. data/lib/expressir/model/expressions/aggregate_item.rb +0 -17
  167. data/lib/expressir/model/expressions/attribute_reference.rb +0 -17
  168. data/lib/expressir/model/expressions/call.rb +0 -17
  169. data/lib/expressir/model/expressions/group_reference.rb +0 -17
  170. data/lib/expressir/model/expressions/index_reference.rb +0 -19
  171. data/lib/expressir/model/expressions/simple_reference.rb +0 -15
  172. data/lib/expressir/model/function.rb +0 -57
  173. data/lib/expressir/model/interface.rb +0 -20
  174. data/lib/expressir/model/interface_item.rb +0 -15
  175. data/lib/expressir/model/interfaced_item.rb +0 -31
  176. data/lib/expressir/model/parameter.rb +0 -28
  177. data/lib/expressir/model/procedure.rb +0 -55
  178. data/lib/expressir/model/remark_item.rb +0 -15
  179. data/lib/expressir/model/rule.rb +0 -60
  180. data/lib/expressir/model/schema.rb +0 -98
  181. data/lib/expressir/model/statements/call.rb +0 -17
  182. data/lib/expressir/model/subtype_constraint.rb +0 -32
  183. data/lib/expressir/model/type.rb +0 -37
  184. data/lib/expressir/model/types/aggregate.rb +0 -28
  185. data/lib/expressir/model/types/array.rb +0 -23
  186. data/lib/expressir/model/types/bag.rb +0 -19
  187. data/lib/expressir/model/types/binary.rb +0 -17
  188. data/lib/expressir/model/types/boolean.rb +0 -8
  189. data/lib/expressir/model/types/enumeration.rb +0 -21
  190. data/lib/expressir/model/types/generic.rb +0 -24
  191. data/lib/expressir/model/types/generic_entity.rb +0 -24
  192. data/lib/expressir/model/types/integer.rb +0 -8
  193. data/lib/expressir/model/types/list.rb +0 -21
  194. data/lib/expressir/model/types/logical.rb +0 -8
  195. data/lib/expressir/model/types/number.rb +0 -8
  196. data/lib/expressir/model/types/real.rb +0 -15
  197. data/lib/expressir/model/types/select.rb +0 -23
  198. data/lib/expressir/model/types/set.rb +0 -19
  199. data/lib/expressir/model/types/string.rb +0 -17
  200. data/lib/expressir/model/unique.rb +0 -26
  201. data/lib/expressir/model/variable.rb +0 -28
  202. data/lib/expressir/model/where.rb +0 -26
  203. data/lib/expressir/parser.rb +0 -6
  204. data/lib/expressir/parser/owl_parser.rb +0 -8
  205. data/original/examples/syntax/multiple.yaml +0 -184
  206. data/original/examples/syntax/single.exp +0 -3
  207. data/original/examples/syntax/single.yaml +0 -9
  208. data/original/examples/syntax/single_formatted.exp +0 -6
  209. data/original/examples/syntax/single_formatted.yaml +0 -19
  210. data/spec/acceptance/express_to_owl_spec.rb +0 -18
  211. data/spec/expressir/express/repository_spec.rb +0 -25
  212. data/spec/expressir/express_exp/formatter_spec.rb +0 -111
@@ -0,0 +1,34 @@
1
+ module Expressir
2
+ module Model
3
+ module Declarations
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 9.5.4 Local variables
6
+ class Variable < Declaration
7
+ include Identifier
8
+
9
+ model_attr_accessor :type, 'DataType'
10
+ model_attr_accessor :expression, 'Expression'
11
+
12
+ # @param [Hash] options
13
+ # @option (see Identifier#initialize_identifier)
14
+ # @option options [DataType] :type
15
+ # @option options [Expression] :expression
16
+ def initialize(options = {})
17
+ initialize_identifier(options)
18
+
19
+ @type = options[:type]
20
+ @expression = options[:expression]
21
+
22
+ super
23
+ end
24
+
25
+ # @return [Array<Declaration>]
26
+ def children
27
+ [
28
+ *remark_items
29
+ ]
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ module Expressir
2
+ module Model
3
+ module Declarations
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 9.2.2.2 Domain rules (WHERE clause)
6
+ class WhereRule < Declaration
7
+ include Identifier
8
+
9
+ model_attr_accessor :expression, 'Expression'
10
+
11
+ # @param [Hash] options
12
+ # @option (see Identifier#initialize_identifier)
13
+ # @option options [Expression] :expression
14
+ def initialize(options = {})
15
+ initialize_identifier(options)
16
+
17
+ @expression = options[:expression]
18
+
19
+ super
20
+ end
21
+
22
+ # @return [Array<Declaration>]
23
+ def children
24
+ [
25
+ *remark_items
26
+ ]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ module Expressir
2
+ module Model
3
+ # Specified in ISO 10303-11:2004
4
+ # - section 12 Expression
5
+ # @abstract
6
+ class Expression < ModelElement
7
+ end
8
+ end
9
+ end
@@ -1,11 +1,15 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Expressions
4
- class AggregateInitializer < ModelElement
5
- model_attr_accessor :items
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.9 Aggregate initializer
6
+ class AggregateInitializer < Expression
7
+ model_attr_accessor :items, 'Array<AggregateInitializerItem>'
6
8
 
9
+ # @param [Hash] options
10
+ # @option options [Array<AggregateInitializerItem>] :items
7
11
  def initialize(options = {})
8
- @items = options.fetch(:items, [])
12
+ @items = options[:items] || []
9
13
 
10
14
  super
11
15
  end
@@ -0,0 +1,22 @@
1
+ module Expressir
2
+ module Model
3
+ module Expressions
4
+ # Specified in ISO 10303-11:2004
5
+ # - section 12.9 Aggregate initializer
6
+ class AggregateInitializerItem < Expression
7
+ model_attr_accessor :expression, 'Expression'
8
+ model_attr_accessor :repetition, 'Expression'
9
+
10
+ # @param [Hash] options
11
+ # @option options [Expression] :expression
12
+ # @option options [Expression] :repetition
13
+ def initialize(options = {})
14
+ @expression = options[:expression]
15
+ @repetition = options[:repetition]
16
+
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -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,13 +1,18 @@
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
- @parameters = options.fetch(:parameters, [])
15
+ @parameters = options[:parameters] || []
11
16
 
12
17
  super
13
18
  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
@@ -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.fetch(:remarks, [])
13
- @remark_items = options.fetch(: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,24 +2,33 @@ 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
- return id if is_a? Statements::Alias or is_a? Statements::Repeat or is_a? Expressions::QueryExpression
25
+ # this creates an implicit scope
26
+ return if is_a? Statements::Alias or is_a? Statements::Repeat or is_a? Expressions::QueryExpression
18
27
 
19
28
  current_node = self
20
29
  path_parts = []
21
30
  loop do
22
- if current_node.class.method_defined? :id
31
+ if current_node.class.method_defined? :id and !(current_node.is_a? References::SimpleReference)
23
32
  path_parts << current_node.id
24
33
  end
25
34
 
@@ -27,25 +36,13 @@ module Expressir
27
36
  break unless current_node
28
37
  end
29
38
 
30
- path_parts.reverse.join(".")
31
- end
39
+ return if path_parts.empty?
32
40
 
33
- def attach_parent_to_children
34
- self.class.model_attrs.each do |variable|
35
- value = self.send(variable)
36
-
37
- if value.is_a? Array
38
- value.each do |value|
39
- if value.is_a? ModelElement
40
- value.parent = self
41
- end
42
- end
43
- elsif value.is_a? ModelElement
44
- value.parent = self
45
- end
46
- end
41
+ path_parts.reverse.join(".")
47
42
  end
48
43
 
44
+ # @param [String] path
45
+ # @return [ModelElement]
49
46
  def find(path)
50
47
  return self if path.empty?
51
48
 
@@ -71,26 +68,34 @@ module Expressir
71
68
  break unless current_scope
72
69
  end
73
70
 
71
+ if target_node.is_a? Model::Declarations::InterfacedItem
72
+ target_node = target_node.base_item
73
+ end
74
+
74
75
  target_node
75
76
  end
76
77
 
78
+ # @return [Array<Declaration>]
77
79
  def children
78
80
  []
79
81
  end
80
82
 
83
+ # @return [Hash<String, Declaration>]
81
84
  def children_by_id
82
85
  @children_by_id ||= children.select{|x| x.id}.map{|x| [x.id.downcase, x]}.to_h
83
86
  end
84
87
 
88
+ # @return [nil]
85
89
  def reset_children_by_id
86
90
  @children_by_id = nil
91
+ nil
87
92
  end
88
-
89
- def to_hash(options = {})
90
- root_path = options[:root_path]
91
- formatter = options[:formatter]
92
- include_empty = options[:include_empty] || !options[:skip_empty] # TODO: remove skip_empty
93
-
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)
94
99
  hash = {}
95
100
  hash[CLASS_KEY] = self.class.name
96
101
 
@@ -103,20 +108,20 @@ module Expressir
103
108
  hash[variable.to_s] = if value.is_a? Array
104
109
  value.map do |value|
105
110
  if value.is_a? ModelElement
106
- value.to_hash(options)
111
+ value.to_hash(root_path: root_path, formatter: formatter, include_empty: include_empty)
107
112
  else
108
113
  value
109
114
  end
110
115
  end
111
116
  elsif value.is_a? ModelElement
112
- value.to_hash(options)
117
+ value.to_hash(root_path: root_path, formatter: formatter, include_empty: include_empty)
113
118
  else
114
119
  value
115
120
  end
116
121
  end
117
122
  end
118
123
 
119
- if self.is_a? Schema and file
124
+ if self.is_a? Declarations::Schema and file
120
125
  hash[FILE_KEY] = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : file
121
126
  end
122
127
 
@@ -126,10 +131,11 @@ module Expressir
126
131
 
127
132
  hash
128
133
  end
129
-
130
- def self.from_hash(hash, options = {})
131
- root_path = options[:root_path]
132
-
134
+
135
+ # @param [Hash] hash
136
+ # @param [String] root_path
137
+ # @return [ModelElement]
138
+ def self.from_hash(hash, root_path: nil)
133
139
  node_class = Object.const_get(hash[CLASS_KEY])
134
140
  node_options = {}
135
141
 
@@ -139,19 +145,19 @@ module Expressir
139
145
  node_options[variable] = if value.is_a? Array
140
146
  value.map do |value|
141
147
  if value.is_a? Hash
142
- self.from_hash(value, options)
148
+ self.from_hash(value, root_path: root_path)
143
149
  else
144
150
  value
145
151
  end
146
152
  end
147
153
  elsif value.is_a? Hash
148
- self.from_hash(value, options)
154
+ self.from_hash(value, root_path: root_path)
149
155
  else
150
156
  value
151
157
  end
152
158
  end
153
159
 
154
- if node_class == Schema and hash[FILE_KEY]
160
+ if node_class == Declarations::Schema and hash[FILE_KEY]
155
161
  node_options[FILE_KEY.to_sym] = root_path ? File.expand_path("#{root_path}/#{hash[FILE_KEY]}") : hash[FILE_KEY]
156
162
  end
157
163
 
@@ -160,15 +166,42 @@ module Expressir
160
166
  node
161
167
  end
162
168
 
169
+ # @return [Array<Symbol>]
163
170
  def self.model_attrs
164
171
  @model_attrs ||= []
165
172
  end
166
173
 
167
- 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)
168
181
  @model_attrs ||= []
169
- @model_attrs.concat(vars)
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)
170
193
 
171
- attr_accessor *vars
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
172
205
  end
173
206
  end
174
207
  end