expressir 0.2.11-x64-mingw32 → 0.2.16-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/exe/format +27 -0
  3. data/expressir.gemspec +1 -0
  4. data/lib/expressir/express_exp/2.4/express_parser.so +0 -0
  5. data/lib/expressir/express_exp/2.5/express_parser.so +0 -0
  6. data/lib/expressir/express_exp/2.6/express_parser.so +0 -0
  7. data/lib/expressir/express_exp/2.7/express_parser.so +0 -0
  8. data/lib/expressir/express_exp/3.0/express_parser.so +0 -0
  9. data/lib/expressir/express_exp/formatter.rb +90 -100
  10. data/lib/expressir/express_exp/hyperlink_formatter.rb +27 -0
  11. data/lib/expressir/express_exp/parser.rb +7 -1
  12. data/lib/expressir/express_exp/schema_head_formatter.rb +12 -0
  13. data/lib/expressir/express_exp/visitor.rb +67 -99
  14. data/lib/expressir/model.rb +2 -2
  15. data/lib/expressir/model/attribute.rb +2 -0
  16. data/lib/expressir/model/constant.rb +2 -0
  17. data/lib/expressir/model/entity.rb +3 -2
  18. data/lib/expressir/model/enumeration_item.rb +2 -0
  19. data/lib/expressir/model/expressions/aggregate_initializer.rb +2 -0
  20. data/lib/expressir/model/expressions/aggregate_item.rb +2 -0
  21. data/lib/expressir/model/expressions/attribute_reference.rb +2 -0
  22. data/lib/expressir/model/expressions/binary_expression.rb +2 -0
  23. data/lib/expressir/model/expressions/call.rb +2 -0
  24. data/lib/expressir/model/expressions/entity_constructor.rb +2 -0
  25. data/lib/expressir/model/expressions/group_reference.rb +2 -0
  26. data/lib/expressir/model/expressions/index_reference.rb +2 -0
  27. data/lib/expressir/model/expressions/interval.rb +2 -0
  28. data/lib/expressir/model/expressions/query_expression.rb +2 -1
  29. data/lib/expressir/model/expressions/simple_reference.rb +2 -0
  30. data/lib/expressir/model/expressions/unary_expression.rb +2 -0
  31. data/lib/expressir/model/function.rb +3 -8
  32. data/lib/expressir/model/identifier.rb +0 -1
  33. data/lib/expressir/model/informal_proposition.rb +2 -0
  34. data/lib/expressir/model/interface.rb +2 -0
  35. data/lib/expressir/model/{renamed_ref.rb → interface_item.rb} +4 -2
  36. data/lib/expressir/model/interfaced_item.rb +23 -0
  37. data/lib/expressir/model/literals/binary.rb +2 -0
  38. data/lib/expressir/model/literals/integer.rb +2 -0
  39. data/lib/expressir/model/literals/logical.rb +2 -0
  40. data/lib/expressir/model/literals/real.rb +2 -0
  41. data/lib/expressir/model/literals/string.rb +2 -0
  42. data/lib/expressir/model/model_element.rb +71 -4
  43. data/lib/expressir/model/parameter.rb +2 -0
  44. data/lib/expressir/model/procedure.rb +3 -8
  45. data/lib/expressir/model/repository.rb +2 -2
  46. data/lib/expressir/model/rule.rb +4 -9
  47. data/lib/expressir/model/schema.rb +45 -12
  48. data/lib/expressir/model/statements/alias.rb +2 -1
  49. data/lib/expressir/model/statements/assignment.rb +2 -0
  50. data/lib/expressir/model/statements/call.rb +2 -0
  51. data/lib/expressir/model/statements/case.rb +2 -0
  52. data/lib/expressir/model/statements/case_action.rb +2 -0
  53. data/lib/expressir/model/statements/compound.rb +2 -0
  54. data/lib/expressir/model/statements/if.rb +2 -0
  55. data/lib/expressir/model/statements/repeat.rb +2 -1
  56. data/lib/expressir/model/statements/return.rb +2 -0
  57. data/lib/expressir/model/subtype_constraint.rb +2 -1
  58. data/lib/expressir/model/type.rb +3 -6
  59. data/lib/expressir/model/types/aggregate.rb +2 -0
  60. data/lib/expressir/model/types/array.rb +2 -0
  61. data/lib/expressir/model/types/bag.rb +2 -0
  62. data/lib/expressir/model/types/binary.rb +2 -0
  63. data/lib/expressir/model/types/enumeration.rb +2 -0
  64. data/lib/expressir/model/types/generic.rb +2 -0
  65. data/lib/expressir/model/types/generic_entity.rb +2 -0
  66. data/lib/expressir/model/types/list.rb +2 -0
  67. data/lib/expressir/model/types/real.rb +2 -0
  68. data/lib/expressir/model/types/select.rb +2 -0
  69. data/lib/expressir/model/types/set.rb +2 -0
  70. data/lib/expressir/model/types/string.rb +2 -0
  71. data/lib/expressir/model/unique.rb +2 -0
  72. data/lib/expressir/model/variable.rb +2 -0
  73. data/lib/expressir/model/where.rb +2 -0
  74. data/lib/expressir/version.rb +1 -1
  75. data/original/examples/syntax/hyperlink.exp +23 -0
  76. data/original/examples/syntax/hyperlink_formatted.exp +51 -0
  77. data/original/examples/syntax/syntax.exp +18 -18
  78. data/original/examples/syntax/syntax_formatted.exp +32 -24
  79. data/spec/expressir/express_exp/{format_remark_spec.rb → formatter/remark_spec.rb} +2 -2
  80. data/spec/expressir/express_exp/{format_syntax_spec.rb → formatter/syntax_spec.rb} +2 -2
  81. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +28 -0
  82. data/spec/expressir/express_exp/{parse_multiple_spec.rb → parser/multiple_spec.rb} +6 -1
  83. data/spec/expressir/express_exp/{parse_remark_spec.rb → parser/remark_spec.rb} +2 -2
  84. data/spec/expressir/express_exp/{source_spec.rb → parser/source_spec.rb} +1 -1
  85. data/spec/expressir/express_exp/{parse_syntax_spec.rb → parser/syntax_spec.rb} +98 -60
  86. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +40 -0
  87. data/spec/expressir/model/{scope_spec.rb → model_element/find_spec.rb} +7 -2
  88. data/spec/expressir/model/{model_element_spec.rb → model_element/hash_spec.rb} +7 -18
  89. metadata +33 -14
  90. data/lib/expressir/model/scope.rb +0 -71
  91. data/spec/expressir/express_exp/ap233_spec.rb +0 -22
  92. data/spec/expressir/express_exp/head_source_spec.rb +0 -38
