expressir 0.2.14 → 0.2.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +5 -0
  3. data/exe/format +56 -11
  4. data/ext/express-parser/extconf.rb +2 -0
  5. data/lib/expressir/express_exp/formatter.rb +201 -147
  6. data/lib/expressir/express_exp/hyperlink_formatter.rb +6 -4
  7. data/lib/expressir/express_exp/parser.rb +34 -26
  8. data/lib/expressir/express_exp/schema_head_formatter.rb +2 -7
  9. data/lib/expressir/express_exp/visitor.rb +27 -54
  10. data/lib/expressir/model.rb +2 -1
  11. data/lib/expressir/model/entity.rb +6 -6
  12. data/lib/expressir/model/expressions/query_expression.rb +3 -3
  13. data/lib/expressir/model/function.rb +15 -11
  14. data/lib/expressir/model/informal_proposition.rb +4 -1
  15. data/lib/expressir/model/{renamed_ref.rb → interface_item.rb} +2 -2
  16. data/lib/expressir/model/interfaced_item.rb +26 -0
  17. data/lib/expressir/model/model_element.rb +43 -13
  18. data/lib/expressir/model/procedure.rb +15 -11
  19. data/lib/expressir/model/repository.rb +3 -3
  20. data/lib/expressir/model/rule.rb +16 -12
  21. data/lib/expressir/model/schema.rb +56 -29
  22. data/lib/expressir/model/statements/alias.rb +3 -3
  23. data/lib/expressir/model/statements/repeat.rb +3 -3
  24. data/lib/expressir/model/subtype_constraint.rb +1 -6
  25. data/lib/expressir/model/type.rb +9 -5
  26. data/lib/expressir/version.rb +1 -1
  27. data/original/examples/syntax/multiple.exp +23 -0
  28. data/original/examples/syntax/multiple.yaml +184 -0
  29. data/original/examples/syntax/multiple_formatted.exp +71 -0
  30. data/original/examples/syntax/multiple_hyperlink_formatted.exp +71 -0
  31. data/original/examples/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  32. data/original/examples/syntax/remark.exp +41 -41
  33. data/original/examples/syntax/remark.yaml +446 -0
  34. data/original/examples/syntax/remark_formatted.exp +62 -50
  35. data/original/examples/syntax/{simple.exp → single.exp} +1 -1
  36. data/original/examples/syntax/single.yaml +9 -0
  37. data/original/examples/syntax/single_formatted.exp +6 -0
  38. data/original/examples/syntax/single_formatted.yaml +19 -0
  39. data/original/examples/syntax/syntax.exp +29 -19
  40. data/original/examples/syntax/syntax.yaml +3439 -0
  41. data/original/examples/syntax/syntax_formatted.exp +271 -131
  42. data/original/examples/syntax/syntax_schema_head_formatted.exp +18 -0
  43. data/spec/expressir/express_exp/formatter_spec.rb +111 -0
  44. data/spec/expressir/express_exp/parser_spec.rb +98 -0
  45. data/spec/expressir/model/{model_element/find_spec.rb → model_element_spec.rb} +96 -10
  46. metadata +19 -18
  47. data/original/examples/syntax/hyperlink.exp +0 -8
  48. data/original/examples/syntax/hyperlink_formatted.exp +0 -19
  49. data/original/examples/syntax/source.exp +0 -16
  50. data/spec/expressir/express_exp/formatter/remark_spec.rb +0 -28
  51. data/spec/expressir/express_exp/formatter/syntax_spec.rb +0 -28
  52. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +0 -24
  53. data/spec/expressir/express_exp/parser/head_source_spec.rb +0 -38
  54. data/spec/expressir/express_exp/parser/multiple_spec.rb +0 -37
  55. data/spec/expressir/express_exp/parser/remark_spec.rb +0 -411
  56. data/spec/expressir/express_exp/parser/source_spec.rb +0 -29
  57. data/spec/expressir/express_exp/parser/syntax_spec.rb +0 -3080
  58. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +0 -36
  59. data/spec/expressir/model/model_element/hash_spec.rb +0 -66
@@ -31,18 +31,22 @@ module Expressir
31
31
  super
32
32
  end
33
33
 
34
+ def enumeration_items
35
+ types.flat_map{|x| x.enumeration_items}
36
+ end
37
+
34
38
  def children
