expressir 0.2.10-arm64-darwin → 0.2.15-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,14 @@
|
|
1
|
+
require "expressir/express_exp/formatter"
|
2
|
+
|
3
|
+
module Expressir
|
4
|
+
module ExpressExp
|
5
|
+
class SchemaHeadFormatter < Formatter
|
6
|
+
def format_schema(node)
|
7
|
+
[
|
8
|
+
"SCHEMA #{node.id}#{node.version ? " #{format(node.version)}" : ""};",
|
9
|
+
*node.interfaces.map{|x| format(x)}
|
10
|
+
].join("\n")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -14,7 +14,7 @@ require "set"
|
|
14
14
|
# > method of gaining this information is multi-pass parsing: the first pass collects the identifiers from their
|
15
15
|
# > declarations, so that subsequent passes are then able to distinguish a veriable_ref from a function_ref,
|
16
16
|
# > for example.
|
17
|
-
#
|
17
|
+
# - such multi-pass parsing is not implemented yet
|
18
18
|
# - xxxRef - merged to SimpleReference
|
19
19
|
# - entityConstructor, functionCall - merged to Call
|
20
20
|
#
|
@@ -44,11 +44,10 @@ module Expressir
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def visit(ctx)
|
47
|
-
|
48
|
-
attach_source(ctx,
|
49
|
-
|
50
|
-
|
51
|
-
result
|
47
|
+
node = super(ctx)
|
48
|
+
attach_source(ctx, node)
|
49
|
+
attach_remarks(ctx, node)
|
50
|
+
node
|
52
51
|
end
|
53
52
|
|
54
53
|
def visit_if(ctx, default = nil)
|
@@ -84,7 +83,7 @@ module Expressir
|
|
84
83
|
end
|
85
84
|
|
86
85
|
def get_tokens(ctx)
|
87
|
-
start_index, stop_index = if ctx.
|
86
|
+
start_index, stop_index = if ctx.is_a? ::ExpressParser::SyntaxContext
|
88
87
|
[0, @tokens.size - 1]
|
89
88
|
else
|
90
89
|
[ctx.start.token_index, ctx.stop.token_index]
|
@@ -94,7 +93,7 @@ module Expressir
|
|
94
93
|
end
|
95
94
|
|
96
95
|
def get_head_tokens(ctx)
|
97
|
-
start_index, stop_index = if ctx.
|
96
|
+
start_index, stop_index = if ctx.is_a? ::ExpressParser::SchemaDeclContext
|
98
97
|
start_index = ctx.start.token_index
|
99
98
|
stop_index = if ctx.schema_body.interface_specification.length > 0
|
100
99
|
ctx.schema_body.interface_specification.last.stop.token_index
|
@@ -124,29 +123,30 @@ module Expressir
|
|
124
123
|
end
|
125
124
|
end
|
126
125
|
|
127
|
-
def attach_parent(ctx, node)
|
128
|
-
if node.class.method_defined? :children
|
129
|
-
node.children.each do |child_node|
|
130
|
-
if child_node.class.method_defined? :parent and !child_node.parent
|
131
|
-
child_node.parent = node
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
126
|
def find_remark_target(node, path)
|
138
|
-
|
139
|
-
target_node
|
127
|
+
target_node = node.find(path)
|
128
|
+
return target_node if target_node
|
140
129
|
|
141
|
-
if
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
current_node = current_node.parent
|
146
|
-
target_node = current_node.find_or_create(path)
|
147
|
-
end
|
130
|
+
# check if path should create implicit informal proposal
|
131
|
+
# see https://github.com/lutaml/expressir/issues/50
|
132
|
+
rest, _, current_path = path.rpartition(".") # get last path part
|
133
|
+
_, _, current_path = current_path.rpartition(":") # ignore prefix
|
148
134
|
|
149
|
-
|
135
|
+
# match informal proposition id
|
136
|
+
informal_proposition_id = current_path.match(/^IP\d+$/).to_a[0]
|
137
|
+
return unless informal_proposition_id
|
138
|
+
|
139
|
+
# find informal proposition target
|
140
|
+
target_node = node.find(rest)
|
141
|
+
return unless target_node and target_node.class.method_defined? :informal_propositions
|
142
|
+
|
143
|
+
# create implicit informal proposition
|
144
|
+
informal_proposition = Model::InformalProposition.new({
|
145
|
+
id: informal_proposition_id
|
146
|
+
})
|
147
|
+
target_node.informal_propositions << informal_proposition
|
148
|
+
informal_proposition.parent = target_node
|
149
|
+
informal_proposition
|
150
150
|
end
|
151
151
|
|
152
152
|
def attach_remarks(ctx, node)
|
@@ -691,9 +691,9 @@ module Expressir
|
|
691
691
|
expression = visit_if(ctx__expression)
|
692
692
|
|
693
693
|
Model::Attribute.new({
|
694
|
-
id: attribute.id,
|
694
|
+
id: attribute.id, # reuse
|
695
695
|
kind: Model::Attribute::DERIVED,
|
696
|
-
supertype_attribute: attribute.supertype_attribute,
|
696
|
+
supertype_attribute: attribute.supertype_attribute, # reuse
|
697
697
|
type: type,
|
698
698
|
expression: expression
|
699
699
|
})
|
@@ -771,7 +771,7 @@ module Expressir
|
|
771
771
|
id = visit_if(ctx__entity_head__entity_id)
|
772
772
|
abstract = (ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration || ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration) && true
|
773
773
|
supertype_expression = visit_if(ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration || ctx__entity_head__subsuper__supertype_constraint__supertype_rule)
|
774
|
-
subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration)
|
774
|
+
subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration, [])
|
775
775
|
attributes = [
|
776
776
|
*visit_if_map_flatten(ctx__entity_body__explicit_attr),
|
777
777
|
*visit_if(ctx__entity_body__derive_clause),
|
@@ -879,9 +879,9 @@ module Expressir
|
|
879
879
|
|
880
880
|
attributes.map do |attribute|
|
881
881
|
Model::Attribute.new({
|
882
|
-
id: attribute.id,
|
882
|
+
id: attribute.id, # reuse
|
883
883
|
kind: Model::Attribute::EXPLICIT,
|
884
|
-
supertype_attribute: attribute.supertype_attribute,
|
884
|
+
supertype_attribute: attribute.supertype_attribute, # reuse
|
885
885
|
optional: optional,
|
886
886
|
type: type
|
887
887
|
})
|
@@ -971,11 +971,11 @@ module Expressir
|
|
971
971
|
parameters = visit_if_map_flatten(ctx__function_head__formal_parameter)
|
972
972
|
return_type = visit_if(ctx__function_head__parameter_type)
|
973
973
|
declarations = visit_if_map(ctx__algorithm_head__declaration)
|
974
|
-
types = declarations.select{|x| x.
|
975
|
-
entities = declarations.select{|x| x.
|
976
|
-
subtype_constraints = declarations.select{|x| x.
|
977
|
-
functions = declarations.select{|x| x.
|
978
|
-
procedures = declarations.select{|x| x.
|
974
|
+
types = declarations.select{|x| x.is_a? Model::Type}
|
975
|
+
entities = declarations.select{|x| x.is_a? Model::Entity}
|
976
|
+
subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
|
977
|
+
functions = declarations.select{|x| x.is_a? Model::Function}
|
978
|
+
procedures = declarations.select{|x| x.is_a? Model::Procedure}
|
979
979
|
constants = visit_if(ctx__algorithm_head__constant_decl, [])
|
980
980
|
variables = visit_if(ctx__algorithm_head__local_decl, [])
|
981
981
|
statements = visit_if_map(ctx__stmt)
|
@@ -1306,9 +1306,9 @@ module Expressir
|
|
1306
1306
|
end
|
1307
1307
|
|
1308
1308
|
Model::Attribute.new({
|
1309
|
-
id: attribute.id,
|
1309
|
+
id: attribute.id, # reuse
|
1310
1310
|
kind: Model::Attribute::INVERSE,
|
1311
|
-
supertype_attribute: attribute.supertype_attribute,
|
1311
|
+
supertype_attribute: attribute.supertype_attribute, # reuse
|
1312
1312
|
type: type,
|
1313
1313
|
expression: expression
|
1314
1314
|
})
|
@@ -1490,14 +1490,10 @@ module Expressir
|
|
1490
1490
|
ref = visit_if(ctx__named_types)
|
1491
1491
|
id = visit_if(ctx__entity_id || ctx__type_id)
|
1492
1492
|
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
})
|
1498
|
-
else
|
1499
|
-
ref
|
1500
|
-
end
|
1493
|
+
Model::InterfaceItem.new({
|
1494
|
+
ref: ref,
|
1495
|
+
id: id
|
1496
|
+
})
|
1501
1497
|
end
|
1502
1498
|
|
1503
1499
|
def visit_null_stmt(ctx)
|
@@ -1599,11 +1595,11 @@ module Expressir
|
|
1599
1595
|
id = visit_if(ctx__procedure_head__procedure_id)
|
1600
1596
|
parameters = visit_if_map_flatten(ctx__procedure_head__procedure_head_parameter)
|
1601
1597
|
declarations = visit_if_map(ctx__algorithm_head__declaration)
|
1602
|
-
types = declarations.select{|x| x.
|
1603
|
-
entities = declarations.select{|x| x.
|
1604
|
-
subtype_constraints = declarations.select{|x| x.
|
1605
|
-
functions = declarations.select{|x| x.
|
1606
|
-
procedures = declarations.select{|x| x.
|
1598
|
+
types = declarations.select{|x| x.is_a? Model::Type}
|
1599
|
+
entities = declarations.select{|x| x.is_a? Model::Entity}
|
1600
|
+
subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
|
1601
|
+
functions = declarations.select{|x| x.is_a? Model::Function}
|
1602
|
+
procedures = declarations.select{|x| x.is_a? Model::Procedure}
|
1607
1603
|
constants = visit_if(ctx__algorithm_head__constant_decl, [])
|
1608
1604
|
variables = visit_if(ctx__algorithm_head__local_decl, [])
|
1609
1605
|
statements = visit_if_map(ctx__stmt)
|
@@ -1674,9 +1670,9 @@ module Expressir
|
|
1674
1670
|
ref: Model::Expressions::SimpleReference.new({
|
1675
1671
|
id: id
|
1676
1672
|
}),
|
1677
|
-
entity: group_reference.entity
|
1673
|
+
entity: group_reference.entity # reuse
|
1678
1674
|
}),
|
1679
|
-
attribute: attribute_reference.attribute
|
1675
|
+
attribute: attribute_reference.attribute # reuse
|
1680
1676
|
})
|
1681
1677
|
end
|
1682
1678
|
|
@@ -1841,21 +1837,13 @@ module Expressir
|
|
1841
1837
|
ctx__resource_ref = ctx.resource_ref
|
1842
1838
|
ctx__rename_id = ctx.rename_id
|
1843
1839
|
|
1844
|
-
|
1845
|
-
|
1846
|
-
ref = visit(ctx__resource_ref)
|
1847
|
-
id = visit(ctx__rename_id)
|
1840
|
+
ref = visit_if(ctx__resource_ref)
|
1841
|
+
id = visit_if(ctx__rename_id)
|
1848
1842
|
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
else
|
1854
|
-
visit(ctx__resource_ref)
|
1855
|
-
end
|
1856
|
-
else
|
1857
|
-
raise 'Invalid state'
|
1858
|
-
end
|
1843
|
+
Model::InterfaceItem.new({
|
1844
|
+
ref: ref,
|
1845
|
+
id: id
|
1846
|
+
})
|
1859
1847
|
end
|
1860
1848
|
|
1861
1849
|
def visit_resource_ref(ctx)
|
@@ -1892,11 +1880,11 @@ module Expressir
|
|
1892
1880
|
id = visit_if(ctx__rule_head__rule_id)
|
1893
1881
|
applies_to = visit_if_map(ctx__rule_head__entity_ref)
|
1894
1882
|
declarations = visit_if_map(ctx__algorithm_head__declaration)
|
1895
|
-
types = declarations.select{|x| x.
|
1896
|
-
entities = declarations.select{|x| x.
|
1897
|
-
subtype_constraints = declarations.select{|x| x.
|
1898
|
-
functions = declarations.select{|x| x.
|
1899
|
-
procedures = declarations.select{|x| x.
|
1883
|
+
types = declarations.select{|x| x.is_a? Model::Type}
|
1884
|
+
entities = declarations.select{|x| x.is_a? Model::Entity}
|
1885
|
+
subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
|
1886
|
+
functions = declarations.select{|x| x.is_a? Model::Function}
|
1887
|
+
procedures = declarations.select{|x| x.is_a? Model::Procedure}
|
1900
1888
|
constants = visit_if(ctx__algorithm_head__constant_decl, [])
|
1901
1889
|
variables = visit_if(ctx__algorithm_head__local_decl, [])
|
1902
1890
|
statements = visit_if_map(ctx__stmt)
|
@@ -1957,12 +1945,12 @@ module Expressir
|
|
1957
1945
|
interfaces = visit_if_map(ctx__schema_body__interface_specification)
|
1958
1946
|
constants = visit_if(ctx__schema_body__constant_decl, [])
|
1959
1947
|
declarations = visit_if_map(ctx__schema_body__schema_body_declaration)
|
1960
|
-
types = declarations.select{|x| x.
|
1961
|
-
entities = declarations.select{|x| x.
|
1962
|
-
subtype_constraints = declarations.select{|x| x.
|
1963
|
-
functions = declarations.select{|x| x.
|
1964
|
-
procedures = declarations.select{|x| x.
|
1965
|
-
rules = declarations.select{|x| x.
|
1948
|
+
types = declarations.select{|x| x.is_a? Model::Type}
|
1949
|
+
entities = declarations.select{|x| x.is_a? Model::Entity}
|
1950
|
+
subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
|
1951
|
+
functions = declarations.select{|x| x.is_a? Model::Function}
|
1952
|
+
procedures = declarations.select{|x| x.is_a? Model::Procedure}
|
1953
|
+
rules = declarations.select{|x| x.is_a? Model::Rule}
|
1966
1954
|
|
1967
1955
|
Model::Schema.new({
|
1968
1956
|
id: id,
|
data/lib/expressir/model.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'expressir/model/model_element'
|
2
2
|
|
3
|
-
require 'expressir/model/scope'
|
4
3
|
require 'expressir/model/identifier'
|
5
4
|
|
6
5
|
require 'expressir/model/attribute'
|
@@ -10,9 +9,10 @@ require 'expressir/model/enumeration_item'
|
|
10
9
|
require 'expressir/model/function'
|
11
10
|
require 'expressir/model/informal_proposition'
|
12
11
|
require 'expressir/model/interface'
|
12
|
+
require 'expressir/model/interface_item'
|
13
|
+
require 'expressir/model/interfaced_item'
|
13
14
|
require 'expressir/model/parameter'
|
14
15
|
require 'expressir/model/procedure'
|
15
|
-
require 'expressir/model/renamed_ref'
|
16
16
|
require 'expressir/model/repository'
|
17
17
|
require 'expressir/model/rule'
|
18
18
|
require 'expressir/model/schema'
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
3
|
class Entity < ModelElement
|
4
|
-
include Scope
|
5
4
|
include Identifier
|
6
5
|
|
7
6
|
attr_accessor :abstract
|
@@ -19,11 +18,13 @@ module Expressir
|
|
19
18
|
|
20
19
|
@abstract = options[:abstract]
|
21
20
|
@supertype_expression = options[:supertype_expression]
|
22
|
-
@subtype_of = options
|
21
|
+
@subtype_of = options.fetch(:subtype_of, [])
|
23
22
|
@attributes = options.fetch(:attributes, [])
|
24
23
|
@unique = options.fetch(:unique, [])
|
25
24
|
@where = options.fetch(:where, [])
|
26
25
|
@informal_propositions = options.fetch(:informal_propositions, [])
|
26
|
+
|
27
|
+
super
|
27
28
|
end
|
28
29
|
|
29
30
|
def children
|
@@ -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
|