@@ -14,6 +14,8 @@ module Expressir
14
14
  @item = options[:item]
15
15
  @operator2 = options[:operator2]
16
16
  @high = options[:high]
17
+
18
+ super
17
19
  end
18
20
  end
19
21
  end
@@ -2,7 +2,6 @@ module Expressir
2
2
  module Model
3
3
  module Expressions
4
4
  class QueryExpression < ModelElement
5
- include Scope
6
5
  include Identifier
7
6
 
8
7
  attr_accessor :aggregate_source
@@ -15,6 +14,8 @@ module Expressir
15
14
 
16
15
  @aggregate_source = options[:aggregate_source]
17
16
  @expression = options[:expression]
17
+
18
+ super
18
19
  end
19
20
 
20
21
  def children
@@ -6,6 +6,8 @@ module Expressir
6
6
 
7
7
  def initialize(options = {})
8
8
  @id = options[:id]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -12,6 +12,8 @@ module Expressir
12
12
  def initialize(options = {})
13
13
  @operator = options[:operator]
14
14
  @operand = options[:operand]
15
+
16
+ super
15
17
  end
16
18
  end
17
19
  end
@@ -1,7 +1,6 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Function < ModelElement
4
- include Scope
5
4
  include Identifier
6
5
 
7
6
  attr_accessor :parameters
@@ -30,19 +29,15 @@ module Expressir
30
29
  @constants = options.fetch(:constants, [])
31
30
  @variables = options.fetch(:variables, [])
32
31
  @statements = options.fetch(:statements, [])
32
+
33
+ super
33
34
  end
34
35
 
35
36
  def children
36
37
  items = []
37
38
  items.push(*@parameters)
38
39
  items.push(*@types)
39
- items.push(*@types.flat_map do |x|
40
- if x.type.instance_of? Expressir::Model::Types::Enumeration
41
- x.type.items
42
- else
43
- []
44
- end
45
- end)
40
+ items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
46
41
  items.push(*@entities)
47
42
  items.push(*@subtype_constraints)
48
43
  items.push(*@functions)
@@ -2,7 +2,6 @@ module Expressir
2
2
  module Model
3
3
  module Identifier
4
4
  attr_accessor :id
5
- attr_accessor :parent
6
5
  attr_accessor :remarks
7
6
  attr_accessor :source
8
7
  end
@@ -7,6 +7,8 @@ module Expressir
7
7
  @id = options[:id]
