expressir 0.2.16 → 0.2.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +5 -0
  3. data/.github/workflows/release.yml +31 -3
  4. data/README.adoc +3 -3
  5. data/exe/format +66 -12
  6. data/ext/express-parser/extconf.rb +2 -0
  7. data/lib/expressir/express_exp/cache.rb +48 -0
  8. data/lib/expressir/express_exp/formatter.rb +185 -135
  9. data/lib/expressir/express_exp/parser.rb +33 -29
  10. data/lib/expressir/express_exp/schema_head_formatter.rb +1 -4
  11. data/lib/expressir/express_exp/visitor.rb +29 -23
  12. data/lib/expressir/model.rb +3 -1
  13. data/lib/expressir/model/attribute.rb +12 -5
  14. data/lib/expressir/model/cache.rb +13 -0
  15. data/lib/expressir/model/constant.rb +9 -2
  16. data/lib/expressir/model/entity.rb +15 -13
  17. data/lib/expressir/model/enumeration_item.rb +7 -0
  18. data/lib/expressir/model/expressions/aggregate_initializer.rb +1 -1
  19. data/lib/expressir/model/expressions/aggregate_item.rb +2 -2
  20. data/lib/expressir/model/expressions/attribute_reference.rb +2 -2
  21. data/lib/expressir/model/expressions/binary_expression.rb +3 -3
  22. data/lib/expressir/model/expressions/call.rb +2 -2
  23. data/lib/expressir/model/expressions/entity_constructor.rb +2 -2
  24. data/lib/expressir/model/expressions/group_reference.rb +2 -2
  25. data/lib/expressir/model/expressions/index_reference.rb +3 -3
  26. data/lib/expressir/model/expressions/interval.rb +5 -5
  27. data/lib/expressir/model/expressions/query_expression.rb +7 -5
  28. data/lib/expressir/model/expressions/simple_reference.rb +1 -1
  29. data/lib/expressir/model/expressions/unary_expression.rb +2 -2
  30. data/lib/expressir/model/function.rb +27 -21
  31. data/lib/expressir/model/identifier.rb +6 -3
  32. data/lib/expressir/model/interface.rb +3 -3
  33. data/lib/expressir/model/interface_item.rb +2 -2
  34. data/lib/expressir/model/interfaced_item.rb +11 -3
  35. data/lib/expressir/model/literals/binary.rb +1 -1
  36. data/lib/expressir/model/literals/integer.rb +1 -1
  37. data/lib/expressir/model/literals/logical.rb +1 -1
  38. data/lib/expressir/model/literals/real.rb +1 -1
  39. data/lib/expressir/model/literals/string.rb +2 -2
  40. data/lib/expressir/model/model_element.rb +54 -19
  41. data/lib/expressir/model/parameter.rb +9 -2
  42. data/lib/expressir/model/procedure.rb +26 -20
  43. data/lib/expressir/model/{informal_proposition.rb → remark_item.rb} +3 -3
  44. data/lib/expressir/model/repository.rb +4 -4
  45. data/lib/expressir/model/rule.rb +29 -23
  46. data/lib/expressir/model/schema.rb +63 -54
  47. data/lib/expressir/model/statements/alias.rb +7 -5
  48. data/lib/expressir/model/statements/assignment.rb +2 -2
  49. data/lib/expressir/model/statements/call.rb +2 -2
  50. data/lib/expressir/model/statements/case.rb +3 -3
  51. data/lib/expressir/model/statements/case_action.rb +2 -2
  52. data/lib/expressir/model/statements/compound.rb +1 -1
  53. data/lib/expressir/model/statements/if.rb +3 -3
  54. data/lib/expressir/model/statements/repeat.rb +11 -9
  55. data/lib/expressir/model/statements/return.rb +1 -1
  56. data/lib/expressir/model/subtype_constraint.rb +9 -7
  57. data/lib/expressir/model/type.rb +14 -8
  58. data/lib/expressir/model/types/aggregate.rb +8 -1
  59. data/lib/expressir/model/types/array.rb +5 -5
  60. data/lib/expressir/model/types/bag.rb +3 -3
  61. data/lib/expressir/model/types/binary.rb +2 -2
  62. data/lib/expressir/model/types/enumeration.rb +4 -4
  63. data/lib/expressir/model/types/generic.rb +7 -0
  64. data/lib/expressir/model/types/generic_entity.rb +7 -0
  65. data/lib/expressir/model/types/list.rb +4 -4
  66. data/lib/expressir/model/types/real.rb +1 -1
  67. data/lib/expressir/model/types/select.rb +5 -5
  68. data/lib/expressir/model/types/set.rb +3 -3
  69. data/lib/expressir/model/types/string.rb +2 -2
  70. data/lib/expressir/model/unique.rb +8 -1
  71. data/lib/expressir/model/variable.rb +9 -2
  72. data/lib/expressir/model/where.rb +8 -1
  73. data/lib/expressir/version.rb +1 -1
  74. data/original/examples/syntax/{hyperlink.exp → multiple.exp} +8 -8
  75. data/original/examples/syntax/multiple.yaml +184 -0
  76. data/original/examples/syntax/multiple_formatted.exp +71 -0
  77. data/original/examples/syntax/multiple_hyperlink_formatted.exp +71 -0
  78. data/original/examples/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  79. data/original/examples/syntax/remark.exp +52 -50
  80. data/original/examples/syntax/remark.yaml +452 -0
  81. data/original/examples/syntax/remark_formatted.exp +64 -50
  82. data/original/examples/syntax/{simple.exp → single.exp} +1 -1
  83. data/original/examples/syntax/single.yaml +9 -0
  84. data/original/examples/syntax/single_formatted.exp +6 -0
  85. data/original/examples/syntax/single_formatted.yaml +19 -0
  86. data/original/examples/syntax/syntax.exp +29 -19
  87. data/original/examples/syntax/syntax.yaml +3439 -0
  88. data/original/examples/syntax/syntax_formatted.exp +271 -131
  89. data/original/examples/syntax/syntax_schema_head_formatted.exp +18 -0
  90. data/spec/expressir/express_exp/cache_spec.rb +64 -0
  91. data/spec/expressir/express_exp/formatter_spec.rb +111 -0
  92. data/spec/expressir/express_exp/parser_spec.rb +98 -0
  93. data/spec/expressir/model/{model_element/find_spec.rb → model_element_spec.rb} +96 -10
  94. metadata +21 -17
  95. data/original/examples/syntax/hyperlink_formatted.exp +0 -51
  96. data/original/examples/syntax/source.exp +0 -16
  97. data/spec/expressir/express_exp/formatter/remark_spec.rb +0 -28
  98. data/spec/expressir/express_exp/formatter/syntax_spec.rb +0 -28
  99. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +0 -28
  100. data/spec/expressir/express_exp/parser/multiple_spec.rb +0 -37
  101. data/spec/expressir/express_exp/parser/remark_spec.rb +0 -411
  102. data/spec/expressir/express_exp/parser/source_spec.rb +0 -29
  103. data/spec/expressir/express_exp/parser/syntax_spec.rb +0 -3086
  104. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +0 -40
  105. data/spec/expressir/model/model_element/hash_spec.rb +0 -66