35
- items = []
36
- items.push(*@parameters)
37
- items.push(*@types)
38
- items.push(*@types.flat_map{|x| x.type.is_a?(Expressir::Model::Types::Enumeration) ? x.type.items : []})
39
- items.push(*@entities)
40
- items.push(*@subtype_constraints)
41
- items.push(*@functions)
42
- items.push(*@procedures)
43
- items.push(*@constants)
44
- items.push(*@variables)
45
- items
39
+ [
40
+ *parameters,
41
+ *types,
42
+ *enumeration_items,
43
+ *entities,
44
+ *subtype_constraints,
45
+ *functions,
46
+ *procedures,
47
+ *constants,
48
+ *variables
49
+ ]
46
50
  end
47
51
  end
48
52
  end
@@ -10,9 +10,9 @@ module Expressir
10
10
  end
11
11
 
12
12
  def children
13
- items = []
14
- items.push(*@schemas)
15
- items
13
+ [
14
+ *schemas
15
+ ]
16
16
  end
17
17
  end
18
18
  end
@@ -35,19 +35,23 @@ module Expressir
35
35
  super
36
36
  end
37
37
 
38
+ def enumeration_items
39
+ types.flat_map{|x| x.enumeration_items}
40
+ end
41
+
38
42
  def children
39
- items = []
40
- items.push(*@types)
41
- items.push(*@types.flat_map{|x| x.type.is_a?(Expressir::Model::Types::Enumeration) ? x.type.items : []})
42
- items.push(*@entities)
43
- items.push(*@subtype_constraints)
44
- items.push(*@functions)
45
- items.push(*@procedures)
46
- items.push(*@constants)
47
- items.push(*@variables)
48
- items.push(*@where)
49
- items.push(*@informal_propositions)
50
- items
43
+ [
44
+ *types,
45
+ *enumeration_items,
46
+ *entities,
47
+ *subtype_constraints,
48
+ *functions,
49
+ *procedures,
50
+ *constants,
51
+ *variables,
52
+ *where,
53
+ *informal_propositions
54
+ ]
51
55
  end
52
56
  end
53
57
  end
@@ -5,8 +5,6 @@ module Expressir
5
5
 
6
6
  include Identifier
7
7
 
8
- attr_accessor :head_source
9
-
10
8
  attr_accessor :version
11
9
  attr_accessor :interfaces
12
10
  attr_accessor :constants
@@ -14,8 +12,8 @@ module Expressir
14
12
  attr_accessor :entities
15
13
  attr_accessor :subtype_constraints
16
14
  attr_accessor :functions
17
- attr_accessor :procedures
18
15
  attr_accessor :rules
16
+ attr_accessor :procedures
19
17
 
20
18
  def initialize(options = {})
21
19
  @file = options[:file]
@@ -23,7 +21,6 @@ module Expressir
23
21
  @id = options[:id]
24
22
  @remarks = options.fetch(:remarks, [])
25
23
  @source = options[:source]
26
- @head_source = options[:head_source]
27
24
 
28
25
  @version = options[:version]
29
26
  @interfaces = options.fetch(:interfaces, [])
@@ -32,37 +29,67 @@ module Expressir
32
29
  @entities = options.fetch(:entities, [])
33
30
  @subtype_constraints = options.fetch(:subtype_constraints, [])
34
31
  @functions = options.fetch(:functions, [])
35
- @procedures = options.fetch(:procedures, [])
36
32
  @rules = options.fetch(:rules, [])
33
+ @procedures = options.fetch(:procedures, [])
37
34
 
38
35
  super
39
36
  end
40
37
 