8
8
  @remarks = options.fetch(:remarks, [])
9
9
  @source = options[:source]
10
+
11
+ super
10
12
  end
11
13
  end
12
14
  end
@@ -12,6 +12,8 @@ module Expressir
12
12
  @kind = options[:kind]
13
13
  @schema = options[:schema]
14
14
  @items = options.fetch(:items, [])
15
+
16
+ super
15
17
  end
16
18
  end
17
19
  end
@@ -1,12 +1,14 @@
1
1
  module Expressir
2
2
  module Model
3
- class RenamedRef < ModelElement
3
+ class InterfaceItem < ModelElement
4
4
  attr_accessor :ref
5
5
  attr_accessor :id
6
6
 
7
7
  def initialize(options = {})
8
- @ref = options[:ref]
8
+ @ref = options[:ref]
9
9
  @id = options[:id]
10
+
11
+ super
10
12
  end
11
13
  end
12
14
  end
@@ -0,0 +1,23 @@
1
+ module Expressir
2
+ module Model
3
+ class InterfacedItem < ModelElement
4
+ include Identifier
5
+
6
+ attr_accessor :base_item
7
+
8
+ def initialize(options = {})
9
+ @id = options[:id]
10
+ @remarks = options.fetch(:remarks, [])
11
+ @source = options[:source]
12
+
13
+ @base_item = options[:base_item]
14
+
15
+ super
16
+ end
17
+
18
+ def path
19
+ base_item.path
20
+ end
21
+ end
22
+ end
23
+ end
@@ -6,6 +6,8 @@ module Expressir
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -6,6 +6,8 @@ module Expressir
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -10,6 +10,8 @@ module Expressir
10
10
 
11
11
  def initialize(options = {})
12
12
  @value = options[:value]
13
+
14
+ super
13
15
  end
14
16
  end
15
17
  end
@@ -6,6 +6,8 @@ module Expressir
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -8,6 +8,8 @@ module Expressir
8
8
  def initialize(options = {})
9
9
  @value = options[:value]
10
10
  @encoded = options[:encoded]
11
+
12
+ super
11
13
  end
12
14
  end
13
15
  end
@@ -4,6 +4,77 @@ module Expressir
4
4
  CLASS_KEY = '_class'
5
5
  SOURCE_KEY = 'source'
6
6
 
7
+ attr_accessor :parent
8
+
9
+ def initialize(options = {})
10
+ attach_parent_to_children
11
+ end
12
+
13
+ def path
14
+ return id if is_a? Statements::Alias or is_a? Statements::Repeat or is_a? Expressions::QueryExpression
15
+
16
+ current_node = self
17
+ path_parts = []
18
+ loop do
19
+ if current_node.class.method_defined? :id
20
+ path_parts << current_node.id
21
+ end
22
+
23
+ current_node = current_node.parent
24
+ break unless current_node
25
+ end
26
+
27
+ path_parts.reverse.join(".")
28
+ end
29
+
30
+ def attach_parent_to_children
31
+ instance_variables.select{|x| x != :@parent}.each do |variable|
32
+ value = instance_variable_get(variable)
33
+
34
+ if value.is_a? Array
35
+ value.each do |value|
36
+ if value.is_a? ModelElement
37
+ value.parent = self
38
+ end
39
+ end
40
+ elsif value.is_a? ModelElement
41
+ value.parent = self
42
+ end
43
+ end
44
+ end
45
+
46
+ def find(path)
47
+ return self if path.empty?
48
+
49
+ path_parts = path.downcase.split(/\./).map do |current_path|
50
+ _, _, current_path = current_path.rpartition(":") # ignore prefix
51
+ current_path
52
+ end
53
+
54
+ current_scope = self
55
+ target_node = nil
56
+ loop do
57
+ # find in current scope
58
+ current_node = current_scope
59
+ path_parts.each do |current_path|
60
+ current_node = current_node.children.find{|x| x.id and x.id.downcase == current_path}
61
+ break unless current_node
62
+ end
63
+ target_node = current_node
64
+ break if target_node
65
+
66
+ # retry search in parent scope
67
+ current_scope = current_scope.parent
68
+ break unless current_scope
69
+ end
70
+
71
+ target_node
72
+ end
73
+
74
+ def children
75
+ []
76
+ end
77
+
7
78
  def to_hash(options = {})
8
79
  skip_empty = options[:skip_empty]
9
80
  formatter = options[:formatter]
@@ -62,10 +133,6 @@ module Expressir
62
133
 
63
134
  node = Object.const_get(node_class).new(node_options)
64
135
 
