expressir 0.2.10-arm64-darwin → 0.2.15-arm64-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/format +27 -0
- data/expressir.gemspec +1 -0
- data/lib/expressir/express_exp/2.4/express_parser.bundle +0 -0
- data/lib/expressir/express_exp/2.5/express_parser.bundle +0 -0
- data/lib/expressir/express_exp/2.6/express_parser.bundle +0 -0
- data/lib/expressir/express_exp/2.7/express_parser.bundle +0 -0
- data/lib/expressir/express_exp/3.0/express_parser.bundle +0 -0
- data/lib/expressir/express_exp/formatter.rb +90 -100
- data/lib/expressir/express_exp/hyperlink_formatter.rb +29 -0
- data/lib/expressir/express_exp/parser.rb +7 -1
- data/lib/expressir/express_exp/schema_head_formatter.rb +14 -0
- data/lib/expressir/express_exp/visitor.rb +68 -80
- data/lib/expressir/model.rb +2 -2
- data/lib/expressir/model/attribute.rb +2 -0
- data/lib/expressir/model/constant.rb +2 -0
- data/lib/expressir/model/entity.rb +3 -2
- data/lib/expressir/model/enumeration_item.rb +2 -0
- data/lib/expressir/model/expressions/aggregate_initializer.rb +2 -0
- data/lib/expressir/model/expressions/aggregate_item.rb +2 -0
- data/lib/expressir/model/expressions/attribute_reference.rb +2 -0
- data/lib/expressir/model/expressions/binary_expression.rb +2 -0
- data/lib/expressir/model/expressions/call.rb +2 -0
- data/lib/expressir/model/expressions/entity_constructor.rb +2 -0
- data/lib/expressir/model/expressions/group_reference.rb +2 -0
- data/lib/expressir/model/expressions/index_reference.rb +2 -0
- data/lib/expressir/model/expressions/interval.rb +2 -0
- data/lib/expressir/model/expressions/query_expression.rb +2 -1
- data/lib/expressir/model/expressions/simple_reference.rb +2 -0
- data/lib/expressir/model/expressions/unary_expression.rb +2 -0
- data/lib/expressir/model/function.rb +3 -8
- data/lib/expressir/model/identifier.rb +0 -1
- data/lib/expressir/model/informal_proposition.rb +2 -0
- data/lib/expressir/model/interface.rb +2 -0
- data/lib/expressir/model/{renamed_ref.rb → interface_item.rb} +4 -2
- data/lib/expressir/model/interfaced_item.rb +23 -0
- data/lib/expressir/model/literals/binary.rb +2 -0
- data/lib/expressir/model/literals/integer.rb +2 -0
- data/lib/expressir/model/literals/logical.rb +2 -0
- data/lib/expressir/model/literals/real.rb +2 -0
- data/lib/expressir/model/literals/string.rb +2 -0
- data/lib/expressir/model/model_element.rb +85 -12
- data/lib/expressir/model/parameter.rb +2 -0
- data/lib/expressir/model/procedure.rb +3 -8
- data/lib/expressir/model/repository.rb +2 -2
- data/lib/expressir/model/rule.rb +4 -9
- data/lib/expressir/model/schema.rb +45 -9
- data/lib/expressir/model/statements/alias.rb +2 -1
- data/lib/expressir/model/statements/assignment.rb +2 -0
- data/lib/expressir/model/statements/call.rb +2 -0
- data/lib/expressir/model/statements/case.rb +2 -0
- data/lib/expressir/model/statements/case_action.rb +2 -0
- data/lib/expressir/model/statements/compound.rb +2 -0
- data/lib/expressir/model/statements/if.rb +2 -0
- data/lib/expressir/model/statements/repeat.rb +2 -1
- data/lib/expressir/model/statements/return.rb +2 -0
- data/lib/expressir/model/subtype_constraint.rb +2 -1
- data/lib/expressir/model/type.rb +3 -6
- data/lib/expressir/model/types/aggregate.rb +2 -0
- data/lib/expressir/model/types/array.rb +2 -0
- data/lib/expressir/model/types/bag.rb +2 -0
- data/lib/expressir/model/types/binary.rb +2 -0
- data/lib/expressir/model/types/enumeration.rb +2 -0
- data/lib/expressir/model/types/generic.rb +2 -0
- data/lib/expressir/model/types/generic_entity.rb +2 -0
- data/lib/expressir/model/types/list.rb +2 -0
- data/lib/expressir/model/types/real.rb +2 -0
- data/lib/expressir/model/types/select.rb +2 -0
- data/lib/expressir/model/types/set.rb +2 -0
- data/lib/expressir/model/types/string.rb +2 -0
- data/lib/expressir/model/unique.rb +2 -0
- data/lib/expressir/model/variable.rb +2 -0
- data/lib/expressir/model/where.rb +2 -0
- data/lib/expressir/version.rb +1 -1
- data/original/examples/syntax/hyperlink.exp +23 -0
- data/original/examples/syntax/hyperlink_formatted.exp +51 -0
- data/original/examples/syntax/syntax.exp +18 -18
- data/original/examples/syntax/syntax_formatted.exp +32 -24
- data/spec/expressir/express_exp/{format_remark_spec.rb → formatter/remark_spec.rb} +2 -2
- data/spec/expressir/express_exp/{format_syntax_spec.rb → formatter/syntax_spec.rb} +2 -2
- data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +24 -0
- data/spec/expressir/express_exp/{head_source_spec.rb → parser/head_source_spec.rb} +1 -1
- data/spec/expressir/express_exp/{parse_multiple_spec.rb → parser/multiple_spec.rb} +6 -1
- data/spec/expressir/express_exp/{parse_remark_spec.rb → parser/remark_spec.rb} +2 -2
- data/spec/expressir/express_exp/{source_spec.rb → parser/source_spec.rb} +1 -1
- data/spec/expressir/express_exp/{parse_syntax_spec.rb → parser/syntax_spec.rb} +98 -60
- data/spec/expressir/express_exp/schema_head_formatter_spec.rb +36 -0
- data/spec/expressir/model/{scope_spec.rb → model_element/find_spec.rb} +7 -2
- data/spec/expressir/model/model_element/hash_spec.rb +66 -0
- metadata +34 -14
- data/lib/expressir/model/scope.rb +0 -63
- data/spec/expressir/express_exp/ap233_spec.rb +0 -22
- data/spec/expressir/model/model_element_spec.rb +0 -59
@@ -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
|
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)
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
|
-
class
|
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
|
@@ -1,16 +1,92 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
3
|
class ModelElement
|
4
|
-
CLASS_KEY = '_class'
|
4
|
+
CLASS_KEY = '_class'
|
5
|
+
SOURCE_KEY = 'source'
|
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
|
5
77
|
|
6
78
|
def to_hash(options = {})
|
7
79
|
skip_empty = options[:skip_empty]
|
80
|
+
formatter = options[:formatter]
|
81
|
+
|
82
|
+
hash = {}
|
83
|
+
hash[CLASS_KEY] = self.class.name
|
8
84
|
|
9
|
-
instance_variables.select{|x| x != :@parent}.each_with_object(
|
85
|
+
instance_variables.select{|x| x != :@parent}.each_with_object(hash) do |variable, result|
|
10
86
|
key = variable.to_s.sub(/^@/, '')
|
11
87
|
value = instance_variable_get(variable)
|
12
88
|
|
13
|
-
# skip
|
89
|
+
# skip empty values (nil, empty array)
|
14
90
|
if !skip_empty or !(value.nil? or (value.is_a? Array and value.count == 0))
|
15
91
|
result[key] = if value.is_a? Array
|
16
92
|
value.map do |value|
|
@@ -27,6 +103,12 @@ module Expressir
|
|
27
103
|
end
|
28
104
|
end
|
29
105
|
end
|
106
|
+
|
107
|
+
if formatter
|
108
|
+
hash[SOURCE_KEY] = formatter.format(self)
|
109
|
+
end
|
110
|
+
|
111
|
+
hash
|
30
112
|
end
|
31
113
|
|
32
114
|
def self.from_hash(hash)
|
@@ -51,15 +133,6 @@ module Expressir
|
|
51
133
|
|
52
134
|
node = Object.const_get(node_class).new(node_options)
|
53
135
|
|
54
|
-
# attach parent
|
55
|
-
if node.class.method_defined? :children
|
56
|
-
node.children.each do |child_node|
|
57
|
-
if child_node.class.method_defined? :parent and !child_node.parent
|
58
|
-
child_node.parent = node
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
136
|
node
|
64
137
|
end
|
65
138
|
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
|
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)
|
data/lib/expressir/model/rule.rb
CHANGED
@@ -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
|
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
|
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,7 +1,8 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
3
|
class Schema < ModelElement
|
4
|
-
|
4
|
+
attr_accessor :file
|
5
|
+
|
5
6
|
include Identifier
|
6
7
|
|
7
8
|
attr_accessor :head_source
|
@@ -17,6 +18,8 @@ module Expressir
|
|
17
18
|
attr_accessor :rules
|
18
19
|
|
19
20
|
def initialize(options = {})
|
21
|
+
@file = options[:file]
|
22
|
+
|
20
23
|
@id = options[:id]
|
21
24
|
@remarks = options.fetch(:remarks, [])
|
22
25
|
@source = options[:source]
|
@@ -31,19 +34,52 @@ module Expressir
|
|
31
34
|
@functions = options.fetch(:functions, [])
|
32
35
|
@procedures = options.fetch(:procedures, [])
|
33
36
|
@rules = options.fetch(:rules, [])
|
37
|
+
|
38
|
+
super
|
34
39
|
end
|
35
40
|
|
36
|
-
def children
|
41
|
+
def children(skip_references = false)
|
37
42
|
items = []
|
43
|
+
unless skip_references
|
44
|
+
items.push(*@interfaces.flat_map do |interface|
|
45
|
+
schema_id = interface.schema.id.downcase
|
46
|
+
schema = parent.schemas.find{|x| x.id.downcase == schema_id}
|
47
|
+
if schema
|
48
|
+
schema_children = schema.children(true) # prevent infinite recursion
|
49
|
+
if interface.items.length > 0
|
50
|
+
interface.items.map do |item|
|
51
|
+
ref_id = item.ref.id.downcase
|
52
|
+
id = item.id || ref_id
|
53
|
+
base_item = schema_children.find{|x| x.id and x.id.downcase == ref_id}
|
54
|
+
|
55
|
+
interfaced_item = InterfacedItem.new({
|
56
|
+
id: id
|
57
|
+
})
|
58
|
+
interfaced_item.base_item = base_item # skip overriding parent
|
59
|
+
interfaced_item.parent = self
|
60
|
+
interfaced_item
|
61
|
+
end
|
62
|
+
else
|
63
|
+
schema_children.map do |item|
|
64
|
+
id = item.id
|
65
|
+
base_item = item
|
66
|
+
|
67
|
+
interfaced_item = InterfacedItem.new({
|
68
|
+
id: id
|
69
|
+
})
|
70
|
+
interfaced_item.base_item = base_item # skip overriding parent
|
71
|
+
interfaced_item.parent = self
|
72
|
+
interfaced_item
|
73
|
+
end
|
74
|
+
end
|
75
|
+
else
|
76
|
+
[]
|
77
|
+
end
|
78
|
+
end)
|
79
|
+
end
|
38
80
|
items.push(*@constants)
|
39
81
|
items.push(*@types)
|
40
|
-
items.push(*@types.flat_map
|
41
|
-
if x.type.instance_of? Expressir::Model::Types::Enumeration
|
42
|
-
x.type.items
|
43
|
-
else
|
44
|
-
[]
|
45
|
-
end
|
46
|
-
end)
|
82
|
+
items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
|
47
83
|
items.push(*@entities)
|
48
84
|
items.push(*@subtype_constraints)
|
49
85
|
items.push(*@functions)
|