41
- def children(item_ids = nil)
42
- items = []
43
- unless item_ids and item_ids.length > 0
44
- items.push(*@interfaces.flat_map do |interface|
45
- schema = parent.schemas.find{|y| interface.schema.id == y.id}
46
- interface_item_ids = if interface.items
47
- # TODO: support renamed references
48
- interface.items.select{|x| x.is_a? Model::Expressions::SimpleReference}.map{|x| x.id}
38
+ def create_interfaced_item(id, base_item)
39
+ interfaced_item = InterfacedItem.new({
40
+ id: id
41
+ })
42
+ interfaced_item.base_item = base_item # skip overriding parent
43
+ interfaced_item.parent = self
44
+ interfaced_item
45
+ end
46
+
47
+ def interfaced_items
48
+ interfaces.flat_map do |interface|
49
+ schema = parent.children_by_id[interface.schema.id.downcase]
50
+ if schema
51
+ schema_safe_children = schema.safe_children
52
+ schema_safe_children_by_id = schema_safe_children.select{|x| x.id}.map{|x| [x.id.downcase, x]}.to_h
53
+ if interface.items.length > 0
54
+ interface.items.map do |interface_item|
55
+ base_item = schema_safe_children_by_id[interface_item.ref.id.downcase]
56
+ if base_item
57
+ id = interface_item.id || base_item.id
58
+ create_interfaced_item(id, base_item)
59
+ end
60
+ end
61
+ else
62
+ schema_safe_children.map do |base_item|
63
+ id = base_item.id
64
+ create_interfaced_item(id, base_item)
65
+ end
49
66
  end
50
- schema_items = schema&.children(interface_item_ids) || []
51
- schema_items
52
- end)
53
- end
54
- items.push(*@constants)
55
- items.push(*@types)
56
- items.push(*@types.flat_map{|x| x.type.is_a?(Expressir::Model::Types::Enumeration) ? x.type.items : []})
57
- items.push(*@entities)
58
- items.push(*@subtype_constraints)
59
- items.push(*@functions)
60
- items.push(*@procedures)
61
- items.push(*@rules)
62
- if item_ids and item_ids.length > 0
63
- items = items.select{|x| item_ids.include?(x.id)}
64
- end
65
- items
67
+ end
68
+ end.select{|x| x}
69
+ end
70
+
71
+ def enumeration_items
72
+ types.flat_map{|x| x.enumeration_items}
73
+ end
74
+
75
+ def safe_children
76
+ [
77
+ *constants,
78
+ *types,
79
+ *enumeration_items,
80
+ *entities,
81
+ *subtype_constraints,
82
+ *functions,
83
+ *rules,
84
+ *procedures
85
+ ]
86
+ end
87
+
88
+ def children
89
+ [
90
+ *interfaced_items,
91
+ *safe_children
92
+ ]
66
93
  end
67
94
  end
68
95
  end
@@ -19,9 +19,9 @@ module Expressir
19
19
  end
20
20
 
21
21
  def children
22
- items = []
23
- items.push(self)
24
- items
22
+ [
23
+ self
24
+ ]
25
25
  end
26
26
  end
27
27
  end
@@ -27,9 +27,9 @@ module Expressir
27
27
  end
28
28
 
29
29
  def children
30
- items = []
31
- items.push(self)
32
- items
30
+ [
31
+ self
32
+ ]
33
33
  end
34
34
  end
35
35
  end
@@ -15,16 +15,11 @@ module Expressir
15
15
 
16
16
  @applies_to = options[:applies_to]
17
17
  @abstract = options[:abstract]
18
- @total_over = options[:total_over]
18
+ @total_over = options.fetch(:total_over, [])
19
19
  @supertype_expression = options[:supertype_expression]
20
20
 
21
21
  super
22
22
  end
23
-
24
- def children
25
- items = []
26
- items
27
- end
28
23
  end
29
24
  end
30
25
  end
@@ -19,12 +19,16 @@ module Expressir
19
19
  super
20
20
  end
21
21
 
22
+ def enumeration_items
23
+ type.is_a?(Types::Enumeration) ? type.items : []
24
+ end
25
+
22
26
  def children
23
- items = []
24
- items.push(*@type.is_a?(Expressir::Model::Types::Enumeration) ? @type.items : [])
25
- items.push(*@where)
26
- items.push(*@informal_propositions)
27
- items
27
+ [
28
+ *enumeration_items,
29
+ *where,
30
+ *informal_propositions
31
+ ]
28
32
  end
29
33
  end
30
34
  end
@@ -1,3 +1,3 @@
1
1
  module Expressir
2
- VERSION = "0.2.14".freeze
2
+ VERSION = "0.2.19".freeze
3
3
  end
