expressir 0.2.9 → 0.2.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/format +20 -0
- data/expressir.gemspec +1 -0
- data/lib/expressir/express_exp/formatter.rb +146 -105
- data/lib/expressir/express_exp/hyperlink_formatter.rb +25 -0
- data/lib/expressir/express_exp/parser.rb +2 -0
- data/lib/expressir/express_exp/schema_head_formatter.rb +14 -0
- data/lib/expressir/express_exp/visitor.rb +132 -82
- data/lib/expressir/model.rb +2 -1
- data/lib/expressir/model/attribute.rb +5 -1
- data/lib/expressir/model/constant.rb +5 -1
- data/lib/expressir/model/entity.rb +13 -22
- data/lib/expressir/model/enumeration_item.rb +5 -1
- data/lib/expressir/model/expressions/aggregate_initializer.rb +4 -2
- data/lib/expressir/model/expressions/aggregate_item.rb +3 -1
- data/lib/expressir/model/expressions/attribute_reference.rb +3 -1
- data/lib/expressir/model/expressions/binary_expression.rb +3 -1
- data/lib/expressir/model/expressions/call.rb +4 -2
- data/lib/expressir/model/expressions/entity_constructor.rb +4 -2
- data/lib/expressir/model/expressions/group_reference.rb +3 -1
- data/lib/expressir/model/expressions/index_reference.rb +3 -1
- data/lib/expressir/model/expressions/interval.rb +3 -1
- data/lib/expressir/model/expressions/query_expression.rb +5 -2
- data/lib/expressir/model/expressions/simple_reference.rb +3 -1
- data/lib/expressir/model/expressions/unary_expression.rb +3 -1
- data/lib/expressir/model/function.rb +28 -39
- data/lib/expressir/model/identifier.rb +1 -3
- data/lib/expressir/model/informal_proposition.rb +5 -1
- data/lib/expressir/model/interface.rb +4 -2
- data/lib/expressir/model/literals/binary.rb +3 -1
- data/lib/expressir/model/literals/integer.rb +3 -1
- data/lib/expressir/model/literals/logical.rb +3 -1
- data/lib/expressir/model/literals/real.rb +3 -1
- data/lib/expressir/model/literals/string.rb +3 -1
- data/lib/expressir/model/model_element.rb +140 -0
- data/lib/expressir/model/parameter.rb +5 -1
- data/lib/expressir/model/procedure.rb +29 -40
- data/lib/expressir/model/renamed_ref.rb +3 -1
- data/lib/expressir/model/repository.rb +5 -5
- data/lib/expressir/model/rule.rb +32 -43
- data/lib/expressir/model/schema.rb +48 -48
- data/lib/expressir/model/statements/alias.rb +6 -3
- data/lib/expressir/model/statements/assignment.rb +3 -1
- data/lib/expressir/model/statements/call.rb +4 -2
- data/lib/expressir/model/statements/case.rb +4 -2
- data/lib/expressir/model/statements/case_action.rb +4 -2
- data/lib/expressir/model/statements/compound.rb +4 -2
- data/lib/expressir/model/statements/escape.rb +1 -1
- data/lib/expressir/model/statements/if.rb +5 -3
- data/lib/expressir/model/statements/null.rb +1 -1
- data/lib/expressir/model/statements/repeat.rb +6 -3
- data/lib/expressir/model/statements/return.rb +3 -1
- data/lib/expressir/model/statements/skip.rb +1 -1
- data/lib/expressir/model/subtype_constraint.rb +5 -2
- data/lib/expressir/model/type.rb +10 -11
- data/lib/expressir/model/types/aggregate.rb +5 -1
- data/lib/expressir/model/types/array.rb +3 -1
- data/lib/expressir/model/types/bag.rb +3 -1
- data/lib/expressir/model/types/binary.rb +3 -1
- data/lib/expressir/model/types/boolean.rb +1 -1
- data/lib/expressir/model/types/enumeration.rb +5 -3
- data/lib/expressir/model/types/generic.rb +5 -1
- data/lib/expressir/model/types/generic_entity.rb +5 -1
- data/lib/expressir/model/types/integer.rb +1 -1
- data/lib/expressir/model/types/list.rb +3 -1
- data/lib/expressir/model/types/logical.rb +1 -1
- data/lib/expressir/model/types/number.rb +1 -1
- data/lib/expressir/model/types/real.rb +3 -1
- data/lib/expressir/model/types/select.rb +5 -3
- data/lib/expressir/model/types/set.rb +3 -1
- data/lib/expressir/model/types/string.rb +3 -1
- data/lib/expressir/model/unique.rb +6 -2
- data/lib/expressir/model/variable.rb +5 -1
- data/lib/expressir/model/where.rb +5 -1
- data/lib/expressir/version.rb +1 -1
- data/original/examples/syntax/hyperlink.exp +8 -0
- data/original/examples/syntax/hyperlink_formatted.exp +19 -0
- data/original/examples/syntax/remark_formatted.exp +0 -5
- data/original/examples/syntax/simple.exp +3 -0
- data/original/examples/syntax/syntax.exp +197 -189
- data/original/examples/syntax/syntax_formatted.exp +362 -800
- 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} +2 -5
- 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} +5 -5
- data/spec/expressir/express_exp/{source_spec.rb → parser/source_spec.rb} +2 -5
- data/spec/expressir/express_exp/{parse_syntax_spec.rb → parser/syntax_spec.rb} +1619 -1582
- data/spec/expressir/express_exp/schema_head_formatter_spec.rb +36 -0
- data/spec/expressir/model/{find_spec.rb → model_element/find_spec.rb} +7 -2
- data/spec/expressir/model/model_element/hash_spec.rb +66 -0
- metadata +34 -12
- data/lib/expressir/model/scope.rb +0 -66
- data/spec/expressir/express_exp/ap233_spec.rb +0 -22
@@ -1,10 +1,14 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
|
-
class InformalProposition
|
3
|
+
class InformalProposition < ModelElement
|
4
4
|
include Identifier
|
5
5
|
|
6
6
|
def initialize(options = {})
|
7
7
|
@id = options[:id]
|
8
|
+
@remarks = options.fetch(:remarks, [])
|
9
|
+
@source = options[:source]
|
10
|
+
|
11
|
+
super
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
|
-
class Interface
|
3
|
+
class Interface < ModelElement
|
4
4
|
USE = :USE
|
5
5
|
REFERENCE = :REFERENCE
|
6
6
|
|
@@ -11,7 +11,9 @@ module Expressir
|
|
11
11
|
def initialize(options = {})
|
12
12
|
@kind = options[:kind]
|
13
13
|
@schema = options[:schema]
|
14
|
-
@items = options
|
14
|
+
@items = options.fetch(:items, [])
|
15
|
+
|
16
|
+
super
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
3
|
module Literals
|
4
|
-
class Logical
|
4
|
+
class Logical < ModelElement
|
5
5
|
TRUE = :TRUE
|
6
6
|
FALSE = :FALSE
|
7
7
|
UNKNOWN = :UNKNOWN
|
@@ -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
|
@@ -1,13 +1,15 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
3
|
module Literals
|
4
|
-
class String
|
4
|
+
class String < ModelElement
|
5
5
|
attr_accessor :value
|
6
6
|
attr_accessor :encoded
|
7
7
|
|
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
|
@@ -0,0 +1,140 @@
|
|
1
|
+
module Expressir
|
2
|
+
module Model
|
3
|
+
class ModelElement
|
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
|
77
|
+
|
78
|
+
def to_hash(options = {})
|
79
|
+
skip_empty = options[:skip_empty]
|
80
|
+
formatter = options[:formatter]
|
81
|
+
|
82
|
+
hash = {}
|
83
|
+
hash[CLASS_KEY] = self.class.name
|
84
|
+
|
85
|
+
instance_variables.select{|x| x != :@parent}.each_with_object(hash) do |variable, result|
|
86
|
+
key = variable.to_s.sub(/^@/, '')
|
87
|
+
value = instance_variable_get(variable)
|
88
|
+
|
89
|
+
# skip empty values (nil, empty array)
|
90
|
+
if !skip_empty or !(value.nil? or (value.is_a? Array and value.count == 0))
|
91
|
+
result[key] = if value.is_a? Array
|
92
|
+
value.map do |value|
|
93
|
+
if value.is_a? ModelElement
|
94
|
+
value.to_hash(options)
|
95
|
+
else
|
96
|
+
value
|
97
|
+
end
|
98
|
+
end
|
99
|
+
elsif value.is_a? ModelElement
|
100
|
+
value.to_hash(options)
|
101
|
+
else
|
102
|
+
value
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
if formatter
|
108
|
+
hash[SOURCE_KEY] = formatter.format(self)
|
109
|
+
end
|
110
|
+
|
111
|
+
hash
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.from_hash(hash)
|
115
|
+
node_class = hash[CLASS_KEY]
|
116
|
+
node_options = hash.select{|x| x != CLASS_KEY}.each_with_object({}) do |(variable, value), result|
|
117
|
+
key = variable.to_sym
|
118
|
+
|
119
|
+
result[key] = if value.is_a? Array
|
120
|
+
value.map do |value|
|
121
|
+
if value.is_a? Hash
|
122
|
+
self.from_hash(value)
|
123
|
+
else
|
124
|
+
value
|
125
|
+
end
|
126
|
+
end
|
127
|
+
elsif value.is_a? Hash
|
128
|
+
self.from_hash(value)
|
129
|
+
else
|
130
|
+
value
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
node = Object.const_get(node_class).new(node_options)
|
135
|
+
|
136
|
+
node
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
|
-
class Parameter
|
3
|
+
class Parameter < ModelElement
|
4
4
|
include Identifier
|
5
5
|
|
6
6
|
attr_accessor :var
|
@@ -8,9 +8,13 @@ module Expressir
|
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
10
|
@id = options[:id]
|
11
|
+
@remarks = options.fetch(:remarks, [])
|
12
|
+
@source = options[:source]
|
11
13
|
|
12
14
|
@var = options[:var]
|
13
15
|
@type = options[:type]
|
16
|
+
|
17
|
+
super
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
@@ -1,58 +1,47 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
|
-
class Procedure
|
4
|
-
include Scope
|
3
|
+
class Procedure < ModelElement
|
5
4
|
include Identifier
|
6
5
|
|
7
6
|
attr_accessor :parameters
|
8
|
-
attr_accessor :
|
7
|
+
attr_accessor :types
|
8
|
+
attr_accessor :entities
|
9
|
+
attr_accessor :subtype_constraints
|
10
|
+
attr_accessor :functions
|
11
|
+
attr_accessor :procedures
|
9
12
|
attr_accessor :constants
|
10
13
|
attr_accessor :variables
|
11
14
|
attr_accessor :statements
|
12
15
|
|
13
16
|
def initialize(options = {})
|
14
17
|
@id = options[:id]
|
15
|
-
|
16
|
-
@
|
17
|
-
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def subtype_constraints
|
32
|
-
@declarations.select{|x| x.instance_of? Expressir::Model::SubtypeConstraint}
|
33
|
-
end
|
34
|
-
|
35
|
-
def functions
|
36
|
-
@declarations.select{|x| x.instance_of? Expressir::Model::Function}
|
37
|
-
end
|
38
|
-
|
39
|
-
def procedures
|
40
|
-
@declarations.select{|x| x.instance_of? Expressir::Model::Procedure}
|
18
|
+
@remarks = options.fetch(:remarks, [])
|
19
|
+
@source = options[:source]
|
20
|
+
|
21
|
+
@parameters = options.fetch(:parameters, [])
|
22
|
+
@types = options.fetch(:types, [])
|
23
|
+
@entities = options.fetch(:entities, [])
|
24
|
+
@subtype_constraints = options.fetch(:subtype_constraints, [])
|
25
|
+
@functions = options.fetch(:functions, [])
|
26
|
+
@procedures = options.fetch(:procedures, [])
|
27
|
+
@constants = options.fetch(:constants, [])
|
28
|
+
@variables = options.fetch(:variables, [])
|
29
|
+
@statements = options.fetch(:statements, [])
|
30
|
+
|
31
|
+
super
|
41
32
|
end
|
42
33
|
|
43
34
|
def children
|
44
35
|
items = []
|
45
|
-
items.push(*@parameters)
|
46
|
-
items.push(*@
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
items.push(*@constants) if @constants
|
55
|
-
items.push(*@variables) if @variables
|
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)
|
56
45
|
items
|
57
46
|
end
|
58
47
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
|
-
class Repository
|
4
|
-
include Scope
|
5
|
-
|
3
|
+
class Repository < ModelElement
|
6
4
|
attr_accessor :schemas
|
7
5
|
|
8
6
|
def initialize(options = {})
|
9
|
-
@schemas = options
|
7
|
+
@schemas = options.fetch(:schemas, [])
|
8
|
+
|
9
|
+
super
|
10
10
|
end
|
11
11
|
|
12
12
|
def children
|
13
13
|
items = []
|
14
|
-
items.push(*@schemas)
|
14
|
+
items.push(*@schemas)
|
15
15
|
items
|
16
16
|
end
|
17
17
|
end
|
data/lib/expressir/model/rule.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
|
-
class Rule
|
4
|
-
include Scope
|
3
|
+
class Rule < ModelElement
|
5
4
|
include Identifier
|
6
5
|
|
7
6
|
attr_accessor :applies_to
|
8
|
-
attr_accessor :
|
7
|
+
attr_accessor :types
|
8
|
+
attr_accessor :entities
|
9
|
+
attr_accessor :subtype_constraints
|
10
|
+
attr_accessor :functions
|
11
|
+
attr_accessor :procedures
|
9
12
|
attr_accessor :constants
|
10
13
|
attr_accessor :variables
|
11
14
|
attr_accessor :statements
|
@@ -14,50 +17,36 @@ module Expressir
|
|
14
17
|
|
15
18
|
def initialize(options = {})
|
16
19
|
@id = options[:id]
|
17
|
-
|
18
|
-
@
|
19
|
-
|
20
|
-
@
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def subtype_constraints
|
36
|
-
@declarations.select{|x| x.instance_of? Expressir::Model::SubtypeConstraint}
|
37
|
-
end
|
38
|
-
|
39
|
-
def functions
|
40
|
-
@declarations.select{|x| x.instance_of? Expressir::Model::Function}
|
41
|
-
end
|
42
|
-
|
43
|
-
def procedures
|
44
|
-
@declarations.select{|x| x.instance_of? Expressir::Model::Procedure}
|
20
|
+
@remarks = options.fetch(:remarks, [])
|
21
|
+
@source = options[:source]
|
22
|
+
|
23
|
+
@applies_to = options.fetch(:applies_to, [])
|
24
|
+
@types = options.fetch(:types, [])
|
25
|
+
@entities = options.fetch(:entities, [])
|
26
|
+
@subtype_constraints = options.fetch(:subtype_constraints, [])
|
27
|
+
@functions = options.fetch(:functions, [])
|
28
|
+
@procedures = options.fetch(:procedures, [])
|
29
|
+
@constants = options.fetch(:constants, [])
|
30
|
+
@variables = options.fetch(:variables, [])
|
31
|
+
@statements = options.fetch(:statements, [])
|
32
|
+
@where = options.fetch(:where, [])
|
33
|
+
@informal_propositions = options.fetch(:informal_propositions, [])
|
34
|
+
|
35
|
+
super
|
45
36
|
end
|
46
37
|
|
47
38
|
def children
|
48
39
|
items = []
|
49
|
-
items.push(*@
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
items.push(*@
|
58
|
-
items.push(*@
|
59
|
-
items.push(*@where) if @where
|
60
|
-
items.push(*@informal_propositions) if @informal_propositions
|
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)
|
61
50
|
items
|
62
51
|
end
|
63
52
|
end
|