@@ -3,19 +3,20 @@ module Expressir
3
3
  class Procedure < ModelElement
4
4
  include Identifier
5
5
 
6
- attr_accessor :parameters
7
- attr_accessor :types
8
- attr_accessor :entities
9
- attr_accessor :subtype_constraints
10
- attr_accessor :functions
11
- attr_accessor :procedures
12
- attr_accessor :constants
13
- attr_accessor :variables
14
- attr_accessor :statements
6
+ model_attr_accessor :parameters
7
+ model_attr_accessor :types
8
+ model_attr_accessor :entities
9
+ model_attr_accessor :subtype_constraints
10
+ model_attr_accessor :functions
11
+ model_attr_accessor :procedures
12
+ model_attr_accessor :constants
13
+ model_attr_accessor :variables
14
+ model_attr_accessor :statements
15
15
 
16
16
  def initialize(options = {})
17
17
  @id = options[:id]
18
18
  @remarks = options.fetch(:remarks, [])
19
+ @remark_items = options.fetch(:remark_items, [])
19
20
  @source = options[:source]
20
21
 
21
22
  @parameters = options.fetch(:parameters, [])
@@ -31,18 +32,23 @@ module Expressir
31
32
  super
32
33
  end
33
34
 
35
+ def enumeration_items
36
+ types.flat_map{|x| x.enumeration_items}
37
+ end
38
+
34
39
  def children