65
- if node.class.method_defined? :attach_parent_to_children
66
- node.attach_parent_to_children
67
- end
68
-
69
136
  node
70
137
  end
71
138
  end
@@ -13,6 +13,8 @@ module Expressir
13
13
 
14
14
  @var = options[:var]
15
15
  @type = options[:type]
16
+
17
+ super
16
18
  end
17
19
  end
18
20
  end
@@ -1,7 +1,6 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Procedure < ModelElement
4
- include Scope
5
4
  include Identifier
6
5
 
7
6
  attr_accessor :parameters
@@ -28,19 +27,15 @@ module Expressir
28
27
  @constants = options.fetch(:constants, [])
29
28
  @variables = options.fetch(:variables, [])
30
29
  @statements = options.fetch(:statements, [])
30
+
31
+ super
31
32
  end
32
33
 
33
34
  def children
34
35
  items = []
35
36
  items.push(*@parameters)
36
37
  items.push(*@types)
37
- items.push(*@types.flat_map do |x|
38
- if x.type.instance_of? Expressir::Model::Types::Enumeration
39
- x.type.items
40
- else
41
- []
42
- end
43
- end)
38
+ items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
44
39
  items.push(*@entities)
45
40
  items.push(*@subtype_constraints)
46
41
  items.push(*@functions)
@@ -1,12 +1,12 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Repository < ModelElement
4
- include Scope
5
-
6
4
  attr_accessor :schemas
7
5
 
8
6
  def initialize(options = {})
9
7
  @schemas = options.fetch(:schemas, [])
8
+
9
+ super
10
10
  end
11
11
 
12
12
  def children
@@ -1,7 +1,6 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Rule < ModelElement
4
- include Scope
5
4
  include Identifier
6
5
 
7
6
  attr_accessor :applies_to
@@ -21,7 +20,7 @@ module Expressir
21
20
  @remarks = options.fetch(:remarks, [])
22
21
  @source = options[:source]
23
22
 
24
- @applies_to = options[:applies_to]
23
+ @applies_to = options.fetch(:applies_to, [])
25
24
  @types = options.fetch(:types, [])
26
25
  @entities = options.fetch(:entities, [])
27
26
  @subtype_constraints = options.fetch(:subtype_constraints, [])
@@ -32,18 +31,14 @@ module Expressir
32
31
  @statements = options.fetch(:statements, [])
33
32
  @where = options.fetch(:where, [])
34
33
  @informal_propositions = options.fetch(:informal_propositions, [])
34
+
35
+ super
35
36
  end
36
37
 
37
38
  def children
38
39
  items = []
39
40
  items.push(*@types)
40
- items.push(*@types.flat_map do |x|
41
- if x.type.instance_of? Expressir::Model::Types::Enumeration
42
- x.type.items
43
- else
44
- []
45
- end
46
- end)
41
+ items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
47
42
  items.push(*@entities)
48
43
  items.push(*@subtype_constraints)
49
44
  items.push(*@functions)
@@ -1,10 +1,9 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Schema < ModelElement
4
- include Scope
5
- include Identifier
4
+ attr_accessor :file
6
5
 
7
- attr_accessor :head_source
6
+ include Identifier
8
7
 
9
8
  attr_accessor :version
10
9
  attr_accessor :interfaces
@@ -17,10 +16,11 @@ module Expressir
17
16
  attr_accessor :rules
18
17
 
19
18
  def initialize(options = {})
19
+ @file = options[:file]
20
+
20
21
  @id = options[:id]
21
22
  @remarks = options.fetch(:remarks, [])
22
23
  @source = options[:source]
23
- @head_source = options[:head_source]
24
24
 
25
25
  @version = options[:version]
26
26
  @interfaces = options.fetch(:interfaces, [])
@@ -31,19 +31,52 @@ module Expressir
31
31
  @functions = options.fetch(:functions, [])
32
32
  @procedures = options.fetch(:procedures, [])
33
33
  @rules = options.fetch(:rules, [])
34
+
35
+ super
34
36
  end
35
37
 
36
- def children
38
+ def children(skip_references = false)
37
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
63
+
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
70
+ end
71
+ end
72
+ else
73
+ []
74
+ end
75
+ end)
76
+ end
38
77
  items.push(*@constants)
39
78
  items.push(*@types)
40
- items.push(*@types.flat_map do |x|
41
- if x.type.instance_of? Expressir::Model::Types::Enumeration
42
- x.type.items
43
- else
44
- []
45
- end
46
- end)
79
+ items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
47
80
  items.push(*@entities)
48
81
  items.push(*@subtype_constraints)
49
82
  items.push(*@functions)