@@ -0,0 +1,23 @@
1
+ SCHEMA multiple_schema1;
2
+ REFERENCE FROM multiple_schema2;
3
+ REFERENCE FROM multiple_schema3 (attribute_entity3);
4
+ REFERENCE FROM multiple_schema4 (attribute_entity AS attribute_entity4);
5
+ ENTITY test; END_ENTITY;
6
+ ENTITY empty_entity; END_ENTITY;
7
+ ENTITY attribute_entity; test : BOOLEAN; END_ENTITY;
8
+ ENTITY subtype_empty_entity SUBTYPE OF (empty_entity); END_ENTITY;
9
+ ENTITY subtype_attribute_entity SUBTYPE OF (attribute_entity); SELF\attribute_entity.test : BOOLEAN; END_ENTITY;
10
+ ENTITY subtype_attribute_entity2 SUBTYPE OF (attribute_entity2); SELF\attribute_entity2.test : BOOLEAN; END_ENTITY;
11
+ ENTITY subtype_attribute_entity3 SUBTYPE OF (attribute_entity3); SELF\attribute_entity3.test : BOOLEAN; END_ENTITY;
12
+ ENTITY subtype_attribute_entity4 SUBTYPE OF (attribute_entity4); SELF\attribute_entity4.test : BOOLEAN; END_ENTITY;
13
+ ENTITY subtype_missing_entity SUBTYPE OF (missing_entity); END_ENTITY;
14
+ END_SCHEMA;
15
+ SCHEMA multiple_schema2;
16
+ ENTITY attribute_entity2; test : BOOLEAN; END_ENTITY;
17
+ END_SCHEMA;
18
+ SCHEMA multiple_schema3;
19
+ ENTITY attribute_entity3; test : BOOLEAN; END_ENTITY;
20
+ END_SCHEMA;
21
+ SCHEMA multiple_schema4;
22
+ ENTITY attribute_entity; test : BOOLEAN; END_ENTITY;
23
+ END_SCHEMA;
@@ -0,0 +1,184 @@
1
+ ---
2
+ _class: Expressir::Model::Repository
3
+ schemas:
4
+ - _class: Expressir::Model::Schema
5
+ file: original/examples/syntax/multiple.exp
6
+ id: multiple_schema1
7
+ interfaces:
8
+ - _class: Expressir::Model::Interface
9
+ kind: :REFERENCE
10
+ schema:
11
+ _class: Expressir::Model::Expressions::SimpleReference
12
+ id: multiple_schema2
13
+ - _class: Expressir::Model::Interface
14
+ kind: :REFERENCE
15
+ schema:
16
+ _class: Expressir::Model::Expressions::SimpleReference
17
+ id: multiple_schema3
18
+ items:
19
+ - _class: Expressir::Model::InterfaceItem
20
+ ref:
21
+ _class: Expressir::Model::Expressions::SimpleReference
22
+ id: attribute_entity3
23
+ - _class: Expressir::Model::Interface
24
+ kind: :REFERENCE
25
+ schema:
26
+ _class: Expressir::Model::Expressions::SimpleReference
27
+ id: multiple_schema4
28
+ items:
29
+ - _class: Expressir::Model::InterfaceItem
30
+ ref:
31
+ _class: Expressir::Model::Expressions::SimpleReference
32
+ id: attribute_entity
33
+ id: attribute_entity4
34
+ entities:
35
+ - _class: Expressir::Model::Entity
36
+ id: test
37
+ - _class: Expressir::Model::Entity
38
+ id: empty_entity
39
+ - _class: Expressir::Model::Entity
40
+ id: attribute_entity
41
+ attributes:
42
+ - _class: Expressir::Model::Attribute
43
+ id: test
44
+ kind: :EXPLICIT
45
+ type:
46
+ _class: Expressir::Model::Types::Boolean
47
+ - _class: Expressir::Model::Entity
48
+ id: subtype_empty_entity
49
+ subtype_of:
50
+ - _class: Expressir::Model::Expressions::SimpleReference
51
+ id: empty_entity
52
+ - _class: Expressir::Model::Entity
53
+ id: subtype_attribute_entity
54
+ subtype_of:
55
+ - _class: Expressir::Model::Expressions::SimpleReference
56
+ id: attribute_entity
57
+ attributes:
58
+ - _class: Expressir::Model::Attribute
59
+ kind: :EXPLICIT
60
+ supertype_attribute:
61
+ _class: Expressir::Model::Expressions::AttributeReference
62
+ ref:
63
+ _class: Expressir::Model::Expressions::GroupReference
64
+ ref:
65
+ _class: Expressir::Model::Expressions::SimpleReference
66
+ id: SELF
67
+ entity:
68
+ _class: Expressir::Model::Expressions::SimpleReference
69
+ id: attribute_entity
70
+ attribute:
71
+ _class: Expressir::Model::Expressions::SimpleReference
72
+ id: test
73
+ type:
74
+ _class: Expressir::Model::Types::Boolean
75
+ - _class: Expressir::Model::Entity
76
+ id: subtype_attribute_entity2
77
+ subtype_of:
78
+ - _class: Expressir::Model::Expressions::SimpleReference
79
+ id: attribute_entity2
80
+ attributes:
81
+ - _class: Expressir::Model::Attribute
82
+ kind: :EXPLICIT
83
+ supertype_attribute:
84
+ _class: Expressir::Model::Expressions::AttributeReference
85
+ ref:
86
+ _class: Expressir::Model::Expressions::GroupReference
87
+ ref:
88
+ _class: Expressir::Model::Expressions::SimpleReference
89
+ id: SELF
90
+ entity:
91
+ _class: Expressir::Model::Expressions::SimpleReference
92
+ id: attribute_entity2
93
+ attribute:
94
+ _class: Expressir::Model::Expressions::SimpleReference
95
+ id: test
96
+ type:
97
+ _class: Expressir::Model::Types::Boolean
98
+ - _class: Expressir::Model::Entity
99
+ id: subtype_attribute_entity3
100
+ subtype_of:
101
+ - _class: Expressir::Model::Expressions::SimpleReference
102
+ id: attribute_entity3
103
+ attributes:
104
+ - _class: Expressir::Model::Attribute
105
+ kind: :EXPLICIT
106
+ supertype_attribute:
107
+ _class: Expressir::Model::Expressions::AttributeReference
108
+ ref:
109
+ _class: Expressir::Model::Expressions::GroupReference
110
+ ref:
111
+ _class: Expressir::Model::Expressions::SimpleReference
112
+ id: SELF
113
+ entity:
114
+ _class: Expressir::Model::Expressions::SimpleReference
115
+ id: attribute_entity3
116
+ attribute:
117
+ _class: Expressir::Model::Expressions::SimpleReference
118
+ id: test
119
+ type:
120
+ _class: Expressir::Model::Types::Boolean
121
+ - _class: Expressir::Model::Entity
122
+ id: subtype_attribute_entity4
123
+ subtype_of:
124
+ - _class: Expressir::Model::Expressions::SimpleReference
125
+ id: attribute_entity4
126
+ attributes:
127
+ - _class: Expressir::Model::Attribute
128
+ kind: :EXPLICIT
129
+ supertype_attribute:
130
+ _class: Expressir::Model::Expressions::AttributeReference
131
+ ref:
132
+ _class: Expressir::Model::Expressions::GroupReference
133
+ ref:
134
+ _class: Expressir::Model::Expressions::SimpleReference
135
+ id: SELF
136
+ entity:
137
+ _class: Expressir::Model::Expressions::SimpleReference
138
+ id: attribute_entity4
139
+ attribute:
140
+ _class: Expressir::Model::Expressions::SimpleReference
141
+ id: test
142
+ type:
143
+ _class: Expressir::Model::Types::Boolean
144
+ - _class: Expressir::Model::Entity
145
+ id: subtype_missing_entity
146
+ subtype_of:
147
+ - _class: Expressir::Model::Expressions::SimpleReference
148
+ id: missing_entity
149
+ - _class: Expressir::Model::Schema
150
+ file: original/examples/syntax/multiple.exp
151
+ id: multiple_schema2
152
+ entities:
153
+ - _class: Expressir::Model::Entity
154
+ id: attribute_entity2
155
+ attributes:
156
+ - _class: Expressir::Model::Attribute
157
+ id: test
158
+ kind: :EXPLICIT
159
+ type:
160
+ _class: Expressir::Model::Types::Boolean
161
+ - _class: Expressir::Model::Schema
162
+ file: original/examples/syntax/multiple.exp
163
+ id: multiple_schema3
164
+ entities:
165
+ - _class: Expressir::Model::Entity
166
+ id: attribute_entity3
167
+ attributes:
168
+ - _class: Expressir::Model::Attribute
169
+ id: test
170
+ kind: :EXPLICIT
171
+ type:
172
+ _class: Expressir::Model::Types::Boolean
173
+ - _class: Expressir::Model::Schema
174
+ file: original/examples/syntax/multiple.exp
175
+ id: multiple_schema4
176
+ entities:
177
+ - _class: Expressir::Model::Entity
178
+ id: attribute_entity
179
+ attributes:
180
+ - _class: Expressir::Model::Attribute
181
+ id: test
182
+ kind: :EXPLICIT
183
+ type:
184
+ _class: Expressir::Model::Types::Boolean