expressir 0.2.16 → 0.2.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +5 -0
- data/.github/workflows/release.yml +31 -3
- data/README.adoc +3 -3
- data/exe/format +66 -12
- data/ext/express-parser/extconf.rb +2 -0
- data/lib/expressir/express_exp/cache.rb +48 -0
- data/lib/expressir/express_exp/formatter.rb +185 -135
- data/lib/expressir/express_exp/parser.rb +33 -29
- data/lib/expressir/express_exp/schema_head_formatter.rb +1 -4
- data/lib/expressir/express_exp/visitor.rb +29 -23
- data/lib/expressir/model.rb +3 -1
- data/lib/expressir/model/attribute.rb +12 -5
- data/lib/expressir/model/cache.rb +13 -0
- data/lib/expressir/model/constant.rb +9 -2
- data/lib/expressir/model/entity.rb +15 -13
- data/lib/expressir/model/enumeration_item.rb +7 -0
- data/lib/expressir/model/expressions/aggregate_initializer.rb +1 -1
- data/lib/expressir/model/expressions/aggregate_item.rb +2 -2
- data/lib/expressir/model/expressions/attribute_reference.rb +2 -2
- data/lib/expressir/model/expressions/binary_expression.rb +3 -3
- data/lib/expressir/model/expressions/call.rb +2 -2
- data/lib/expressir/model/expressions/entity_constructor.rb +2 -2
- data/lib/expressir/model/expressions/group_reference.rb +2 -2
- data/lib/expressir/model/expressions/index_reference.rb +3 -3
- data/lib/expressir/model/expressions/interval.rb +5 -5
- data/lib/expressir/model/expressions/query_expression.rb +7 -5
- data/lib/expressir/model/expressions/simple_reference.rb +1 -1
- data/lib/expressir/model/expressions/unary_expression.rb +2 -2
- data/lib/expressir/model/function.rb +27 -21
- data/lib/expressir/model/identifier.rb +6 -3
- data/lib/expressir/model/interface.rb +3 -3
- data/lib/expressir/model/interface_item.rb +2 -2
- data/lib/expressir/model/interfaced_item.rb +11 -3
- data/lib/expressir/model/literals/binary.rb +1 -1
- data/lib/expressir/model/literals/integer.rb +1 -1
- data/lib/expressir/model/literals/logical.rb +1 -1
- data/lib/expressir/model/literals/real.rb +1 -1
- data/lib/expressir/model/literals/string.rb +2 -2
- data/lib/expressir/model/model_element.rb +54 -19
- data/lib/expressir/model/parameter.rb +9 -2
- data/lib/expressir/model/procedure.rb +26 -20
- data/lib/expressir/model/{informal_proposition.rb → remark_item.rb} +3 -3
- data/lib/expressir/model/repository.rb +4 -4
- data/lib/expressir/model/rule.rb +29 -23
- data/lib/expressir/model/schema.rb +63 -54
- data/lib/expressir/model/statements/alias.rb +7 -5
- data/lib/expressir/model/statements/assignment.rb +2 -2
- data/lib/expressir/model/statements/call.rb +2 -2
- data/lib/expressir/model/statements/case.rb +3 -3
- data/lib/expressir/model/statements/case_action.rb +2 -2
- data/lib/expressir/model/statements/compound.rb +1 -1
- data/lib/expressir/model/statements/if.rb +3 -3
- data/lib/expressir/model/statements/repeat.rb +11 -9
- data/lib/expressir/model/statements/return.rb +1 -1
- data/lib/expressir/model/subtype_constraint.rb +9 -7
- data/lib/expressir/model/type.rb +14 -8
- data/lib/expressir/model/types/aggregate.rb +8 -1
- data/lib/expressir/model/types/array.rb +5 -5
- data/lib/expressir/model/types/bag.rb +3 -3
- data/lib/expressir/model/types/binary.rb +2 -2
- data/lib/expressir/model/types/enumeration.rb +4 -4
- data/lib/expressir/model/types/generic.rb +7 -0
- data/lib/expressir/model/types/generic_entity.rb +7 -0
- data/lib/expressir/model/types/list.rb +4 -4
- data/lib/expressir/model/types/real.rb +1 -1
- data/lib/expressir/model/types/select.rb +5 -5
- data/lib/expressir/model/types/set.rb +3 -3
- data/lib/expressir/model/types/string.rb +2 -2
- data/lib/expressir/model/unique.rb +8 -1
- data/lib/expressir/model/variable.rb +9 -2
- data/lib/expressir/model/where.rb +8 -1
- data/lib/expressir/version.rb +1 -1
- data/original/examples/syntax/{hyperlink.exp → multiple.exp} +8 -8
- data/original/examples/syntax/multiple.yaml +184 -0
- data/original/examples/syntax/multiple_formatted.exp +71 -0
- data/original/examples/syntax/multiple_hyperlink_formatted.exp +71 -0
- data/original/examples/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
- data/original/examples/syntax/remark.exp +52 -50
- data/original/examples/syntax/remark.yaml +452 -0
- data/original/examples/syntax/remark_formatted.exp +64 -50
- data/original/examples/syntax/{simple.exp → single.exp} +1 -1
- data/original/examples/syntax/single.yaml +9 -0
- data/original/examples/syntax/single_formatted.exp +6 -0
- data/original/examples/syntax/single_formatted.yaml +19 -0
- data/original/examples/syntax/syntax.exp +29 -19
- data/original/examples/syntax/syntax.yaml +3439 -0
- data/original/examples/syntax/syntax_formatted.exp +271 -131
- data/original/examples/syntax/syntax_schema_head_formatted.exp +18 -0
- data/spec/expressir/express_exp/cache_spec.rb +64 -0
- data/spec/expressir/express_exp/formatter_spec.rb +111 -0
- data/spec/expressir/express_exp/parser_spec.rb +98 -0
- data/spec/expressir/model/{model_element/find_spec.rb → model_element_spec.rb} +96 -10
- metadata +21 -17
- data/original/examples/syntax/hyperlink_formatted.exp +0 -51
- data/original/examples/syntax/source.exp +0 -16
- data/spec/expressir/express_exp/formatter/remark_spec.rb +0 -28
- data/spec/expressir/express_exp/formatter/syntax_spec.rb +0 -28
- data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +0 -28
- data/spec/expressir/express_exp/parser/multiple_spec.rb +0 -37
- data/spec/expressir/express_exp/parser/remark_spec.rb +0 -411
- data/spec/expressir/express_exp/parser/source_spec.rb +0 -29
- data/spec/expressir/express_exp/parser/syntax_spec.rb +0 -3086
- data/spec/expressir/express_exp/schema_head_formatter_spec.rb +0 -40
- data/spec/expressir/model/model_element/hash_spec.rb +0 -66
@@ -6,54 +6,58 @@ rescue LoadError
|
|
6
6
|
end
|
7
7
|
require 'expressir/express_exp/visitor'
|
8
8
|
|
9
|
-
module Expressir
|
10
|
-
module ExpressExp
|
11
|
-
class Parser
|
12
|
-
def self.from_file(file)
|
13
|
-
input = File.read(file)
|
14
|
-
|
15
9
|
=begin
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
|
11
|
+
lexer = ::ExpressParser::Lexer.new(char_stream)
|
12
|
+
token_stream = Antlr4::Runtime::CommonTokenStream.new(lexer)
|
13
|
+
parser = ::ExpressParser::Parser.new(token_stream)
|
20
14
|
|
21
|
-
|
22
|
-
|
15
|
+
# don't attempt to recover from any parsing error
|
16
|
+
parser.instance_variable_set(:@_err_handler, Antlr4::Runtime::BailErrorStrategy.new)
|
23
17
|
|
24
|
-
|
18
|
+
parse_tree = parser.syntax()
|
25
19
|
|
26
|
-
|
27
|
-
|
20
|
+
visitor = Visitor.new(token_stream)
|
21
|
+
repo = visitor.visit(parse_tree)
|
28
22
|
=end
|
29
23
|
|
24
|
+
module Expressir
|
25
|
+
module ExpressExp
|
26
|
+
class Parser
|
27
|
+
def self.from_file(file, options = {})
|
28
|
+
input = File.read(file)
|
29
|
+
|
30
30
|
parser = ::ExpressParser::Parser.parse(input)
|
31
31
|
|
32
32
|
parse_tree = parser.syntax()
|
33
33
|
|
34
|
-
visitor = Visitor.new(parser.tokens)
|
35
|
-
|
34
|
+
visitor = Visitor.new(parser.tokens, options)
|
35
|
+
repository = visitor.visit(parse_tree)
|
36
36
|
|
37
|
-
|
37
|
+
repository.schemas.each do |schema|
|
38
|
+
schema.file = file.to_s
|
39
|
+
end
|
38
40
|
|
39
|
-
|
41
|
+
repository
|
40
42
|
end
|
41
43
|
|
42
|
-
def self.from_files(files)
|
43
|
-
schemas = files.map
|
44
|
+
def self.from_files(files, options = {})
|
45
|
+
schemas = files.each_with_index.map do |file, i|
|
46
|
+
# start = Time.now
|
47
|
+
repository = self.from_file(file, options)
|
48
|
+
# STDERR.puts "#{i+1}/#{files.length} #{file} #{Time.now - start}"
|
49
|
+
repository.schemas
|
50
|
+
end.flatten
|
44
51
|
|
45
|
-
|
52
|
+
repository = Model::Repository.new({
|
46
53
|
schemas: schemas
|
47
54
|
})
|
48
55
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
56
|
+
repository.schemas.each do |schema|
|
57
|
+
schema.parent = repository
|
58
|
+
end
|
53
59
|
|
54
|
-
|
55
|
-
def self.from_exp(file)
|
56
|
-
self.from_file(file)
|
60
|
+
repository
|
57
61
|
end
|
58
62
|
end
|
59
63
|
end
|
@@ -2,10 +2,7 @@ module Expressir
|
|
2
2
|
module ExpressExp
|
3
3
|
module SchemaHeadFormatter
|
4
4
|
def format_schema(node)
|
5
|
-
|
6
|
-
"SCHEMA #{node.id}#{node.version ? " #{format(node.version)}" : ""};",
|
7
|
-
*node.interfaces.map{|x| format(x)}
|
8
|
-
].join("\n")
|
5
|
+
format_schema_head(node)
|
9
6
|
end
|
10
7
|
end
|
11
8
|
end
|
@@ -36,8 +36,10 @@ module Expressir
|
|
36
36
|
class Visitor < ::ExpressParser::Visitor
|
37
37
|
REMARK_CHANNEL = 2
|
38
38
|
|
39
|
-
def initialize(tokens)
|
39
|
+
def initialize(tokens, options = {})
|
40
40
|
@tokens = tokens
|
41
|
+
@include_source = options[:include_source]
|
42
|
+
|
41
43
|
@attached_remark_tokens = ::Set.new
|
42
44
|
|
43
45
|
super()
|
@@ -45,7 +47,9 @@ module Expressir
|
|
45
47
|
|
46
48
|
def visit(ctx)
|
47
49
|
node = super(ctx)
|
48
|
-
|
50
|
+
if @include_source
|
51
|
+
attach_source(ctx, node)
|
52
|
+
end
|
49
53
|
attach_remarks(ctx, node)
|
50
54
|
node
|
51
55
|
end
|
@@ -103,26 +107,28 @@ module Expressir
|
|
103
107
|
target_node = node.find(path)
|
104
108
|
return target_node if target_node
|
105
109
|
|
106
|
-
# check if path
|
107
|
-
# see https://github.com/lutaml/expressir/issues/
|
110
|
+
# check if path can create implicit remark item
|
111
|
+
# see https://github.com/lutaml/expressir/issues/78
|
108
112
|
rest, _, current_path = path.rpartition(".") # get last path part
|
109
113
|
_, _, current_path = current_path.rpartition(":") # ignore prefix
|
114
|
+
parent_node = node.find(rest)
|
115
|
+
if parent_node and parent_node.class.method_defined? :remark_items
|
116
|
+
remark_item = Model::RemarkItem.new({
|
117
|
+
id: current_path
|
118
|
+
})
|
119
|
+
remark_item.parent = parent_node
|
110
120
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
})
|
123
|
-
target_node.informal_propositions << informal_proposition
|
124
|
-
informal_proposition.parent = target_node
|
125
|
-
informal_proposition
|
121
|
+
# check if path can create implicit informal proposition
|
122
|
+
# see https://github.com/lutaml/expressir/issues/50
|
123
|
+
if parent_node.class.method_defined? :informal_propositions and current_path.match(/^IP\d+$/)
|
124
|
+
parent_node.informal_propositions << remark_item
|
125
|
+
else
|
126
|
+
parent_node.remark_items << remark_item
|
127
|
+
end
|
128
|
+
parent_node.reset_children_by_id
|
129
|
+
|
130
|
+
remark_item
|
131
|
+
end
|
126
132
|
end
|
127
133
|
|
128
134
|
def attach_remarks(ctx, node)
|
@@ -1925,8 +1931,8 @@ module Expressir
|
|
1925
1931
|
entities = declarations.select{|x| x.is_a? Model::Entity}
|
1926
1932
|
subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
|
1927
1933
|
functions = declarations.select{|x| x.is_a? Model::Function}
|
1928
|
-
procedures = declarations.select{|x| x.is_a? Model::Procedure}
|
1929
1934
|
rules = declarations.select{|x| x.is_a? Model::Rule}
|
1935
|
+
procedures = declarations.select{|x| x.is_a? Model::Procedure}
|
1930
1936
|
|
1931
1937
|
Model::Schema.new({
|
1932
1938
|
id: id,
|
@@ -1937,8 +1943,8 @@ module Expressir
|
|
1937
1943
|
entities: entities,
|
1938
1944
|
subtype_constraints: subtype_constraints,
|
1939
1945
|
functions: functions,
|
1940
|
-
|
1941
|
-
|
1946
|
+
rules: rules,
|
1947
|
+
procedures: procedures
|
1942
1948
|
})
|
1943
1949
|
end
|
1944
1950
|
|
@@ -2149,7 +2155,7 @@ module Expressir
|
|
2149
2155
|
id = visit_if(ctx__subtype_constraint_head__subtype_constraint_id)
|
2150
2156
|
applies_to = visit_if(ctx__subtype_constraint_head__entity_ref)
|
2151
2157
|
abstract = ctx__subtype_constraint_body__abstract_supertype && true
|
2152
|
-
total_over = visit_if(ctx__subtype_constraint_body__total_over)
|
2158
|
+
total_over = visit_if(ctx__subtype_constraint_body__total_over, [])
|
2153
2159
|
supertype_expression = visit_if(ctx__subtype_constraint_body__supertype_expression)
|
2154
2160
|
|
2155
2161
|
Model::SubtypeConstraint.new({
|
data/lib/expressir/model.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'expressir/model/model_element'
|
2
2
|
|
3
|
+
require 'expressir/model/cache'
|
4
|
+
|
3
5
|
require 'expressir/model/identifier'
|
4
6
|
|
5
7
|
require 'expressir/model/attribute'
|
@@ -7,12 +9,12 @@ require 'expressir/model/constant'
|
|
7
9
|
require 'expressir/model/entity'
|
8
10
|
require 'expressir/model/enumeration_item'
|
9
11
|
require 'expressir/model/function'
|
10
|
-
require 'expressir/model/informal_proposition'
|
11
12
|
require 'expressir/model/interface'
|
12
13
|
require 'expressir/model/interface_item'
|
13
14
|
require 'expressir/model/interfaced_item'
|
14
15
|
require 'expressir/model/parameter'
|
15
16
|
require 'expressir/model/procedure'
|
17
|
+
require 'expressir/model/remark_item'
|
16
18
|
require 'expressir/model/repository'
|
17
19
|
require 'expressir/model/rule'
|
18
20
|
require 'expressir/model/schema'
|
@@ -7,15 +7,16 @@ module Expressir
|
|
7
7
|
DERIVED = :DERIVED
|
8
8
|
INVERSE = :INVERSE
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
model_attr_accessor :kind
|
11
|
+
model_attr_accessor :supertype_attribute
|
12
|
+
model_attr_accessor :optional
|
13
|
+
model_attr_accessor :type
|
14
|
+
model_attr_accessor :expression
|
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
|
@kind = options[:kind]
|
@@ -26,6 +27,12 @@ module Expressir
|
|
26
27
|
|
27
28
|
super
|
28
29
|
end
|
30
|
+
|
31
|
+
def children
|
32
|
+
[
|
33
|
+
*remark_items
|
34
|
+
]
|
35
|
+
end
|
29
36
|
end
|
30
37
|
end
|
31
38
|
end
|
@@ -3,12 +3,13 @@ module Expressir
|
|
3
3
|
class Constant < ModelElement
|
4
4
|
include Identifier
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
model_attr_accessor :type
|
7
|
+
model_attr_accessor :expression
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
10
|
@id = options[:id]
|
11
11
|
@remarks = options.fetch(:remarks, [])
|
12
|
+
@remark_items = options.fetch(:remark_items, [])
|
12
13
|
@source = options[:source]
|
13
14
|
|
14
15
|
@type = options[:type]
|
@@ -16,6 +17,12 @@ module Expressir
|
|
16
17
|
|
17
18
|
super
|
18
19
|
end
|
20
|
+
|
21
|
+
def children
|
22
|
+
[
|
23
|
+
*remark_items
|
24
|
+
]
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
@@ -3,17 +3,18 @@ module Expressir
|
|
3
3
|
class Entity < ModelElement
|
4
4
|
include Identifier
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
model_attr_accessor :abstract
|
7
|
+
model_attr_accessor :supertype_expression
|
8
|
+
model_attr_accessor :subtype_of
|
9
|
+
model_attr_accessor :attributes
|
10
|
+
model_attr_accessor :unique
|
11
|
+
model_attr_accessor :where
|
12
|
+
model_attr_accessor :informal_propositions
|
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
|
@abstract = options[:abstract]
|
@@ -28,12 +29,13 @@ module Expressir
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def children
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
[
|
33
|
+
*attributes,
|
34
|
+
*unique,
|
35
|
+
*where,
|
36
|
+
*informal_propositions,
|
37
|
+
*remark_items
|
38
|
+
]
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -6,10 +6,17 @@ module Expressir
|
|
6
6
|
def initialize(options = {})
|
7
7
|
@id = options[:id]
|
8
8
|
@remarks = options.fetch(:remarks, [])
|
9
|
+
@remark_items = options.fetch(:remark_items, [])
|
9
10
|
@source = options[:source]
|
10
11
|
|
11
12
|
super
|
12
13
|
end
|
14
|
+
|
15
|
+
def children
|
16
|
+
[
|
17
|
+
*remark_items
|
18
|
+
]
|
19
|
+
end
|
13
20
|
end
|
14
21
|
end
|
15
22
|
end
|
@@ -2,8 +2,8 @@ module Expressir
|
|
2
2
|
module Model
|
3
3
|
module Expressions
|
4
4
|
class AggregateItem < ModelElement
|
5
|
-
|
6
|
-
|
5
|
+
model_attr_accessor :expression
|
6
|
+
model_attr_accessor :repetition
|
7
7
|
|
8
8
|
def initialize(options = {})
|
9
9
|
@expression = options[:expression]
|
@@ -25,9 +25,9 @@ module Expressir
|
|
25
25
|
SUBTRACTION = :SUBTRACTION
|
26
26
|
XOR = :XOR
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
model_attr_accessor :operator
|
29
|
+
model_attr_accessor :operand1
|
30
|
+
model_attr_accessor :operand2
|
31
31
|
|
32
32
|
def initialize(options = {})
|
33
33
|
@operator = options[:operator]
|
@@ -2,8 +2,8 @@ module Expressir
|
|
2
2
|
module Model
|
3
3
|
module Expressions
|
4
4
|
class EntityConstructor < ModelElement
|
5
|
-
|
6
|
-
|
5
|
+
model_attr_accessor :entity
|
6
|
+
model_attr_accessor :parameters
|
7
7
|
|
8
8
|
def initialize(options = {})
|
9
9
|
@entity = options[:entity]
|