expressir 0.2.11-x86-mingw32 → 0.2.16-x86-mingw32
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.so +0 -0
- data/lib/expressir/express_exp/2.5/express_parser.so +0 -0
- data/lib/expressir/express_exp/2.6/express_parser.so +0 -0
- data/lib/expressir/express_exp/2.7/express_parser.so +0 -0
- data/lib/expressir/express_exp/3.0/express_parser.so +0 -0
- data/lib/expressir/express_exp/formatter.rb +90 -100
- data/lib/expressir/express_exp/hyperlink_formatter.rb +27 -0
- data/lib/expressir/express_exp/parser.rb +7 -1
- data/lib/expressir/express_exp/schema_head_formatter.rb +12 -0
- data/lib/expressir/express_exp/visitor.rb +67 -99
- 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 +71 -4
- 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 -12
- 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 +28 -0
- 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 +40 -0
- data/spec/expressir/model/{scope_spec.rb → model_element/find_spec.rb} +7 -2
- data/spec/expressir/model/{model_element_spec.rb → model_element/hash_spec.rb} +7 -18
- metadata +33 -14
- data/lib/expressir/model/scope.rb +0 -71
- data/spec/expressir/express_exp/ap233_spec.rb +0 -22
- data/spec/expressir/express_exp/head_source_spec.rb +0 -38
@@ -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]
|
@@ -93,56 +92,37 @@ module Expressir
|
|
93
92
|
@tokens[start_index..stop_index]
|
94
93
|
end
|
95
94
|
|
96
|
-
def get_head_tokens(ctx)
|
97
|
-
start_index, stop_index = if ctx.instance_of? ::ExpressParser::SchemaDeclContext
|
98
|
-
start_index = ctx.start.token_index
|
99
|
-
stop_index = if ctx.schema_body.interface_specification.length > 0
|
100
|
-
ctx.schema_body.interface_specification.last.stop.token_index
|
101
|
-
elsif ctx.schema_version_id
|
102
|
-
ctx.schema_version_id.stop.token_index + 1
|
103
|
-
else
|
104
|
-
ctx.schema_id.stop.token_index + 1
|
105
|
-
end
|
106
|
-
|
107
|
-
[start_index, stop_index]
|
108
|
-
end
|
109
|
-
|
110
|
-
if start_index and stop_index
|
111
|
-
@tokens[start_index..stop_index]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
95
|
def attach_source(ctx, node)
|
116
96
|
if node.class.method_defined? :source
|
117
97
|
tokens = get_tokens(ctx)
|
118
98
|
node.source = get_tokens_source(tokens)
|
119
99
|
end
|
120
|
-
|
121
|
-
if node.class.method_defined? :head_source
|
122
|
-
tokens = get_head_tokens(ctx)
|
123
|
-
node.head_source = get_tokens_source(tokens)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def attach_parent(node)
|
128
|
-
if node.class.method_defined? :attach_parent_to_children
|
129
|
-
node.attach_parent_to_children
|
130
|
-
end
|
131
100
|
end
|
132
101
|
|
133
102
|
def find_remark_target(node, path)
|
134
|
-
|
135
|
-
target_node
|
103
|
+
target_node = node.find(path)
|
104
|
+
return target_node if target_node
|
136
105
|
|
137
|
-
if
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
106
|
+
# check if path should create implicit informal proposal
|
107
|
+
# see https://github.com/lutaml/expressir/issues/50
|
108
|
+
rest, _, current_path = path.rpartition(".") # get last path part
|
109
|
+
_, _, current_path = current_path.rpartition(":") # ignore prefix
|
110
|
+
|
111
|
+
# match informal proposition id
|
112
|
+
informal_proposition_id = current_path.match(/^IP\d+$/).to_a[0]
|
113
|
+
return unless informal_proposition_id
|
144
114
|
|
145
|
-
|
115
|
+
# find informal proposition target
|
116
|
+
target_node = node.find(rest)
|
117
|
+
return unless target_node and target_node.class.method_defined? :informal_propositions
|
118
|
+
|
119
|
+
# create implicit informal proposition
|
120
|
+
informal_proposition = Model::InformalProposition.new({
|
121
|
+
id: informal_proposition_id
|
122
|
+
})
|
123
|
+
target_node.informal_propositions << informal_proposition
|
124
|
+
informal_proposition.parent = target_node
|
125
|
+
informal_proposition
|
146
126
|
end
|
147
127
|
|
148
128
|
def attach_remarks(ctx, node)
|
@@ -687,9 +667,9 @@ module Expressir
|
|
687
667
|
expression = visit_if(ctx__expression)
|
688
668
|
|
689
669
|
Model::Attribute.new({
|
690
|
-
id: attribute.id,
|
670
|
+
id: attribute.id, # reuse
|
691
671
|
kind: Model::Attribute::DERIVED,
|
692
|
-
supertype_attribute: attribute.supertype_attribute,
|
672
|
+
supertype_attribute: attribute.supertype_attribute, # reuse
|
693
673
|
type: type,
|
694
674
|
expression: expression
|
695
675
|
})
|
@@ -767,7 +747,7 @@ module Expressir
|
|
767
747
|
id = visit_if(ctx__entity_head__entity_id)
|
768
748
|
abstract = (ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration || ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration) && true
|
769
749
|
supertype_expression = visit_if(ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration || ctx__entity_head__subsuper__supertype_constraint__supertype_rule)
|
770
|
-
subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration)
|
750
|
+
subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration, [])
|
771
751
|
attributes = [
|
772
752
|
*visit_if_map_flatten(ctx__entity_body__explicit_attr),
|
773
753
|
*visit_if(ctx__entity_body__derive_clause),
|
@@ -875,9 +855,9 @@ module Expressir
|
|
875
855
|
|
876
856
|
attributes.map do |attribute|
|
877
857
|
Model::Attribute.new({
|
878
|
-
id: attribute.id,
|
858
|
+
id: attribute.id, # reuse
|
879
859
|
kind: Model::Attribute::EXPLICIT,
|
880
|
-
supertype_attribute: attribute.supertype_attribute,
|
860
|
+
supertype_attribute: attribute.supertype_attribute, # reuse
|
881
861
|
optional: optional,
|
882
862
|
type: type
|
883
863
|
})
|
@@ -967,11 +947,11 @@ module Expressir
|
|
967
947
|
parameters = visit_if_map_flatten(ctx__function_head__formal_parameter)
|
968
948
|
return_type = visit_if(ctx__function_head__parameter_type)
|
969
949
|
declarations = visit_if_map(ctx__algorithm_head__declaration)
|
970
|
-
types = declarations.select{|x| x.
|
971
|
-
entities = declarations.select{|x| x.
|
972
|
-
subtype_constraints = declarations.select{|x| x.
|
973
|
-
functions = declarations.select{|x| x.
|
974
|
-
procedures = declarations.select{|x| x.
|
950
|
+
types = declarations.select{|x| x.is_a? Model::Type}
|
951
|
+
entities = declarations.select{|x| x.is_a? Model::Entity}
|
952
|
+
subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
|
953
|
+
functions = declarations.select{|x| x.is_a? Model::Function}
|
954
|
+
procedures = declarations.select{|x| x.is_a? Model::Procedure}
|
975
955
|
constants = visit_if(ctx__algorithm_head__constant_decl, [])
|
976
956
|
variables = visit_if(ctx__algorithm_head__local_decl, [])
|
977
957
|
statements = visit_if_map(ctx__stmt)
|
@@ -1302,9 +1282,9 @@ module Expressir
|
|
1302
1282
|
end
|
1303
1283
|
|
1304
1284
|
Model::Attribute.new({
|
1305
|
-
id: attribute.id,
|
1285
|
+
id: attribute.id, # reuse
|
1306
1286
|
kind: Model::Attribute::INVERSE,
|
1307
|
-
supertype_attribute: attribute.supertype_attribute,
|
1287
|
+
supertype_attribute: attribute.supertype_attribute, # reuse
|
1308
1288
|
type: type,
|
1309
1289
|
expression: expression
|
1310
1290
|
})
|
@@ -1486,14 +1466,10 @@ module Expressir
|
|
1486
1466
|
ref = visit_if(ctx__named_types)
|
1487
1467
|
id = visit_if(ctx__entity_id || ctx__type_id)
|
1488
1468
|
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
})
|
1494
|
-
else
|
1495
|
-
ref
|
1496
|
-
end
|
1469
|
+
Model::InterfaceItem.new({
|
1470
|
+
ref: ref,
|
1471
|
+
id: id
|
1472
|
+
})
|
1497
1473
|
end
|
1498
1474
|
|
1499
1475
|
def visit_null_stmt(ctx)
|
@@ -1595,11 +1571,11 @@ module Expressir
|
|
1595
1571
|
id = visit_if(ctx__procedure_head__procedure_id)
|
1596
1572
|
parameters = visit_if_map_flatten(ctx__procedure_head__procedure_head_parameter)
|
1597
1573
|
declarations = visit_if_map(ctx__algorithm_head__declaration)
|
1598
|
-
types = declarations.select{|x| x.
|
1599
|
-
entities = declarations.select{|x| x.
|
1600
|
-
subtype_constraints = declarations.select{|x| x.
|
1601
|
-
functions = declarations.select{|x| x.
|
1602
|
-
procedures = declarations.select{|x| x.
|
1574
|
+
types = declarations.select{|x| x.is_a? Model::Type}
|
1575
|
+
entities = declarations.select{|x| x.is_a? Model::Entity}
|
1576
|
+
subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
|
1577
|
+
functions = declarations.select{|x| x.is_a? Model::Function}
|
1578
|
+
procedures = declarations.select{|x| x.is_a? Model::Procedure}
|
1603
1579
|
constants = visit_if(ctx__algorithm_head__constant_decl, [])
|
1604
1580
|
variables = visit_if(ctx__algorithm_head__local_decl, [])
|
1605
1581
|
statements = visit_if_map(ctx__stmt)
|
@@ -1670,9 +1646,9 @@ module Expressir
|
|
1670
1646
|
ref: Model::Expressions::SimpleReference.new({
|
1671
1647
|
id: id
|
1672
1648
|
}),
|
1673
|
-
entity: group_reference.entity
|
1649
|
+
entity: group_reference.entity # reuse
|
1674
1650
|
}),
|
1675
|
-
attribute: attribute_reference.attribute
|
1651
|
+
attribute: attribute_reference.attribute # reuse
|
1676
1652
|
})
|
1677
1653
|
end
|
1678
1654
|
|
@@ -1837,21 +1813,13 @@ module Expressir
|
|
1837
1813
|
ctx__resource_ref = ctx.resource_ref
|
1838
1814
|
ctx__rename_id = ctx.rename_id
|
1839
1815
|
|
1840
|
-
|
1841
|
-
|
1842
|
-
ref = visit(ctx__resource_ref)
|
1843
|
-
id = visit(ctx__rename_id)
|
1816
|
+
ref = visit_if(ctx__resource_ref)
|
1817
|
+
id = visit_if(ctx__rename_id)
|
1844
1818
|
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
else
|
1850
|
-
visit(ctx__resource_ref)
|
1851
|
-
end
|
1852
|
-
else
|
1853
|
-
raise 'Invalid state'
|
1854
|
-
end
|
1819
|
+
Model::InterfaceItem.new({
|
1820
|
+
ref: ref,
|
1821
|
+
id: id
|
1822
|
+
})
|
1855
1823
|
end
|
1856
1824
|
|
1857
1825
|
def visit_resource_ref(ctx)
|
@@ -1888,11 +1856,11 @@ module Expressir
|
|
1888
1856
|
id = visit_if(ctx__rule_head__rule_id)
|
1889
1857
|
applies_to = visit_if_map(ctx__rule_head__entity_ref)
|
1890
1858
|
declarations = visit_if_map(ctx__algorithm_head__declaration)
|
1891
|
-
types = declarations.select{|x| x.
|
1892
|
-
entities = declarations.select{|x| x.
|
1893
|
-
subtype_constraints = declarations.select{|x| x.
|
1894
|
-
functions = declarations.select{|x| x.
|
1895
|
-
procedures = declarations.select{|x| x.
|
1859
|
+
types = declarations.select{|x| x.is_a? Model::Type}
|
1860
|
+
entities = declarations.select{|x| x.is_a? Model::Entity}
|
1861
|
+
subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
|
1862
|
+
functions = declarations.select{|x| x.is_a? Model::Function}
|
1863
|
+
procedures = declarations.select{|x| x.is_a? Model::Procedure}
|
1896
1864
|
constants = visit_if(ctx__algorithm_head__constant_decl, [])
|
1897
1865
|
variables = visit_if(ctx__algorithm_head__local_decl, [])
|
1898
1866
|
statements = visit_if_map(ctx__stmt)
|
@@ -1953,12 +1921,12 @@ module Expressir
|
|
1953
1921
|
interfaces = visit_if_map(ctx__schema_body__interface_specification)
|
1954
1922
|
constants = visit_if(ctx__schema_body__constant_decl, [])
|
1955
1923
|
declarations = visit_if_map(ctx__schema_body__schema_body_declaration)
|
1956
|
-
types = declarations.select{|x| x.
|
1957
|
-
entities = declarations.select{|x| x.
|
1958
|
-
subtype_constraints = declarations.select{|x| x.
|
1959
|
-
functions = declarations.select{|x| x.
|
1960
|
-
procedures = declarations.select{|x| x.
|
1961
|
-
rules = declarations.select{|x| x.
|
1924
|
+
types = declarations.select{|x| x.is_a? Model::Type}
|
1925
|
+
entities = declarations.select{|x| x.is_a? Model::Entity}
|
1926
|
+
subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
|
1927
|
+
functions = declarations.select{|x| x.is_a? Model::Function}
|
1928
|
+
procedures = declarations.select{|x| x.is_a? Model::Procedure}
|
1929
|
+
rules = declarations.select{|x| x.is_a? Model::Rule}
|
1962
1930
|
|
1963
1931
|
Model::Schema.new({
|
1964
1932
|
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
|