35
- items = []
36
- items.push(*@parameters)
37
- items.push(*@types)
38
- items.push(*@types.flat_map{|x| x.type.is_a?(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
40
+ [
41
+ *parameters,
42
+ *types,
43
+ *enumeration_items,
44
+ *entities,
45
+ *subtype_constraints,
46
+ *functions,
47
+ *procedures,
48
+ *constants,
49
+ *variables,
50
+ *remark_items
51
+ ]
46
52
  end
47
53
  end
48
54
  end
@@ -1,12 +1,12 @@
1
1
  module Expressir
2
2
  module Model
3
- class InformalProposition < ModelElement
4
- include Identifier
3
+ class RemarkItem < ModelElement
4
+ model_attr_accessor :id
5
+ model_attr_accessor :remarks
5
6
 
6
7
  def initialize(options = {})
7
8
  @id = options[:id]
8
9
  @remarks = options.fetch(:remarks, [])
9
- @source = options[:source]
10
10
 
11
11
  super
12
12
  end
@@ -1,7 +1,7 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Repository < ModelElement
4
- attr_accessor :schemas
4
+ model_attr_accessor :schemas
5
5
 
6
6
  def initialize(options = {})
7
7
  @schemas = options.fetch(:schemas, [])
@@ -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
@@ -3,21 +3,22 @@ module Expressir
3
3
  class Rule < ModelElement
4
4
  include Identifier
5
5
 
6
- attr_accessor :applies_to
7
- attr_accessor :types
8
- attr_accessor :entities
9
- attr_accessor :subtype_constraints
10
- attr_accessor :functions
11
- attr_accessor :procedures
12
- attr_accessor :constants
13
- attr_accessor :variables
14
- attr_accessor :statements
15
- attr_accessor :where
16
- attr_accessor :informal_propositions
6
+ model_attr_accessor :applies_to
7
+ model_attr_accessor :types
8
+ model_attr_accessor :entities
9
+ model_attr_accessor :subtype_constraints
10
+ model_attr_accessor :functions
11
+ model_attr_accessor :procedures
12
+ model_attr_accessor :constants
13
+ model_attr_accessor :variables
14
+ model_attr_accessor :statements
15
+ model_attr_accessor :where
16
+ model_attr_accessor :informal_propositions
17
17
 
18
18
  def initialize(options = {})
19
19
  @id = options[:id]
20
20
  @remarks = options.fetch(:remarks, [])
21
+ @remark_items = options.fetch(:remark_items, [])
21
22
  @source = options[:source]
22
23
 
23
24
  @applies_to = options.fetch(:applies_to, [])
@@ -35,19 +36,24 @@ module Expressir
35
36
  super
36
37
  end
37
38
 
39
+ def enumeration_items
40
+ types.flat_map{|x| x.enumeration_items}
41
+ end
42
+
38
43
  def children
39
- items = []
40
- items.push(*@types)
41
- items.push(*@types.flat_map{|x| x.type.is_a?(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
44
+ [
45
+ *types,
46
+ *enumeration_items,
47
+ *entities,
48
+ *subtype_constraints,
49
+ *functions,
50
+ *procedures,
51
+ *constants,
52
+ *variables,
53
+ *where,
54
+ *informal_propositions,
55
+ *remark_items
56
+ ]
51
57
  end
52
58
  end
53
59
  end
@@ -1,25 +1,26 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Schema < ModelElement
4
- attr_accessor :file
4
+ model_attr_accessor :file
5
5
 
6
6
  include Identifier
7
7
 
8
- attr_accessor :version
9
- attr_accessor :interfaces
10
- attr_accessor :constants
11
- attr_accessor :types
12
- attr_accessor :entities
13
- attr_accessor :subtype_constraints
14
- attr_accessor :functions
15
- attr_accessor :procedures
16
- attr_accessor :rules
8
+ model_attr_accessor :version
9
+ model_attr_accessor :interfaces
10
+ model_attr_accessor :constants
11
+ model_attr_accessor :types
12
+ model_attr_accessor :entities
13
+ model_attr_accessor :subtype_constraints
14
+ model_attr_accessor :functions
15
+ model_attr_accessor :rules
16
+ model_attr_accessor :procedures
17
17
 
18
18
  def initialize(options = {})
19
19
  @file = options[:file]
20
20
 
21
21
  @id = options[:id]
22
22
  @remarks = options.fetch(:remarks, [])
23
+ @remark_items = options.fetch(:remark_items, [])
23
24
  @source = options[:source]
24
25
 
25
26
  @version = options[:version]
@@ -29,60 +30,68 @@ module Expressir
29
30
  @entities = options.fetch(:entities, [])
30
31
  @subtype_constraints = options.fetch(:subtype_constraints, [])
31
32
  @functions = options.fetch(:functions, [])
32
- @procedures = options.fetch(:procedures, [])
33
33
  @rules = options.fetch(:rules, [])
34
+ @procedures = options.fetch(:procedures, [])
34
35
 
35
36
  super
36
37
  end
37
38
 
38
- def children(skip_references = false)
39
- items = []
40
- unless skip_references
41
- items.push(*@interfaces.flat_map do |interface|
42
- schema_id = interface.schema.id.downcase
43
- schema = parent.schemas.find{|x| x.id.downcase == schema_id}
44
- if schema
45
- schema_children = schema.children(true) # prevent infinite recursion
46
- if interface.items.length > 0
47
- interface.items.map do |item|
48
- ref_id = item.ref.id.downcase
49
- id = item.id || ref_id
50
- base_item = schema_children.find{|x| x.id and x.id.downcase == ref_id}
51
-
52
- interfaced_item = InterfacedItem.new({
53
- id: id
54
- })
55
- interfaced_item.base_item = base_item # skip overriding parent
56
- interfaced_item.parent = self
57
- interfaced_item
58
- end
59
- else
60
- schema_children.map do |item|
61
- id = item.id
62
- base_item = item
39
+ def create_interfaced_item(id, base_item)
40
+ interfaced_item = InterfacedItem.new({
41
+ id: id
42
+ })
43
+ interfaced_item.base_item = base_item # skip overriding parent
44
+ interfaced_item.parent = self
45
+ interfaced_item
46
+ end
63
47
 
64
- interfaced_item = InterfacedItem.new({
65
- id: id
66
- })
67
- interfaced_item.base_item = base_item # skip overriding parent
68
- interfaced_item.parent = self
69
- interfaced_item
48
+ def interfaced_items
49
+ interfaces.flat_map do |interface|
50
+ schema = parent.children_by_id[interface.schema.id.downcase]
51
+ if schema
52
+ schema_safe_children = schema.safe_children
53
+ schema_safe_children_by_id = schema_safe_children.select{|x| x.id}.map{|x| [x.id.downcase, x]}.to_h
54
+ if interface.items.length > 0
55
+ interface.items.map do |interface_item|
56
+ base_item = schema_safe_children_by_id[interface_item.ref.id.downcase]
57
+ if base_item
58
+ id = interface_item.id || base_item.id
59
+ create_interfaced_item(id, base_item)
70
60
  end
71
61
  end
72
62
  else
73
- []
63
+ schema_safe_children.map do |base_item|
64
+ id = base_item.id
65
+ create_interfaced_item(id, base_item)
66
+ end
74
67
  end
75
- end)
76
- end
77
- items.push(*@constants)
78
- items.push(*@types)
79
- items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
80
- items.push(*@entities)
81
- items.push(*@subtype_constraints)
82
- items.push(*@functions)
83
- items.push(*@procedures)
84
- items.push(*@rules)
85
- items
68
+ end
69
+ end.select{|x| x}
70
+ end
71
+
72
+ def enumeration_items
73
+ types.flat_map{|x| x.enumeration_items}
74
+ end
75
+
76
+ def safe_children
77
+ [
78
+ *constants,
79
+ *types,
80
+ *enumeration_items,
81
+ *entities,
82
+ *subtype_constraints,
83
+ *functions,
84
+ *rules,
85
+ *procedures,
86
+ *remark_items
87
+ ]
88
+ end
89
+
90
+ def children
91
+ [
92
+ *interfaced_items,
93
+ *safe_children
94
+ ]
86
95
  end
87
96
  end
88
97
  end
@@ -4,12 +4,13 @@ module Expressir
4
4
  class Alias < ModelElement
5
5
  include Identifier
6
6
 
7
- attr_accessor :expression
8
- attr_accessor :statements
7
+ model_attr_accessor :expression
8
+ model_attr_accessor :statements
9
9
 
10
10
  def initialize(options = {})
11
11
  @id = options[:id]
12
12
  @remarks = options.fetch(:remarks, [])
13
+ @remark_items = options.fetch(:remark_items, [])
13
14
  @source = options[:source]
14
15
 
15
16
  @expression = options[:expression]
@@ -19,9 +20,10 @@ module Expressir
19
20
  end
20
21
 
21
22
  def children
22
- items = []
23
- items.push(self)
24
- items
23
+ [
24
+ self,
25
+ *remark_items
26
+ ]
25
27
  end
26
28
  end
27
29
  end
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class Assignment < ModelElement
5
- attr_accessor :ref
6
- attr_accessor :expression
5
+ model_attr_accessor :ref
6
+ model_attr_accessor :expression
7
7
 
8
8
  def initialize(options = {})
9
9
  @ref = options[:ref]
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class Call < ModelElement
5
- attr_accessor :ref
6
- attr_accessor :parameters
5
+ model_attr_accessor :ref
6
+ model_attr_accessor :parameters
7
7
 
8
8
  def initialize(options = {})
9
9
  @ref = options[:ref]
@@ -2,9 +2,9 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class Case < ModelElement
5
- attr_accessor :expression
6
- attr_accessor :actions
7
- attr_accessor :otherwise_statement
5
+ model_attr_accessor :expression
6
+ model_attr_accessor :actions
7
+ model_attr_accessor :otherwise_statement
8
8
 
9
9
  def initialize(options = {})
10
10
  @expression = options[:expression]
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class CaseAction < ModelElement
5
- attr_accessor :labels
6
- attr_accessor :statement
5
+ model_attr_accessor :labels
6
+ model_attr_accessor :statement
7
7
 
8
8
  def initialize(options = {})
9
9
  @labels = options.fetch(:labels, [])
@@ -2,7 +2,7 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class Compound < ModelElement
5
- attr_accessor :statements
5
+ model_attr_accessor :statements
6
6
 
7
7
  def initialize(options = {})
8
8
  @statements = options.fetch(:statements, [])
@@ -2,9 +2,9 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class If < ModelElement
5
- attr_accessor :expression
6
- attr_accessor :statements
7
- attr_accessor :else_statements
5
+ model_attr_accessor :expression
6
+ model_attr_accessor :statements
7
+ model_attr_accessor :else_statements
8
8
 
9
9
  def initialize(options = {})
10
10
  @expression = options[:expression]
@@ -4,16 +4,17 @@ module Expressir
4
4
  class Repeat < ModelElement
5
5
  include Identifier
6
6
 
7
- attr_accessor :bound1
8
- attr_accessor :bound2
9
- attr_accessor :increment
10
- attr_accessor :while_expression
11
- attr_accessor :until_expression
12
- attr_accessor :statements
7
+ model_attr_accessor :bound1
8
+ model_attr_accessor :bound2
9
+ model_attr_accessor :increment
10
+ model_attr_accessor :while_expression
11
+ model_attr_accessor :until_expression
12
+ model_attr_accessor :statements
13
13
 
14
14
  def initialize(options = {})
15
15
  @id = options[:id]
16
16
  @remarks = options.fetch(:remarks, [])
17
+ @remark_items = options.fetch(:remark_items, [])
17
18
  @source = options[:source]
18
19
 
19
20
  @bound1 = options[:bound1]
@@ -27,9 +28,10 @@ module Expressir
27
28
  end
28
29
 
29
30
  def children
30
- items = []
31
- items.push(self)
32
- items
31
+ [
32
+ self,
33
+ *remark_items
34
+ ]
33
35
  end
34
36
  end
35
37
  end