expressir 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -13
- data/.rubocop_todo.yml +69 -6
- data/Gemfile +1 -1
- data/README.adoc +46 -0
- data/exe/expressir-format-test +2 -1
- data/expressir.gemspec +2 -3
- data/lib/expressir/express/cache.rb +6 -6
- data/lib/expressir/express/formatter.rb +754 -741
- data/lib/expressir/express/hyperlink_formatter.rb +2 -2
- data/lib/expressir/express/model_visitor.rb +1 -1
- data/lib/expressir/express/parser.rb +224 -100
- data/lib/expressir/express/resolve_references_model_visitor.rb +6 -6
- data/lib/expressir/express/schema_head_formatter.rb +3 -3
- data/lib/expressir/express/visitor.rb +353 -344
- data/lib/expressir/model/cache.rb +3 -3
- data/lib/expressir/model/data_type.rb +1 -1
- data/lib/expressir/model/data_types/aggregate.rb +3 -3
- data/lib/expressir/model/data_types/array.rb +6 -6
- data/lib/expressir/model/data_types/bag.rb +4 -4
- data/lib/expressir/model/data_types/binary.rb +3 -3
- data/lib/expressir/model/data_types/boolean.rb +1 -1
- data/lib/expressir/model/data_types/enumeration.rb +4 -4
- data/lib/expressir/model/data_types/enumeration_item.rb +2 -2
- data/lib/expressir/model/data_types/generic.rb +2 -2
- data/lib/expressir/model/data_types/generic_entity.rb +2 -2
- data/lib/expressir/model/data_types/integer.rb +1 -1
- data/lib/expressir/model/data_types/list.rb +5 -5
- data/lib/expressir/model/data_types/logical.rb +1 -1
- data/lib/expressir/model/data_types/number.rb +1 -1
- data/lib/expressir/model/data_types/real.rb +2 -2
- data/lib/expressir/model/data_types/select.rb +5 -5
- data/lib/expressir/model/data_types/set.rb +4 -4
- data/lib/expressir/model/data_types/string.rb +3 -3
- data/lib/expressir/model/declaration.rb +1 -1
- data/lib/expressir/model/declarations/attribute.rb +7 -7
- data/lib/expressir/model/declarations/constant.rb +4 -4
- data/lib/expressir/model/declarations/entity.rb +9 -9
- data/lib/expressir/model/declarations/function.rb +13 -13
- data/lib/expressir/model/declarations/interface.rb +4 -4
- data/lib/expressir/model/declarations/interface_item.rb +3 -3
- data/lib/expressir/model/declarations/interfaced_item.rb +6 -6
- data/lib/expressir/model/declarations/parameter.rb +4 -4
- data/lib/expressir/model/declarations/procedure.rb +12 -12
- data/lib/expressir/model/declarations/remark_item.rb +3 -3
- data/lib/expressir/model/declarations/rule.rb +14 -14
- data/lib/expressir/model/declarations/schema.rb +18 -18
- data/lib/expressir/model/declarations/schema_version.rb +3 -3
- data/lib/expressir/model/declarations/schema_version_item.rb +3 -3
- data/lib/expressir/model/declarations/subtype_constraint.rb +6 -6
- data/lib/expressir/model/declarations/type.rb +5 -5
- data/lib/expressir/model/declarations/unique_rule.rb +3 -3
- data/lib/expressir/model/declarations/variable.rb +4 -4
- data/lib/expressir/model/declarations/where_rule.rb +3 -3
- data/lib/expressir/model/expression.rb +1 -1
- data/lib/expressir/model/expressions/aggregate_initializer.rb +2 -2
- data/lib/expressir/model/expressions/aggregate_initializer_item.rb +3 -3
- data/lib/expressir/model/expressions/binary_expression.rb +12 -5
- data/lib/expressir/model/expressions/entity_constructor.rb +3 -3
- data/lib/expressir/model/expressions/function_call.rb +3 -3
- data/lib/expressir/model/expressions/interval.rb +6 -6
- data/lib/expressir/model/expressions/query_expression.rb +4 -4
- data/lib/expressir/model/expressions/unary_expression.rb +3 -3
- data/lib/expressir/model/identifier.rb +5 -5
- data/lib/expressir/model/literal.rb +1 -1
- data/lib/expressir/model/literals/binary.rb +2 -2
- data/lib/expressir/model/literals/integer.rb +2 -2
- data/lib/expressir/model/literals/logical.rb +2 -2
- data/lib/expressir/model/literals/real.rb +2 -2
- data/lib/expressir/model/literals/string.rb +3 -3
- data/lib/expressir/model/model_element.rb +35 -41
- data/lib/expressir/model/reference.rb +1 -1
- data/lib/expressir/model/references/attribute_reference.rb +3 -3
- data/lib/expressir/model/references/group_reference.rb +3 -3
- data/lib/expressir/model/references/index_reference.rb +4 -4
- data/lib/expressir/model/references/simple_reference.rb +3 -3
- data/lib/expressir/model/repository.rb +3 -4
- data/lib/expressir/model/statement.rb +1 -1
- data/lib/expressir/model/statements/alias.rb +4 -4
- data/lib/expressir/model/statements/assignment.rb +3 -3
- data/lib/expressir/model/statements/case.rb +4 -4
- data/lib/expressir/model/statements/case_action.rb +3 -3
- data/lib/expressir/model/statements/compound.rb +2 -2
- data/lib/expressir/model/statements/escape.rb +1 -1
- data/lib/expressir/model/statements/if.rb +4 -4
- data/lib/expressir/model/statements/null.rb +1 -1
- data/lib/expressir/model/statements/procedure_call.rb +3 -3
- data/lib/expressir/model/statements/repeat.rb +8 -8
- data/lib/expressir/model/statements/return.rb +2 -2
- data/lib/expressir/model/statements/skip.rb +1 -1
- data/lib/expressir/model/supertype_expression.rb +1 -1
- data/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +4 -4
- data/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +2 -2
- data/lib/expressir/version.rb +1 -1
- metadata +12 -12
@@ -9,7 +9,7 @@ module Expressir
|
|
9
9
|
# @!visibility private
|
10
10
|
def self.included(mod)
|
11
11
|
if !mod.superclass.private_method_defined? :format_references_simple_reference
|
12
|
-
raise
|
12
|
+
raise "Missing method"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -33,4 +33,4 @@ module Expressir
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
-
end
|
36
|
+
end
|
@@ -30,13 +30,13 @@ module Expressir
|
|
30
30
|
SUBTYPE_CONSTRAINT SUPERTYPE TAN THEN TO TRUE TYPE TYPEOF TOTAL_OVER UNIQUE
|
31
31
|
UNKNOWN UNTIL USE USEDIN VALUE VALUE_IN VALUE_UNIQUE VAR WITH WHERE WHILE
|
32
32
|
XOR
|
33
|
-
]
|
33
|
+
].freeze
|
34
34
|
|
35
35
|
def keyword_rule(str)
|
36
36
|
key_chars = str.to_s.split(//)
|
37
|
-
key_chars
|
38
|
-
collect! { |char| match("[#{char}#{char.downcase}]") }
|
39
|
-
reduce(:>>) >> match["a-zA-Z0-9_"].absent?
|
37
|
+
key_chars
|
38
|
+
.collect! { |char| match("[#{char}#{char.downcase}]") }
|
39
|
+
.reduce(:>>) >> match["a-zA-Z0-9_"].absent?
|
40
40
|
end
|
41
41
|
|
42
42
|
KEYWORDS.each do |keyword|
|
@@ -44,80 +44,121 @@ module Expressir
|
|
44
44
|
rule(sym) { cts(keyword_rule(keyword).as(:str)).as(sym) }
|
45
45
|
end
|
46
46
|
|
47
|
-
rule(:abstractEntityDeclaration) {
|
48
|
-
rule(:abstractSupertypeDeclaration)
|
47
|
+
rule(:abstractEntityDeclaration) { tABSTRACT.as(:abstractEntityDeclaration) }
|
48
|
+
rule(:abstractSupertypeDeclaration) do
|
49
|
+
(tABSTRACT >> tSUPERTYPE >> subtypeConstraint.maybe).as(:abstractSupertypeDeclaration)
|
50
|
+
end
|
49
51
|
rule(:abstractSupertype) { (tABSTRACT >> tSUPERTYPE >> op_delim).as(:abstractSupertype) }
|
50
|
-
rule(:actualParameterList)
|
52
|
+
rule(:actualParameterList) do
|
53
|
+
(op_leftparen >> (parameter >> (op_comma >> parameter).repeat).as(:listOf_parameter) >> op_rightparen)
|
54
|
+
.as(:actualParameterList)
|
55
|
+
end
|
51
56
|
rule(:addLikeOp) { (op_plus | op_minus | tOR | tXOR).as(:addLikeOp) }
|
52
|
-
rule(:aggregateInitializer)
|
53
|
-
|
54
|
-
|
57
|
+
rule(:aggregateInitializer) do
|
58
|
+
(op_leftbracket >> (element >> (op_comma >> element).repeat).as(:listOf_element).maybe >> op_rightbracket)
|
59
|
+
.as(:aggregateInitializer)
|
60
|
+
end
|
61
|
+
rule(:aggregateSource) { simpleExpression.as(:aggregateSource) }
|
62
|
+
rule(:aggregateType) do
|
63
|
+
(tAGGREGATE >> (op_colon >> typeLabel).maybe >> tOF >> parameterType).as(:aggregateType)
|
64
|
+
end
|
55
65
|
rule(:aggregationTypes) { (arrayType | bagType | listType | setType).as(:aggregationTypes) }
|
56
|
-
rule(:algorithmHead)
|
57
|
-
|
66
|
+
rule(:algorithmHead) do
|
67
|
+
(declaration.repeat.as(:declaration) >> constantDecl.maybe >> localDecl.maybe).as(:algorithmHead)
|
68
|
+
end
|
69
|
+
rule(:aliasStmt) do
|
70
|
+
(tALIAS >> variableId >> tFOR >> generalRef >> qualifier.repeat.as(:qualifier) >>
|
71
|
+
op_delim >> stmt.repeat(1).as(:stmt) >> tEND_ALIAS >> (op_delim.as(:op_delim2))).as(:aliasStmt)
|
72
|
+
end
|
58
73
|
rule(:anyKeyword) { KEYWORDS.map { |kw| send("t#{kw}") }.inject(:|) }
|
59
|
-
rule(:arrayType)
|
74
|
+
rule(:arrayType) do
|
75
|
+
(tARRAY >> boundSpec >> tOF >> tOPTIONAL.maybe >> tUNIQUE.maybe >> instantiableType).as(:arrayType)
|
76
|
+
end
|
60
77
|
rule(:assignmentStmt) { (generalRef >> qualifier.repeat.as(:qualifier) >> op_decl >> expression >> op_delim).as(:assignmentStmt) }
|
61
78
|
rule(:attributeDecl) { (attributeId | redeclaredAttribute).as(:attributeDecl) }
|
62
|
-
rule(:attributeId) {
|
79
|
+
rule(:attributeId) { simpleId.as(:attributeId) }
|
63
80
|
rule(:attributeQualifier) { (op_period >> attributeRef).as(:attributeQualifier) }
|
64
|
-
rule(:attributeRef) {
|
81
|
+
rule(:attributeRef) { attributeId.as(:attributeRef) }
|
65
82
|
rule(:bagType) { (tBAG >> boundSpec.maybe >> tOF >> instantiableType).as(:bagType) }
|
66
83
|
rule(:binaryLiteral) { cts((str("%") >> bit.repeat(1)).as(:str)).as(:binaryLiteral) }
|
67
84
|
rule(:binaryType) { (tBINARY >> widthSpec.maybe).as(:binaryType) }
|
68
|
-
rule(:bit) {
|
69
|
-
rule(:booleanType) {
|
70
|
-
rule(:bound1) {
|
71
|
-
rule(:bound2) {
|
85
|
+
rule(:bit) { match["0-1"] }
|
86
|
+
rule(:booleanType) { tBOOLEAN.as(:booleanType) }
|
87
|
+
rule(:bound1) { numericExpression.as(:bound1) }
|
88
|
+
rule(:bound2) { numericExpression.as(:bound2) }
|
72
89
|
rule(:boundSpec) { (op_leftbracket >> bound1 >> op_colon >> bound2 >> op_rightbracket).as(:boundSpec) }
|
73
90
|
rule(:builtInConstant) { (tCONST_E | tPI | tSELF | op_question_mark).as(:builtInConstant) }
|
74
|
-
rule(:builtInFunction)
|
91
|
+
rule(:builtInFunction) do
|
92
|
+
(
|
93
|
+
tABS | tACOS | tASIN | tATAN | tBLENGTH | tCOS | tEXISTS | tEXP | tFORMAT | tHIBOUND | tHIINDEX | tLENGTH |
|
94
|
+
tLOBOUND | tLOINDEX | tLOG2 | tLOG10 | tLOG | tNVL | tODD | tROLESOF | tSIN | tSIZEOF | tSQRT | tTAN |
|
95
|
+
tTYPEOF | tUSEDIN | tVALUE_IN | tVALUE_UNIQUE | tVALUE
|
96
|
+
).as(:builtInFunction)
|
97
|
+
end
|
75
98
|
rule(:builtInProcedure) { (tINSERT | tREMOVE).as(:builtInProcedure) }
|
76
99
|
rule(:caseAction) { ((caseLabel >> (op_comma >> caseLabel).repeat).as(:listOf_caseLabel) >> op_colon >> stmt).as(:caseAction) }
|
77
|
-
rule(:caseLabel) {
|
78
|
-
rule(:caseStmt)
|
100
|
+
rule(:caseLabel) { expression.as(:caseLabel) }
|
101
|
+
rule(:caseStmt) do
|
102
|
+
(tCASE >> selector >> tOF >> caseAction.repeat.as(:caseAction) >> (tOTHERWISE >> op_colon >> stmt).maybe >> tEND_CASE >> op_delim).as(:caseStmt)
|
103
|
+
end
|
79
104
|
rule(:compoundStmt) { (tBEGIN >> stmt.repeat(1).as(:stmt) >> tEND >> op_delim).as(:compoundStmt) }
|
80
105
|
rule(:concreteTypes) { (aggregationTypes | simpleTypes | typeRef).as(:concreteTypes) }
|
81
106
|
rule(:constantBody) { (constantId >> op_colon >> instantiableType >> op_decl >> expression >> op_delim).as(:constantBody) }
|
82
107
|
rule(:constantDecl) { (tCONSTANT >> constantBody.repeat(1).as(:constantBody) >> tEND_CONSTANT >> op_delim).as(:constantDecl) }
|
83
108
|
rule(:constantFactor) { (builtInConstant | constantRef).as(:constantFactor) }
|
84
|
-
rule(:constantId) {
|
85
|
-
rule(:constantRef) {
|
109
|
+
rule(:constantId) { simpleId.as(:constantId) }
|
110
|
+
rule(:constantRef) { constantId.as(:constantRef) }
|
86
111
|
rule(:constructedTypes) { (enumerationType | selectType).as(:constructedTypes) }
|
87
112
|
rule(:declaration) { (entityDecl | functionDecl | procedureDecl | subtypeConstraintDecl | typeDecl).as(:declaration) }
|
88
113
|
rule(:delim) { cts(str(";").as(:delim)) }
|
89
114
|
rule(:deriveClause) { (tDERIVE >> derivedAttr.repeat(1).as(:derivedAttr)).as(:deriveClause) }
|
90
115
|
rule(:derivedAttr) { (attributeDecl >> op_colon >> parameterType >> op_decl >> expression >> op_delim).as(:derivedAttr) }
|
91
|
-
rule(:digit) {
|
116
|
+
rule(:digit) { match["0-9"] }
|
92
117
|
rule(:digits) { (digit >> digit.repeat) }
|
93
118
|
rule(:domainRule) { ((ruleLabelId >> op_colon).maybe >> expression).as(:domainRule) }
|
94
119
|
rule(:element) { (expression >> (op_colon >> repetition).maybe).as(:element) }
|
95
120
|
rule(:embeddedRemark) { (str("(*") >> (str("*)").absent? >> (embeddedRemark | any)).repeat >> str("*)")).as(:embeddedRemark) }
|
96
121
|
rule(:encodedCharacter) { (octet >> octet >> octet >> octet) }
|
97
122
|
rule(:encodedStringLiteral) { cts((str('"') >> (encodedCharacter.repeat(1)) >> str('"')).as(:str)).as(:encodedStringLiteral) }
|
98
|
-
rule(:entityBody)
|
99
|
-
|
123
|
+
rule(:entityBody) do
|
124
|
+
(explicitAttr.repeat.as(:explicitAttr) >> deriveClause.maybe >> inverseClause.maybe >> uniqueClause.maybe >> whereClause.maybe).as(:entityBody)
|
125
|
+
end
|
126
|
+
rule(:entityConstructor) do
|
127
|
+
(entityRef >> op_leftparen >> (expression >> (op_comma >> expression).repeat).as(:listOf_expression).maybe >> op_rightparen).as(:entityConstructor)
|
128
|
+
end
|
100
129
|
rule(:entityDecl) { (entityHead >> entityBody >> tEND_ENTITY >> op_delim).as(:entityDecl) }
|
101
130
|
rule(:entityHead) { (tENTITY >> entityId >> subsuper >> op_delim).as(:entityHead) }
|
102
|
-
rule(:entityId) {
|
103
|
-
rule(:entityRef) {
|
131
|
+
rule(:entityId) { simpleId.as(:entityId) }
|
132
|
+
rule(:entityRef) { entityId.as(:entityRef) }
|
104
133
|
rule(:enumerationExtension) { (tBASED_ON >> typeRef >> (tWITH >> enumerationItems).maybe).as(:enumerationExtension) }
|
105
|
-
rule(:enumerationId) {
|
106
|
-
rule(:enumerationItem) {
|
107
|
-
rule(:enumerationItems)
|
108
|
-
|
134
|
+
rule(:enumerationId) { simpleId.as(:enumerationId) }
|
135
|
+
rule(:enumerationItem) { enumerationId.as(:enumerationItem) }
|
136
|
+
rule(:enumerationItems) do
|
137
|
+
(op_leftparen >> (enumerationItem >> (op_comma >> enumerationItem).repeat).as(:listOf_enumerationItem) >> op_rightparen).as(:enumerationItems)
|
138
|
+
end
|
139
|
+
rule(:enumerationRef) { enumerationId.as(:enumerationRef) }
|
109
140
|
rule(:enumerationReference) { ((typeRef >> op_period).maybe >> enumerationRef).as(:enumerationReference) }
|
110
141
|
rule(:enumerationType) { (tEXTENSIBLE.maybe >> tENUMERATION >> (tOF >> enumerationItems | enumerationExtension).maybe).as(:enumerationType) }
|
111
142
|
rule(:escapeStmt) { (tESCAPE >> op_delim).as(:escapeStmt) }
|
112
|
-
rule(:explicitAttr)
|
143
|
+
rule(:explicitAttr) do
|
144
|
+
(
|
145
|
+
(attributeDecl >> (op_comma >> attributeDecl).repeat).as(:listOf_attributeDecl) >> op_colon >>
|
146
|
+
tOPTIONAL.maybe >> parameterType >> op_delim
|
147
|
+
).as(:explicitAttr)
|
148
|
+
end
|
113
149
|
rule(:expression) { (simpleExpression >> (relOpExtended >> simpleExpression.as(:rhs)).maybe).as(:expression) }
|
114
150
|
rule(:factor) { (simpleFactor >> (op_double_asterisk >> simpleFactor.as(:rhs)).maybe).as(:factor) }
|
115
151
|
rule(:formalParameter) { ((parameterId >> (op_comma >> parameterId).repeat).as(:listOf_parameterId) >> op_colon >> parameterType).as(:formalParameter) }
|
116
152
|
rule(:functionCall) { ((builtInFunction | functionRef) >> actualParameterList.maybe).as(:functionCall) }
|
117
153
|
rule(:functionDecl) { (functionHead >> algorithmHead >> stmt.repeat(1).as(:stmt) >> tEND_FUNCTION >> op_delim).as(:functionDecl) }
|
118
|
-
rule(:functionHead)
|
119
|
-
|
120
|
-
|
154
|
+
rule(:functionHead) do
|
155
|
+
(tFUNCTION >> functionId >>
|
156
|
+
(op_leftparen >> (formalParameter >> (op_delim >> formalParameter).repeat).as(:listOf_formalParameter) >> op_rightparen).maybe >>
|
157
|
+
op_colon >> parameterType >> (op_delim.as(:op_delim2))
|
158
|
+
).as(:functionHead)
|
159
|
+
end
|
160
|
+
rule(:functionId) { simpleId.as(:functionId) }
|
161
|
+
rule(:functionRef) { functionId.as(:functionRef) }
|
121
162
|
rule(:generalAggregationTypes) { (generalArrayType | generalBagType | generalListType | generalSetType).as(:generalAggregationTypes) }
|
122
163
|
rule(:generalArrayType) { (tARRAY >> boundSpec.maybe >> tOF >> tOPTIONAL.maybe >> tUNIQUE.maybe >> parameterType).as(:generalArrayType) }
|
123
164
|
rule(:generalBagType) { (tBAG >> boundSpec.maybe >> tOF >> parameterType).as(:generalBagType) }
|
@@ -129,43 +170,59 @@ module Expressir
|
|
129
170
|
rule(:genericType) { (tGENERIC >> (op_colon >> typeLabel).maybe).as(:genericType) }
|
130
171
|
rule(:groupQualifier) { (op_double_backslash >> entityRef).as(:groupQualifier) }
|
131
172
|
rule(:hexDigit) { match["0-9a-fA-F"] }
|
132
|
-
rule(:ifStmtElseStatements) {
|
133
|
-
rule(:ifStmtStatements) {
|
173
|
+
rule(:ifStmtElseStatements) { stmt.repeat(1).as(:stmt).as(:ifStmtElseStatements) }
|
174
|
+
rule(:ifStmtStatements) { stmt.repeat(1).as(:stmt).as(:ifStmtStatements) }
|
134
175
|
rule(:ifStmt) { (tIF >> logicalExpression >> tTHEN >> ifStmtStatements >> (tELSE >> ifStmtElseStatements).maybe >> tEND_IF >> op_delim).as(:ifStmt) }
|
135
176
|
rule(:incrementControl) { (variableId >> op_decl >> bound1 >> tTO >> bound2 >> (tBY >> increment).maybe).as(:incrementControl) }
|
136
|
-
rule(:increment) {
|
137
|
-
rule(:index1) {
|
138
|
-
rule(:index2) {
|
139
|
-
rule(:index) {
|
177
|
+
rule(:increment) { numericExpression.as(:increment) }
|
178
|
+
rule(:index1) { index.as(:index1) }
|
179
|
+
rule(:index2) { index.as(:index2) }
|
180
|
+
rule(:index) { numericExpression.as(:index) }
|
140
181
|
rule(:indexQualifier) { (op_leftbracket >> index1 >> (op_colon >> index2).maybe >> op_rightbracket).as(:indexQualifier) }
|
141
182
|
rule(:instantiableType) { (concreteTypes | entityRef).as(:instantiableType) }
|
142
183
|
rule(:integerLiteral) { cts(digits.as(:str)).as(:integerLiteral) }
|
143
|
-
rule(:integerType) {
|
184
|
+
rule(:integerType) { tINTEGER.as(:integerType) }
|
144
185
|
rule(:interfaceSpecification) { (referenceClause | useClause).as(:interfaceSpecification) }
|
145
|
-
rule(:intervalHigh) {
|
146
|
-
rule(:intervalItem) {
|
147
|
-
rule(:intervalLow) {
|
148
|
-
rule(:interval)
|
186
|
+
rule(:intervalHigh) { simpleExpression.as(:intervalHigh) }
|
187
|
+
rule(:intervalItem) { simpleExpression.as(:intervalItem) }
|
188
|
+
rule(:intervalLow) { simpleExpression.as(:intervalLow) }
|
189
|
+
rule(:interval) do
|
190
|
+
(op_left_curly_brace >> intervalLow >> intervalOp >> intervalItem >> (intervalOp.as(:intervalOp2)) >>
|
191
|
+
intervalHigh >> op_right_curly_brace
|
192
|
+
).as(:interval)
|
193
|
+
end
|
149
194
|
rule(:intervalOp) { (op_less_equal | op_less_than).as(:intervalOp) }
|
150
|
-
rule(:inverseAttr)
|
195
|
+
rule(:inverseAttr) do
|
196
|
+
(attributeDecl >> op_colon >> inverseAttrType >> tFOR >> (entityRef >> op_period).maybe >> attributeRef >> op_delim).as(:inverseAttr)
|
197
|
+
end
|
151
198
|
rule(:inverseAttrType) { (((tSET | tBAG) >> boundSpec.maybe >> tOF).maybe >> entityRef).as(:inverseAttrType) }
|
152
199
|
rule(:inverseClause) { (tINVERSE >> inverseAttr.repeat(1).as(:inverseAttr)).as(:inverseClause) }
|
153
200
|
rule(:letter) { match["a-zA-Z"] }
|
154
201
|
rule(:listType) { (tLIST >> boundSpec.maybe >> tOF >> tUNIQUE.maybe >> instantiableType).as(:listType) }
|
155
202
|
rule(:literal) { (binaryLiteral | logicalLiteral | realLiteral | integerLiteral | stringLiteral).as(:literal) }
|
156
203
|
rule(:localDecl) { (tLOCAL >> localVariable.repeat(1).as(:localVariable) >> tEND_LOCAL >> op_delim).as(:localDecl) }
|
157
|
-
rule(:localVariable)
|
158
|
-
|
204
|
+
rule(:localVariable) do
|
205
|
+
((variableId >> (op_comma >> variableId).repeat).as(:listOf_variableId) >>
|
206
|
+
op_colon >> parameterType >>
|
207
|
+
(op_decl >> expression).maybe >> op_delim
|
208
|
+
).as(:localVariable)
|
209
|
+
end
|
210
|
+
rule(:logicalExpression) { expression.as(:logicalExpression) }
|
159
211
|
rule(:logicalLiteral) { (tFALSE | tTRUE | tUNKNOWN).as(:logicalLiteral) }
|
160
|
-
rule(:logicalType) {
|
212
|
+
rule(:logicalType) { tLOGICAL.as(:logicalType) }
|
161
213
|
rule(:multiplicationLikeOp) { (op_asterisk | op_slash | tDIV | tMOD | tAND | op_double_pipe).as(:multiplicationLikeOp) }
|
162
214
|
rule(:namedTypeOrRename) { (namedTypes >> (tAS >> (entityId | typeId)).maybe).as(:namedTypeOrRename) }
|
163
215
|
rule(:namedTypes) { (entityRef | typeRef).as(:namedTypes) }
|
164
|
-
rule(:nullStmt) {
|
165
|
-
rule(:numberType) {
|
166
|
-
rule(:numericExpression) {
|
216
|
+
rule(:nullStmt) { op_delim.as(:nullStmt) }
|
217
|
+
rule(:numberType) { tNUMBER.as(:numberType) }
|
218
|
+
rule(:numericExpression) { simpleExpression.as(:numericExpression) }
|
167
219
|
rule(:octet) { hexDigit >> hexDigit }
|
168
|
-
rule(:oneOf)
|
220
|
+
rule(:oneOf) do
|
221
|
+
(
|
222
|
+
tONEOF >> op_leftparen >> (supertypeExpression >>
|
223
|
+
(op_comma >> supertypeExpression).repeat).as(:listOf_supertypeExpression) >> op_rightparen
|
224
|
+
).as(:oneOf)
|
225
|
+
end
|
169
226
|
rule(:op_asterisk) { cstr("*").as(:op_asterisk) }
|
170
227
|
rule(:op_colon) { cstr(":").as(:op_colon) }
|
171
228
|
rule(:op_colon_equals_colon) { cstr(":=:").as(:op_colon_equals_colon) }
|
@@ -174,7 +231,7 @@ module Expressir
|
|
174
231
|
rule(:op_decl) { cstr(":=").as(:op_decl) }
|
175
232
|
rule(:op_delim) { cstr(";").as(:op_delim) }
|
176
233
|
rule(:op_double_asterisk) { cstr("**").as(:op_double_asterisk) }
|
177
|
-
rule(:op_double_backslash) { cstr(
|
234
|
+
rule(:op_double_backslash) { cstr("\\").as(:op_double_backslash) }
|
178
235
|
rule(:op_double_pipe) { cstr("||").as(:op_double_pipe) }
|
179
236
|
rule(:op_equals) { cstr("=").as(:op_equals) }
|
180
237
|
rule(:op_greater_equal) { cstr(">=").as(:op_greater_equal) }
|
@@ -196,57 +253,97 @@ module Expressir
|
|
196
253
|
rule(:op_right_curly_brace) { cstr("}").as(:op_right_curly_brace) }
|
197
254
|
rule(:op_rightparen) { cstr(")").as(:op_rightparen) }
|
198
255
|
rule(:op_slash) { cstr("/").as(:op_slash) }
|
199
|
-
rule(:parameter) {
|
200
|
-
rule(:parameterId) {
|
201
|
-
rule(:parameterRef) {
|
256
|
+
rule(:parameter) { expression.as(:parameter) }
|
257
|
+
rule(:parameterId) { simpleId.as(:parameterId) }
|
258
|
+
rule(:parameterRef) { parameterId.as(:parameterRef) }
|
202
259
|
rule(:parameterType) { (generalizedTypes | namedTypes | simpleTypes).as(:parameterType) }
|
203
|
-
rule(:population) {
|
204
|
-
rule(:precisionSpec) {
|
260
|
+
rule(:population) { entityRef.as(:population) }
|
261
|
+
rule(:precisionSpec) { numericExpression.as(:precisionSpec) }
|
205
262
|
rule(:primary) { (literal | qualifiableFactor >> qualifier.repeat.as(:qualifier)).as(:primary) }
|
206
263
|
rule(:procedureCallStmt) { ((builtInProcedure | procedureRef) >> actualParameterList.maybe >> op_delim).as(:procedureCallStmt) }
|
207
264
|
rule(:procedureDecl) { (procedureHead >> algorithmHead >> stmt.repeat.as(:stmt) >> tEND_PROCEDURE >> op_delim).as(:procedureDecl) }
|
208
265
|
rule(:procedureHeadParameter) { (tVAR.maybe >> formalParameter).as(:procedureHeadParameter) }
|
209
|
-
rule(:procedureHead)
|
210
|
-
|
211
|
-
|
212
|
-
|
266
|
+
rule(:procedureHead) do
|
267
|
+
(
|
268
|
+
tPROCEDURE >> procedureId >>
|
269
|
+
(
|
270
|
+
op_leftparen >> (
|
271
|
+
procedureHeadParameter >>
|
272
|
+
(op_delim >> procedureHeadParameter).repeat
|
273
|
+
).as(:listOf_procedureHeadParameter) >> op_rightparen
|
274
|
+
).maybe >> (op_delim.as(:op_delim2))).as(:procedureHead)
|
275
|
+
end
|
276
|
+
rule(:procedureId) { simpleId.as(:procedureId) }
|
277
|
+
rule(:procedureRef) { procedureId.as(:procedureRef) }
|
278
|
+
rule(:qualifiableFactor) { (functionCall | attributeRef | constantFactor | generalRef | population).as(:qualifiableFactor) }
|
213
279
|
rule(:qualifiedAttribute) { (tSELF >> groupQualifier >> attributeQualifier).as(:qualifiedAttribute) }
|
214
280
|
rule(:qualifier) { (attributeQualifier | groupQualifier | indexQualifier).as(:qualifier) }
|
215
|
-
rule(:queryExpression)
|
281
|
+
rule(:queryExpression) do
|
282
|
+
(tQUERY >> op_leftparen >> variableId >> op_query_begin >> aggregateSource >> op_pipe >> logicalExpression >> op_rightparen).as(:queryExpression)
|
283
|
+
end
|
216
284
|
rule(:realLiteral) { cts((digits >> str(".") >> digits.maybe >> (match["eE"] >> sign.maybe >> digits).maybe).as(:str)).as(:realLiteral) }
|
217
285
|
rule(:realType) { (tREAL >> (op_leftparen >> precisionSpec >> op_rightparen).maybe).as(:realType) }
|
218
286
|
rule(:redeclaredAttribute) { (qualifiedAttribute >> (tRENAMED >> attributeId).maybe).as(:redeclaredAttribute) }
|
219
|
-
rule(:referenceClause)
|
287
|
+
rule(:referenceClause) do
|
288
|
+
(
|
289
|
+
tREFERENCE >> tFROM >> schemaRef >>
|
290
|
+
(op_leftparen >> (resourceOrRename >> (
|
291
|
+
op_comma >> resourceOrRename
|
292
|
+
).repeat).as(:listOf_resourceOrRename) >> op_rightparen).maybe >> op_delim
|
293
|
+
).as(:referenceClause)
|
294
|
+
end
|
220
295
|
rule(:referencedAttribute) { (attributeRef | qualifiedAttribute).as(:referencedAttribute) }
|
221
296
|
rule(:relOpExtended) { (relOp | tIN | tLIKE).as(:relOpExtended) }
|
222
|
-
rule(:relOp)
|
297
|
+
rule(:relOp) do
|
298
|
+
(
|
299
|
+
op_less_equal | op_greater_equal | op_less_greater | op_less_than | op_greater_than | op_equals |
|
300
|
+
op_colon_less_greater_colon | op_colon_equals_colon
|
301
|
+
).as(:relOp)
|
302
|
+
end
|
223
303
|
rule(:renameId) { (constantId | entityId | functionId | procedureId | typeId).as(:renameId) }
|
224
304
|
rule(:repeatControl) { (incrementControl.maybe >> whileControl.maybe >> untilControl.maybe).as(:repeatControl) }
|
225
305
|
rule(:repeatStmt) { (tREPEAT >> repeatControl >> op_delim >> stmt.repeat(1).as(:stmt) >> tEND_REPEAT >> (op_delim.as(:op_delim2))).as(:repeatStmt) }
|
226
|
-
rule(:repetition) {
|
306
|
+
rule(:repetition) { numericExpression.as(:repetition) }
|
227
307
|
rule(:resourceOrRename) { (resourceRef >> (tAS >> renameId).maybe).as(:resourceOrRename) }
|
228
308
|
rule(:resourceRef) { (constantRef | entityRef | functionRef | procedureRef | typeRef).as(:resourceRef) }
|
229
309
|
rule(:returnStmt) { (tRETURN >> (op_leftparen >> expression >> op_rightparen).maybe >> op_delim).as(:returnStmt) }
|
230
310
|
rule(:ruleDecl) { (ruleHead >> algorithmHead >> stmt.repeat.as(:stmt) >> whereClause >> tEND_RULE >> op_delim).as(:ruleDecl) }
|
231
|
-
rule(:ruleHead)
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
311
|
+
rule(:ruleHead) do
|
312
|
+
(
|
313
|
+
tRULE >> ruleId >> tFOR >> op_leftparen >>
|
314
|
+
(entityRef >> (op_comma >> entityRef).repeat).as(:listOf_entityRef) >> op_rightparen >> op_delim
|
315
|
+
).as(:ruleHead)
|
316
|
+
end
|
317
|
+
rule(:ruleId) { simpleId.as(:ruleId) }
|
318
|
+
rule(:ruleLabelId) { simpleId.as(:ruleLabelId) }
|
319
|
+
rule(:ruleLabelRef) { ruleLabelId.as(:ruleLabelRef) }
|
320
|
+
rule(:ruleRef) { ruleId.as(:ruleRef) }
|
236
321
|
rule(:schemaBodyDeclaration) { (declaration | ruleDecl).as(:schemaBodyDeclaration) }
|
237
|
-
rule(:schemaBody)
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
322
|
+
rule(:schemaBody) do
|
323
|
+
(
|
324
|
+
interfaceSpecification.repeat.as(:interfaceSpecification) >> constantDecl.maybe >>
|
325
|
+
schemaBodyDeclaration.repeat.as(:schemaBodyDeclaration)
|
326
|
+
).as(:schemaBody)
|
327
|
+
end
|
328
|
+
rule(:schemaDecl) do
|
329
|
+
(tSCHEMA >> schemaId >> schemaVersionId.maybe >> op_delim >> schemaBody >> tEND_SCHEMA >> (op_delim.as(:op_delim2))).as(:schemaDecl)
|
330
|
+
end
|
331
|
+
rule(:schemaId) { simpleId.as(:schemaId) }
|
332
|
+
rule(:schemaRef) { schemaId.as(:schemaRef) }
|
333
|
+
rule(:schemaVersionId) { stringLiteral.as(:schemaVersionId) }
|
242
334
|
rule(:selectExtension) { (tBASED_ON >> typeRef >> (tWITH >> selectList).maybe).as(:selectExtension) }
|
243
335
|
rule(:selectList) { (op_leftparen >> (namedTypes >> (op_comma >> namedTypes).repeat).as(:listOf_namedTypes) >> op_rightparen).as(:selectList) }
|
244
|
-
rule(:selector) {
|
336
|
+
rule(:selector) { expression.as(:selector) }
|
245
337
|
rule(:selectType) { ((tEXTENSIBLE >> tGENERIC_ENTITY.maybe).maybe >> tSELECT >> (selectList | selectExtension).maybe).as(:selectType) }
|
246
338
|
rule(:setType) { (tSET >> boundSpec.maybe >> tOF >> instantiableType).as(:setType) }
|
247
339
|
rule(:sign) { match["+-"] }
|
248
340
|
rule(:simpleExpression) { (term >> (addLikeOp.as(:operator) >> term).as(:item).repeat.as(:rhs)).as(:simpleExpression) }
|
249
|
-
rule(:simpleFactor)
|
341
|
+
rule(:simpleFactor) do
|
342
|
+
(
|
343
|
+
aggregateInitializer | entityConstructor | interval | queryExpression | simpleFactorExpression |
|
344
|
+
simpleFactorUnaryExpression | enumerationReference
|
345
|
+
).as(:simpleFactor)
|
346
|
+
end
|
250
347
|
rule(:simpleFactorExpression) { (op_leftparen >> expression >> op_rightparen | primary).as(:simpleFactorExpression) }
|
251
348
|
rule(:simpleFactorUnaryExpression) { (unaryOp >> simpleFactorExpression).as(:simpleFactorUnaryExpression) }
|
252
349
|
rule(:simpleId) { anyKeyword.absent? >> cts((match["a-zA-Z_"] >> match["a-zA-Z0-9_"].repeat).as(:str)).as(:simpleId) }
|
@@ -255,17 +352,24 @@ module Expressir
|
|
255
352
|
rule(:skipStmt) { (tSKIP >> op_delim).as(:skipStmt) }
|
256
353
|
rule(:space) { match[" \r\n\t\f"] | embeddedRemark | tailRemark }
|
257
354
|
rule(:spaces) { space.repeat.as(:spaces) }
|
258
|
-
rule(:stmt)
|
355
|
+
rule(:stmt) do
|
356
|
+
(
|
357
|
+
aliasStmt | assignmentStmt | caseStmt | compoundStmt | escapeStmt | ifStmt |
|
358
|
+
nullStmt | procedureCallStmt | repeatStmt | returnStmt | skipStmt
|
359
|
+
).as(:stmt)
|
360
|
+
end
|
259
361
|
rule(:stringLiteral) { (simpleStringLiteral | encodedStringLiteral).as(:stringLiteral) }
|
260
362
|
rule(:stringType) { (tSTRING >> widthSpec.maybe).as(:stringType) }
|
261
363
|
rule(:subsuper) { (supertypeConstraint.maybe >> subtypeDeclaration.maybe).as(:subsuper) }
|
262
364
|
rule(:subtypeConstraintBody) { (abstractSupertype.maybe >> totalOver.maybe >> (supertypeExpression >> op_delim).maybe).as(:subtypeConstraintBody) }
|
263
365
|
rule(:subtypeConstraintDecl) { (subtypeConstraintHead >> subtypeConstraintBody >> tEND_SUBTYPE_CONSTRAINT >> op_delim).as(:subtypeConstraintDecl) }
|
264
366
|
rule(:subtypeConstraintHead) { (tSUBTYPE_CONSTRAINT >> subtypeConstraintId >> tFOR >> entityRef >> op_delim).as(:subtypeConstraintHead) }
|
265
|
-
rule(:subtypeConstraintId) {
|
266
|
-
rule(:subtypeConstraintRef) {
|
367
|
+
rule(:subtypeConstraintId) { simpleId.as(:subtypeConstraintId) }
|
368
|
+
rule(:subtypeConstraintRef) { subtypeConstraintId.as(:subtypeConstraintRef) }
|
267
369
|
rule(:subtypeConstraint) { (tOF >> op_leftparen >> supertypeExpression >> op_rightparen).as(:subtypeConstraint) }
|
268
|
-
rule(:subtypeDeclaration)
|
370
|
+
rule(:subtypeDeclaration) do
|
371
|
+
(tSUBTYPE >> tOF >> op_leftparen >> entityRef >> (op_comma >> entityRef).repeat >> op_rightparen).as(:listOf_entityRef).as(:subtypeDeclaration)
|
372
|
+
end
|
269
373
|
rule(:supertypeConstraint) { (abstractSupertypeDeclaration | abstractEntityDeclaration | supertypeRule).as(:supertypeConstraint) }
|
270
374
|
rule(:supertypeExpression) { (supertypeFactor >> (tANDOR.as(:operator) >> supertypeFactor).as(:item).repeat.as(:rhs)).as(:supertypeExpression) }
|
271
375
|
rule(:supertypeFactor) { (supertypeTerm >> (tAND.as(:operator) >> supertypeTerm).as(:item).repeat.as(:rhs)).as(:supertypeFactor) }
|
@@ -274,24 +378,44 @@ module Expressir
|
|
274
378
|
rule(:syntax) { (spaces.as(:spaces) >> schemaDecl.repeat(1).as(:schemaDecl) >> spaces.as(:trailer)).as(:syntax) }
|
275
379
|
rule(:tailRemark) { (str("--") >> (str("\n").absent? >> any).repeat >> str("\n")).as(:tailRemark) }
|
276
380
|
rule(:term) { (factor >> (multiplicationLikeOp >> factor).as(:item).repeat.as(:rhs)).as(:term) }
|
277
|
-
rule(:totalOver)
|
278
|
-
|
279
|
-
|
280
|
-
rule(:
|
281
|
-
|
381
|
+
rule(:totalOver) do
|
382
|
+
(tTOTAL_OVER >> op_leftparen >> (entityRef >> (op_comma >> entityRef).repeat).as(:listOf_entityRef) >> op_rightparen >> op_delim).as(:totalOver)
|
383
|
+
end
|
384
|
+
rule(:typeDecl) do
|
385
|
+
(tTYPE >> typeId >> op_equals >> underlyingType >> op_delim >> whereClause.maybe >> tEND_TYPE >> (op_delim.as(:op_delim2))).as(:typeDecl)
|
386
|
+
end
|
387
|
+
rule(:typeId) { simpleId.as(:typeId) }
|
388
|
+
rule(:typeLabelId) { simpleId.as(:typeLabelId) }
|
389
|
+
rule(:typeLabelRef) { typeLabelId.as(:typeLabelRef) }
|
282
390
|
rule(:typeLabel) { (typeLabelId | typeLabelRef).as(:typeLabel) }
|
283
|
-
rule(:typeRef) {
|
391
|
+
rule(:typeRef) { typeId.as(:typeRef) }
|
284
392
|
rule(:unaryOp) { (op_plus | op_minus | tNOT).as(:unaryOp) }
|
285
393
|
rule(:underlyingType) { (concreteTypes | constructedTypes).as(:underlyingType) }
|
286
|
-
rule(:uniqueClause)
|
287
|
-
|
394
|
+
rule(:uniqueClause) do
|
395
|
+
(tUNIQUE >> (uniqueRule >> op_delim >> (uniqueRule >> (op_delim.as(:op_delim2))).repeat).as(:listOf_uniqueRule)).as(:uniqueClause)
|
396
|
+
end
|
397
|
+
rule(:uniqueRule) do
|
398
|
+
((ruleLabelId >> op_colon).maybe >> (referencedAttribute >> (op_comma >> referencedAttribute).repeat).as(:listOf_referencedAttribute)).as(:uniqueRule)
|
399
|
+
end
|
288
400
|
rule(:untilControl) { (tUNTIL >> logicalExpression).as(:untilControl) }
|
289
|
-
rule(:useClause)
|
290
|
-
|
291
|
-
|
401
|
+
rule(:useClause) do
|
402
|
+
(
|
403
|
+
tUSE >> tFROM >> schemaRef >>
|
404
|
+
(
|
405
|
+
op_leftparen >> (
|
406
|
+
namedTypeOrRename >> (
|
407
|
+
op_comma >>
|
408
|
+
namedTypeOrRename
|
409
|
+
).repeat
|
410
|
+
).as(:listOf_namedTypeOrRename) >> op_rightparen
|
411
|
+
).maybe >> op_delim
|
412
|
+
).as(:useClause)
|
413
|
+
end
|
414
|
+
rule(:variableId) { simpleId.as(:variableId) }
|
415
|
+
rule(:variableRef) { variableId.as(:variableRef) }
|
292
416
|
rule(:whereClause) { (tWHERE >> (domainRule >> op_delim).repeat.as(:listOf_domainRule)).as(:whereClause) }
|
293
417
|
rule(:whileControl) { (tWHILE >> logicalExpression).as(:whileControl) }
|
294
|
-
rule(:width) {
|
418
|
+
rule(:width) { numericExpression.as(:width) }
|
295
419
|
rule(:widthSpec) { (op_leftparen >> width >> op_rightparen >> tFIXED.maybe).as(:widthSpec) }
|
296
420
|
end
|
297
421
|
|
@@ -326,9 +450,9 @@ module Expressir
|
|
326
450
|
# @param [Boolean] include_source attach original source code to model elements
|
327
451
|
# @return [Model::Repository]
|
328
452
|
def self.from_files(files, skip_references: nil, include_source: nil)
|
329
|
-
schemas = files.each_with_index.map do |file,
|
453
|
+
schemas = files.each_with_index.map do |file, _i|
|
330
454
|
# start = Time.now
|
331
|
-
repository =
|
455
|
+
repository = from_file(file, skip_references: true)
|
332
456
|
# STDERR.puts "#{i+1}/#{files.length} #{file} #{Time.now - start}"
|
333
457
|
repository.schemas
|
334
458
|
end.flatten
|
@@ -17,15 +17,15 @@ module Expressir
|
|
17
17
|
def visit_references_simple_reference(node)
|
18
18
|
return if node.parent.is_a? Model::References::AttributeReference
|
19
19
|
|
20
|
-
if node.parent.is_a? Model::Declarations::InterfaceItem
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
base_item = if node.parent.is_a? Model::Declarations::InterfaceItem
|
21
|
+
node.find("#{node.parent.parent.schema.id}.#{node.parent.ref.id}")
|
22
|
+
else
|
23
|
+
node.find(node.id)
|
24
|
+
end
|
25
25
|
return unless base_item
|
26
26
|
|
27
27
|
node.base_path = base_item.path
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
@@ -8,8 +8,8 @@ module Expressir
|
|
8
8
|
module SchemaHeadFormatter
|
9
9
|
# @!visibility private
|
10
10
|
def self.included(mod)
|
11
|
-
if !mod.superclass.private_method_defined?
|
12
|
-
raise
|
11
|
+
if !mod.superclass.private_method_defined?(:format_declarations_schema) || !mod.superclass.private_method_defined?(:format_declarations_schema_head)
|
12
|
+
raise "Missing method"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -20,4 +20,4 @@ module Expressir
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|