expressir 2.4.47 → 2.4.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/_guides/reference/grammar-crosswalk.adoc +1 -0
- data/expressir.gemspec +1 -1
- data/grammar-parg/CONVENTIONS.md +90 -0
- data/grammar-parg/RULE-INVENTORY.txt +252 -0
- data/grammar-parg/atoms_to_parg.rb +232 -0
- data/grammar-parg/bisect.sh +37 -0
- data/grammar-parg/ddmin.sh +39 -0
- data/grammar-parg/dsl-dump.json +1 -0
- data/grammar-parg/entries.parg.frag +12 -0
- data/grammar-parg/express-grammar.artifact.json +1 -0
- data/grammar-parg/express-grammar.parg +381 -0
- data/grammar-parg/express.json +1 -0
- data/grammar-parg/express.parg +57 -0
- data/grammar-parg/express_keywords.parg +132 -0
- data/grammar-parg/express_literals.parg +14 -0
- data/grammar-parg/express_operators.parg +34 -0
- data/grammar-parg/express_remarks.parg +19 -0
- data/grammar-parg/express_structure.parg +11 -0
- data/grammar-parg/generate-terminals.rb +55 -0
- data/grammar-parg/keywords.parg.frag +130 -0
- data/grammar-parg/literals.parg.frag +9 -0
- data/grammar-parg/operators.parg.frag +34 -0
- data/grammar-parg/parity-model.rb +68 -0
- data/grammar-parg/parity-vm.rb +60 -0
- data/grammar-parg/parity.sh +66 -0
- data/grammar-parg/parser-dsl-reference.rb.txt +757 -0
- data/grammar-parg/splice.rb +16 -0
- data/grammar-parg/tree_diff.rb +62 -0
- data/lib/expressir/express/grammar/express-grammar.artifact.json +1 -0
- data/lib/expressir/express/grammar/parser.rb +55 -1
- data/lib/expressir/express/parser.rb +3 -3
- data/lib/expressir/express/remark_attacher.rb +4 -2
- data/lib/expressir/model/model_element.rb +3 -0
- data/lib/expressir/reference/grammar_crosswalk.yml +3 -0
- data/lib/expressir/version.rb +1 -1
- metadata +31 -10
|
@@ -0,0 +1,757 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "parsanol"
|
|
4
|
+
|
|
5
|
+
module Expressir
|
|
6
|
+
module Express
|
|
7
|
+
module Grammar
|
|
8
|
+
# EXPRESS grammar definition: ~250 Parsanol rules implementing
|
|
9
|
+
# ISO 10303-11 concrete syntax.
|
|
10
|
+
#
|
|
11
|
+
# Extracted from the outer Parser class so grammar changes land in
|
|
12
|
+
# one focused file, separate from the I/O orchestration on the
|
|
13
|
+
# Parser facade (lib/expressir/express/parser.rb).
|
|
14
|
+
class Parser < Parsanol::Parser
|
|
15
|
+
root(:syntax)
|
|
16
|
+
|
|
17
|
+
# Class instance variables for caching (not @@ class variables,
|
|
18
|
+
# which are shared across the entire hierarchy). These are scoped
|
|
19
|
+
# to this class only. Accessed via @var within class methods.
|
|
20
|
+
@cached_grammar_json = nil
|
|
21
|
+
@cached_grammar_atom_id = nil
|
|
22
|
+
@cached_parser = nil
|
|
23
|
+
@parser_mutex = Mutex.new
|
|
24
|
+
@cached_schema_grammar_json = nil
|
|
25
|
+
|
|
26
|
+
# Threshold for using memory-bounded fresh parse (bytes)
|
|
27
|
+
# Files above this use parse_fresh which has no packrat cache
|
|
28
|
+
LARGE_FILE_THRESHOLD = 1024 * 1024 # 1 MB
|
|
29
|
+
|
|
30
|
+
# Whitespace rides the engine's injected trivia (parsanol-ruby
|
|
31
|
+
# #180's source-preserving mode, 1.3.82+): each unit records
|
|
32
|
+
# verbatim under :space and attaches to the next Named capture.
|
|
33
|
+
# Remarks stay OUT of the skip rule — they are product data,
|
|
34
|
+
# captured by the tailRemark/embeddedRemark rules and attached
|
|
35
|
+
# by RemarkScanner; tail remarks attach backward, the engine's
|
|
36
|
+
# next-capture channel is the wrong direction for them.
|
|
37
|
+
rule(:trivia) { match[" \r\n\t\f"].repeat(1) }
|
|
38
|
+
# exempt (parsanol#195, shipped 1.3.89): token rules whose bodies
|
|
39
|
+
# manage their own internals — injection before a char-class tail
|
|
40
|
+
# repetition absorbs the following token across whitespace
|
|
41
|
+
# ("RULE r FOR" parsed as one simpleId). simpleId additionally
|
|
42
|
+
# matches as a single quantified Re, which needs no exemption;
|
|
43
|
+
# the two mechanisms agree and stay for defense in depth.
|
|
44
|
+
# The whitespace/remark rules manage their own trivia end to end
|
|
45
|
+
# (they ARE the trivia surface for remarks); injection around
|
|
46
|
+
# them breaks consecutive remark lines on the Ruby engine
|
|
47
|
+
# ("-- X\n--\nSCHEMA ..." failed - the #487 windows follow-up,
|
|
48
|
+
# parsanol-ruby#195 family).
|
|
49
|
+
skip(:trivia, whitespace: :space,
|
|
50
|
+
exempt: %i[simpleId digits spaces space embeddedRemark tailRemark])
|
|
51
|
+
|
|
52
|
+
# Get cached parser instance (thread-safe)
|
|
53
|
+
# Reusing the parser avoids the overhead of reinitializing all rule definitions
|
|
54
|
+
def self.cached_parser
|
|
55
|
+
return @cached_parser if @cached_parser
|
|
56
|
+
|
|
57
|
+
@parser_mutex.synchronize do
|
|
58
|
+
@cached_parser ||= new
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Clear the cached parser (useful for testing or after grammar changes)
|
|
63
|
+
def self.clear_parser_cache
|
|
64
|
+
@parser_mutex.synchronize do
|
|
65
|
+
@cached_parser = nil
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Check if native parsing is available
|
|
70
|
+
def self.native_available?
|
|
71
|
+
return @native_available unless @native_available.nil?
|
|
72
|
+
|
|
73
|
+
@native_available = begin
|
|
74
|
+
require "parsanol/native"
|
|
75
|
+
Parsanol::Native.available?
|
|
76
|
+
rescue LoadError
|
|
77
|
+
false
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Get cached grammar JSON for native parsing
|
|
82
|
+
def self.cached_grammar_json
|
|
83
|
+
return @cached_grammar_json if @cached_grammar_json
|
|
84
|
+
|
|
85
|
+
parser = new
|
|
86
|
+
atom = parser.syntax
|
|
87
|
+
|
|
88
|
+
# Cache by atom object_id
|
|
89
|
+
if atom.object_id != @cached_grammar_atom_id
|
|
90
|
+
@cached_grammar_atom_id = atom.object_id
|
|
91
|
+
@cached_grammar_json = Parsanol::Native.serialize_grammar(atom)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
@cached_grammar_json
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Get cached grammar JSON for schemaDecl (used for streaming parse)
|
|
98
|
+
def self.cached_schema_grammar_json
|
|
99
|
+
return @cached_schema_grammar_json if @cached_schema_grammar_json
|
|
100
|
+
|
|
101
|
+
schema_atom = cached_parser.schemaDecl
|
|
102
|
+
@cached_schema_grammar_json = Parsanol::Native.serialize_grammar(schema_atom)
|
|
103
|
+
@cached_schema_grammar_json
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Parse using native engine with Rust-side transformation (fastest)
|
|
107
|
+
#
|
|
108
|
+
# This method provides ~17x speedup over pure Ruby parsing.
|
|
109
|
+
# The transformation happens in Rust using to_parslet_compatible,
|
|
110
|
+
# producing Parslet-compatible output that Builder.build can consume directly.
|
|
111
|
+
#
|
|
112
|
+
# @param source [String] EXPRESS source code to parse
|
|
113
|
+
# @return [Hash, Array] Transformed AST in Parslet-compatible format
|
|
114
|
+
# @raise [LoadError] If native parser is not available
|
|
115
|
+
def self.parse_native(source)
|
|
116
|
+
unless native_available?
|
|
117
|
+
raise LoadError, "Native parser not available"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
grammar_atom = cached_parser.syntax
|
|
121
|
+
# Use fresh-parse (no cache) for large files to bound memory
|
|
122
|
+
if source.bytesize > LARGE_FILE_THRESHOLD
|
|
123
|
+
Parsanol::Native.parse_fresh(grammar_atom, source)
|
|
124
|
+
else
|
|
125
|
+
Parsanol::Native.parse(grammar_atom, source)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def cts(atom)
|
|
130
|
+
spaces >> atom
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def cstr(atom)
|
|
134
|
+
cts(str(atom).as(:str))
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
KEYWORDS = %i[
|
|
138
|
+
ABS ABSTRACT ACOS AGGREGATE ALIAS AND ANDOR ARRAY AS ASIN ATAN BAG BASED_ON
|
|
139
|
+
BEGIN BINARY BLENGTH BOOLEAN BY CASE CONSTANT CONST_E COS DERIVE DIV ELSE
|
|
140
|
+
END END_ALIAS END_CASE END_CONSTANT END_ENTITY END_FUNCTION END_IF
|
|
141
|
+
END_LOCAL END_PROCEDURE END_REPEAT END_RULE END_SCHEMA
|
|
142
|
+
END_SUBTYPE_CONSTRAINT END_TYPE ENTITY ENUMERATION ESCAPE EXISTS EXP
|
|
143
|
+
EXTENSIBLE FALSE FIXED FOR FORMAT FROM FUNCTION GENERIC GENERIC_ENTITY
|
|
144
|
+
HIBOUND HIINDEX IF IN INSERT INTEGER INVERSE LENGTH LIKE LIST LOBOUND LOCAL
|
|
145
|
+
LOG LOG10 LOG2 LOGICAL LOINDEX MOD NOT NUMBER NVL ODD OF ONEOF OPTIONAL OR
|
|
146
|
+
OTHERWISE PI PROCEDURE QUERY REAL REFERENCE REMOVE RENAMED REPEAT RETURN
|
|
147
|
+
ROLESOF RULE SCHEMA SELECT SELF SET SIN SIZEOF SKIP SQRT STRING SUBTYPE
|
|
148
|
+
SUBTYPE_CONSTRAINT SUPERTYPE TAN THEN TO TRUE TYPE TYPEOF TOTAL_OVER UNIQUE
|
|
149
|
+
UNKNOWN UNTIL USE USEDIN VALUE VALUE_IN VALUE_UNIQUE VAR WITH WHERE WHILE
|
|
150
|
+
XOR
|
|
151
|
+
].freeze
|
|
152
|
+
|
|
153
|
+
def keyword_rule(str)
|
|
154
|
+
key_chars = str.to_s.chars
|
|
155
|
+
key_chars
|
|
156
|
+
.collect! { |char| match("[#{char}#{char.downcase}]") }
|
|
157
|
+
.reduce(:>>) >> match["a-zA-Z0-9_"].absent?
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
KEYWORDS.each do |keyword|
|
|
161
|
+
sym = :"t#{keyword}"
|
|
162
|
+
rule(sym) { cts(keyword_rule(keyword).as(:str)).as(sym) }
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
rule(:abstractEntityDeclaration) do
|
|
166
|
+
tABSTRACT.as(:abstractEntityDeclaration)
|
|
167
|
+
end
|
|
168
|
+
rule(:abstractSupertypeDeclaration) do
|
|
169
|
+
(tABSTRACT >> tSUPERTYPE >> subtypeConstraint.maybe).as(:abstractSupertypeDeclaration)
|
|
170
|
+
end
|
|
171
|
+
# ISO 10303-11 abstract_supertype_constraint = ABSTRACT ';' —
|
|
172
|
+
# tolerated nonstandard variant: ABSTRACT SUPERTYPE ';' (real
|
|
173
|
+
# corpora ship it; longest-first so PEG stays deterministic).
|
|
174
|
+
# The entity-header forms live in abstractSupertypeDeclaration.
|
|
175
|
+
rule(:abstractSupertype) do
|
|
176
|
+
(
|
|
177
|
+
(tABSTRACT >> tSUPERTYPE >> op_delim) |
|
|
178
|
+
(tABSTRACT >> op_delim)
|
|
179
|
+
).as(:abstractSupertype)
|
|
180
|
+
end
|
|
181
|
+
rule(:actualParameterList) do
|
|
182
|
+
(op_leftparen >> (parameter >> (op_comma >> parameter).repeat).as(:listOf_parameter).maybe >> op_rightparen)
|
|
183
|
+
.as(:actualParameterList)
|
|
184
|
+
end
|
|
185
|
+
rule(:addLikeOp) { (op_plus | op_minus | tOR | tXOR).as(:addLikeOp) }
|
|
186
|
+
rule(:aggregateInitializer) do
|
|
187
|
+
(op_leftbracket >> (element >> (op_comma >> element).repeat).as(:listOf_element).maybe >> op_rightbracket)
|
|
188
|
+
.as(:aggregateInitializer)
|
|
189
|
+
end
|
|
190
|
+
rule(:aggregateSource) { simpleExpression.as(:aggregateSource) }
|
|
191
|
+
rule(:aggregateType) do
|
|
192
|
+
(tAGGREGATE >> (op_colon >> typeLabel).maybe >> tOF >> parameterType).as(:aggregateType)
|
|
193
|
+
end
|
|
194
|
+
rule(:aggregationTypes) do
|
|
195
|
+
(arrayType | bagType | listType | setType).as(:aggregationTypes)
|
|
196
|
+
end
|
|
197
|
+
rule(:algorithmHead) do
|
|
198
|
+
(declaration.repeat.as(:declaration) >> constantDecl.maybe >> localDecl.maybe).as(:algorithmHead)
|
|
199
|
+
end
|
|
200
|
+
rule(:aliasStmt) do
|
|
201
|
+
(tALIAS >> variableId >> tFOR >> generalRef >> qualifier.repeat.as(:qualifier) >>
|
|
202
|
+
op_delim >> stmt.repeat(1).as(:stmt) >> tEND_ALIAS >> op_delim.as(:op_delim2)).as(:aliasStmt)
|
|
203
|
+
end
|
|
204
|
+
rule(:anyKeyword) { KEYWORDS.map { |kw| send("t#{kw}") }.inject(:|) }
|
|
205
|
+
rule(:arrayType) do
|
|
206
|
+
(tARRAY >> boundSpec >> tOF >> tOPTIONAL.maybe >> tUNIQUE.maybe >> instantiableType).as(:arrayType)
|
|
207
|
+
end
|
|
208
|
+
rule(:assignmentStmt) do
|
|
209
|
+
(generalRef >> qualifier.repeat.as(:qualifier) >> op_decl >> expression >> op_delim).as(:assignmentStmt)
|
|
210
|
+
end
|
|
211
|
+
rule(:attributeDecl) do
|
|
212
|
+
(attributeId | redeclaredAttribute).as(:attributeDecl)
|
|
213
|
+
end
|
|
214
|
+
rule(:attributeId) { simpleId.as(:attributeId) }
|
|
215
|
+
rule(:attributeQualifier) do
|
|
216
|
+
(op_period >> attributeRef).as(:attributeQualifier)
|
|
217
|
+
end
|
|
218
|
+
rule(:attributeRef) { attributeId.as(:attributeRef) }
|
|
219
|
+
rule(:bagType) do
|
|
220
|
+
(tBAG >> boundSpec.maybe >> tOF >> instantiableType).as(:bagType)
|
|
221
|
+
end
|
|
222
|
+
rule(:binaryLiteral) do
|
|
223
|
+
cts((str("%") >> bit.repeat(1)).as(:str)).as(:binaryLiteral)
|
|
224
|
+
end
|
|
225
|
+
rule(:binaryType) { (tBINARY >> widthSpec.maybe).as(:binaryType) }
|
|
226
|
+
rule(:bit) { match["0-1"] }
|
|
227
|
+
rule(:booleanType) { tBOOLEAN.as(:booleanType) }
|
|
228
|
+
rule(:bound1) { numericExpression.as(:bound1) }
|
|
229
|
+
rule(:bound2) { numericExpression.as(:bound2) }
|
|
230
|
+
rule(:boundSpec) do
|
|
231
|
+
(op_leftbracket >> bound1 >> op_colon >> bound2 >> op_rightbracket).as(:boundSpec)
|
|
232
|
+
end
|
|
233
|
+
rule(:builtInConstant) do
|
|
234
|
+
(tCONST_E | tPI | tSELF | op_question_mark).as(:builtInConstant)
|
|
235
|
+
end
|
|
236
|
+
rule(:builtInFunction) do
|
|
237
|
+
(tABS | tACOS | tASIN | tATAN | tBLENGTH | tCOS | tEXISTS | tEXP | tFORMAT | tHIBOUND | tHIINDEX | tLENGTH |
|
|
238
|
+
tLOBOUND | tLOINDEX | tLOG2 | tLOG10 | tLOG | tNVL | tODD | tROLESOF | tSIN | tSIZEOF | tSQRT | tTAN |
|
|
239
|
+
tTYPEOF | tUSEDIN | tVALUE_IN | tVALUE_UNIQUE | tVALUE).as(:builtInFunction)
|
|
240
|
+
end
|
|
241
|
+
rule(:builtInProcedure) { (tINSERT | tREMOVE).as(:builtInProcedure) }
|
|
242
|
+
rule(:caseAction) do
|
|
243
|
+
((caseLabel >> (op_comma >> caseLabel).repeat).as(:listOf_caseLabel) >> op_colon >> stmt).as(:caseAction)
|
|
244
|
+
end
|
|
245
|
+
rule(:caseLabel) { expression.as(:caseLabel) }
|
|
246
|
+
rule(:caseStmt) do
|
|
247
|
+
(tCASE >> selector >> tOF >> caseAction.repeat.as(:caseAction) >> (tOTHERWISE >> op_colon >> stmt).maybe >> tEND_CASE >> op_delim).as(:caseStmt)
|
|
248
|
+
end
|
|
249
|
+
rule(:compoundStmt) do
|
|
250
|
+
(tBEGIN >> stmt.repeat(1).as(:stmt) >> tEND >> op_delim).as(:compoundStmt)
|
|
251
|
+
end
|
|
252
|
+
rule(:concreteTypes) do
|
|
253
|
+
(aggregationTypes | simpleTypes | typeRef).as(:concreteTypes)
|
|
254
|
+
end
|
|
255
|
+
rule(:constantBody) do
|
|
256
|
+
(constantId >> op_colon >> instantiableType >> op_decl >> expression >> op_delim).as(:constantBody)
|
|
257
|
+
end
|
|
258
|
+
rule(:constantDecl) do
|
|
259
|
+
(tCONSTANT >> constantBody.repeat(1).as(:constantBody) >> tEND_CONSTANT >> op_delim).as(:constantDecl)
|
|
260
|
+
end
|
|
261
|
+
rule(:constantFactor) do
|
|
262
|
+
(builtInConstant | constantRef).as(:constantFactor)
|
|
263
|
+
end
|
|
264
|
+
rule(:constantId) { simpleId.as(:constantId) }
|
|
265
|
+
rule(:constantRef) { constantId.as(:constantRef) }
|
|
266
|
+
rule(:constructedTypes) do
|
|
267
|
+
(enumerationType | selectType).as(:constructedTypes)
|
|
268
|
+
end
|
|
269
|
+
rule(:declaration) do
|
|
270
|
+
(entityDecl | functionDecl | procedureDecl | subtypeConstraintDecl | typeDecl).as(:declaration)
|
|
271
|
+
end
|
|
272
|
+
rule(:delim) { cts(str(";").as(:delim)) }
|
|
273
|
+
rule(:deriveClause) do
|
|
274
|
+
(tDERIVE >> derivedAttr.repeat(1).as(:derivedAttr)).as(:deriveClause)
|
|
275
|
+
end
|
|
276
|
+
rule(:derivedAttr) do
|
|
277
|
+
(attributeDecl >> op_colon >> parameterType >> op_decl >> expression >> op_delim).as(:derivedAttr)
|
|
278
|
+
end
|
|
279
|
+
rule(:digit) { match["0-9"] }
|
|
280
|
+
rule(:digits) { digit >> digit.repeat }
|
|
281
|
+
rule(:domainRule) do
|
|
282
|
+
((ruleLabelId >> op_colon).maybe >> expression).as(:domainRule)
|
|
283
|
+
end
|
|
284
|
+
rule(:element) do
|
|
285
|
+
(expression >> (op_colon >> repetition).maybe).as(:element)
|
|
286
|
+
end
|
|
287
|
+
rule(:embeddedRemark) do
|
|
288
|
+
(
|
|
289
|
+
# `(*)` is a 3-character empty embedded remark: the opener `(*`
|
|
290
|
+
# and closer `*)` share the `*`. Per strict ISO 10303-11 §7.1.6
|
|
291
|
+
# grammar the opener and closer are distinct tokens and cannot
|
|
292
|
+
# share characters, so `(*)` is technically invalid. We accept
|
|
293
|
+
# it for robustness (issue #126).
|
|
294
|
+
str("(*)") |
|
|
295
|
+
(str("(*") >> (str("*)").absent? >> (embeddedRemark | any)).repeat >> str("*)"))
|
|
296
|
+
).as(:embeddedRemark)
|
|
297
|
+
end
|
|
298
|
+
rule(:encodedCharacter) { octet >> octet >> octet >> octet }
|
|
299
|
+
rule(:encodedStringLiteral) do
|
|
300
|
+
cts((str('"') >> encodedCharacter.repeat(1) >> str('"')).as(:str)).as(:encodedStringLiteral)
|
|
301
|
+
end
|
|
302
|
+
rule(:entityBody) do
|
|
303
|
+
(explicitAttr.repeat.as(:explicitAttr) >> deriveClause.maybe >> inverseClause.maybe >> uniqueClause.maybe >> whereClause.maybe).as(:entityBody)
|
|
304
|
+
end
|
|
305
|
+
rule(:entityConstructor) do
|
|
306
|
+
(entityRef >> op_leftparen >> (expression >> (op_comma >> expression).repeat).as(:listOf_expression).maybe >> op_rightparen).as(:entityConstructor)
|
|
307
|
+
end
|
|
308
|
+
rule(:entityDecl) do
|
|
309
|
+
(entityHead >> entityBody >> tEND_ENTITY >> op_delim).as(:entityDecl)
|
|
310
|
+
end
|
|
311
|
+
rule(:entityHead) do
|
|
312
|
+
# ISO 10303-11 requires the header delimiter, but real-world
|
|
313
|
+
# corpora (STEPmod resources) omit it — eengine accepts the
|
|
314
|
+
# form, and the corpus gate demands it (#537). The tail is
|
|
315
|
+
# one atomic rule (trivia + optional delimiter) so the
|
|
316
|
+
# native evaluator consumes the header remark inside a
|
|
317
|
+
# single Named capture (#537: bare spaces.maybe at this
|
|
318
|
+
# seam diverges on the native engine).
|
|
319
|
+
(tENTITY >> entityId >> subsuper >> entityHeaderTail.maybe).as(:entityHead)
|
|
320
|
+
end
|
|
321
|
+
rule(:entityId) { simpleId.as(:entityId) }
|
|
322
|
+
rule(:entityHeaderTail) do
|
|
323
|
+
(space.repeat >> op_delim.maybe).as(:entityHeaderTail)
|
|
324
|
+
end
|
|
325
|
+
rule(:entityRef) { entityId.as(:entityRef) }
|
|
326
|
+
rule(:enumerationExtension) do
|
|
327
|
+
(tBASED_ON >> typeRef >> (tWITH >> enumerationItems).maybe).as(:enumerationExtension)
|
|
328
|
+
end
|
|
329
|
+
rule(:enumerationId) { simpleId.as(:enumerationId) }
|
|
330
|
+
rule(:enumerationItem) { enumerationId.as(:enumerationItem) }
|
|
331
|
+
rule(:enumerationItems) do
|
|
332
|
+
(op_leftparen >> (enumerationItem >> (op_comma >> enumerationItem).repeat).as(:listOf_enumerationItem) >> op_rightparen).as(:enumerationItems)
|
|
333
|
+
end
|
|
334
|
+
rule(:enumerationRef) { enumerationId.as(:enumerationRef) }
|
|
335
|
+
rule(:enumerationReference) do
|
|
336
|
+
((typeRef >> op_period).maybe >> enumerationRef).as(:enumerationReference)
|
|
337
|
+
end
|
|
338
|
+
rule(:enumerationType) do
|
|
339
|
+
(tEXTENSIBLE.maybe >> tENUMERATION >> ((tOF >> enumerationItems) | enumerationExtension).maybe).as(:enumerationType)
|
|
340
|
+
end
|
|
341
|
+
rule(:escapeStmt) { (tESCAPE >> op_delim).as(:escapeStmt) }
|
|
342
|
+
rule(:explicitAttr) do
|
|
343
|
+
((attributeDecl >> (op_comma >> attributeDecl).repeat).as(:listOf_attributeDecl) >> op_colon >>
|
|
344
|
+
tOPTIONAL.maybe >> parameterType >> op_delim).as(:explicitAttr)
|
|
345
|
+
end
|
|
346
|
+
rule(:expression) do
|
|
347
|
+
(simpleExpression >> (relOpExtended >> simpleExpression.as(:rhs)).maybe).as(:expression)
|
|
348
|
+
end
|
|
349
|
+
rule(:factor) do
|
|
350
|
+
(simpleFactor >> (op_double_asterisk >> simpleFactor.as(:rhs)).maybe).as(:factor)
|
|
351
|
+
end
|
|
352
|
+
rule(:formalParameter) do
|
|
353
|
+
((parameterId >> (op_comma >> parameterId).repeat).as(:listOf_parameterId) >> op_colon >> parameterType).as(:formalParameter)
|
|
354
|
+
end
|
|
355
|
+
rule(:functionCall) do
|
|
356
|
+
((builtInFunction | functionRef) >> actualParameterList.maybe).as(:functionCall)
|
|
357
|
+
end
|
|
358
|
+
rule(:functionDecl) do
|
|
359
|
+
(functionHead >> algorithmHead >> stmt.repeat(1).as(:stmt) >> tEND_FUNCTION >> op_delim).as(:functionDecl)
|
|
360
|
+
end
|
|
361
|
+
rule(:functionHead) do
|
|
362
|
+
(tFUNCTION >> functionId >>
|
|
363
|
+
# syntax 253: the parameter list is optional within the
|
|
364
|
+
# parentheses, so FUNCTION f() is legal (#558)
|
|
365
|
+
(op_leftparen >> (formalParameter >> (op_delim >> formalParameter).repeat).as(:listOf_formalParameter).maybe >> op_rightparen).maybe.as(:function_head_parameter_group) >>
|
|
366
|
+
op_colon >> parameterType >> op_delim.as(:op_delim2)).as(:functionHead)
|
|
367
|
+
end
|
|
368
|
+
rule(:functionId) { simpleId.as(:functionId) }
|
|
369
|
+
rule(:functionRef) { functionId.as(:functionRef) }
|
|
370
|
+
rule(:generalAggregationTypes) do
|
|
371
|
+
(generalArrayType | generalBagType | generalListType | generalSetType).as(:generalAggregationTypes)
|
|
372
|
+
end
|
|
373
|
+
rule(:generalArrayType) do
|
|
374
|
+
(tARRAY >> boundSpec.maybe >> tOF >> tOPTIONAL.maybe >> tUNIQUE.maybe >> parameterType).as(:generalArrayType)
|
|
375
|
+
end
|
|
376
|
+
rule(:generalBagType) do
|
|
377
|
+
(tBAG >> boundSpec.maybe >> tOF >> parameterType).as(:generalBagType)
|
|
378
|
+
end
|
|
379
|
+
rule(:generalizedTypes) do
|
|
380
|
+
(aggregateType | generalAggregationTypes | genericEntityType | genericType).as(:generalizedTypes)
|
|
381
|
+
end
|
|
382
|
+
rule(:generalListType) do
|
|
383
|
+
(tLIST >> boundSpec.maybe >> tOF >> tUNIQUE.maybe >> parameterType).as(:generalListType)
|
|
384
|
+
end
|
|
385
|
+
rule(:generalRef) { (parameterRef | variableId).as(:generalRef) }
|
|
386
|
+
rule(:generalSetType) do
|
|
387
|
+
(tSET >> boundSpec.maybe >> tOF >> parameterType).as(:generalSetType)
|
|
388
|
+
end
|
|
389
|
+
rule(:genericEntityType) do
|
|
390
|
+
(tGENERIC_ENTITY >> (op_colon >> typeLabel).maybe).as(:genericEntityType)
|
|
391
|
+
end
|
|
392
|
+
rule(:genericType) do
|
|
393
|
+
(tGENERIC >> (op_colon >> typeLabel).maybe).as(:genericType)
|
|
394
|
+
end
|
|
395
|
+
rule(:groupQualifier) do
|
|
396
|
+
(op_double_backslash >> entityRef).as(:groupQualifier)
|
|
397
|
+
end
|
|
398
|
+
rule(:hexDigit) { match["0-9a-fA-F"] }
|
|
399
|
+
rule(:ifStmtElseStatements) do
|
|
400
|
+
stmt.repeat(1).as(:stmt).as(:ifStmtElseStatements)
|
|
401
|
+
end
|
|
402
|
+
rule(:ifStmtStatements) do
|
|
403
|
+
stmt.repeat(1).as(:stmt).as(:ifStmtStatements)
|
|
404
|
+
end
|
|
405
|
+
rule(:ifStmt) do
|
|
406
|
+
(tIF >> logicalExpression >> tTHEN >> ifStmtStatements >> (tELSE >> ifStmtElseStatements).maybe >> tEND_IF >> op_delim).as(:ifStmt)
|
|
407
|
+
end
|
|
408
|
+
rule(:incrementControl) do
|
|
409
|
+
(variableId >> op_decl >> bound1 >> tTO >> bound2 >> (tBY >> increment).maybe).as(:incrementControl)
|
|
410
|
+
end
|
|
411
|
+
rule(:increment) { numericExpression.as(:increment) }
|
|
412
|
+
rule(:index1) { index.as(:index1) }
|
|
413
|
+
rule(:index2) { index.as(:index2) }
|
|
414
|
+
rule(:index) { numericExpression.as(:index) }
|
|
415
|
+
rule(:indexQualifier) do
|
|
416
|
+
(op_leftbracket >> index1 >> (op_colon >> index2).maybe >> op_rightbracket).as(:indexQualifier)
|
|
417
|
+
end
|
|
418
|
+
rule(:instantiableType) do
|
|
419
|
+
(concreteTypes | entityRef).as(:instantiableType)
|
|
420
|
+
end
|
|
421
|
+
rule(:integerLiteral) { cts(digits.as(:str)).as(:integerLiteral) }
|
|
422
|
+
rule(:integerType) { tINTEGER.as(:integerType) }
|
|
423
|
+
rule(:interfaceSpecification) do
|
|
424
|
+
(referenceClause | useClause).as(:interfaceSpecification)
|
|
425
|
+
end
|
|
426
|
+
rule(:intervalHigh) { simpleExpression.as(:intervalHigh) }
|
|
427
|
+
rule(:intervalItem) { simpleExpression.as(:intervalItem) }
|
|
428
|
+
rule(:intervalLow) { simpleExpression.as(:intervalLow) }
|
|
429
|
+
rule(:interval) do
|
|
430
|
+
(op_left_curly_brace >> intervalLow >> intervalOp >> intervalItem >> intervalOp.as(:intervalOp2) >>
|
|
431
|
+
intervalHigh >> op_right_curly_brace).as(:interval)
|
|
432
|
+
end
|
|
433
|
+
rule(:intervalOp) { (op_less_equal | op_less_than).as(:intervalOp) }
|
|
434
|
+
rule(:inverseAttr) do
|
|
435
|
+
(attributeDecl >> op_colon >> inverseAttrType >> tFOR >> (entityRef >> op_period).maybe >> attributeRef >> op_delim).as(:inverseAttr)
|
|
436
|
+
end
|
|
437
|
+
rule(:inverseAttrType) do
|
|
438
|
+
(((tSET | tBAG) >> boundSpec.maybe >> tOF).maybe >> entityRef).as(:inverseAttrType)
|
|
439
|
+
end
|
|
440
|
+
rule(:inverseClause) do
|
|
441
|
+
(tINVERSE >> inverseAttr.repeat(1).as(:inverseAttr)).as(:inverseClause)
|
|
442
|
+
end
|
|
443
|
+
rule(:letter) { match["a-zA-Z"] }
|
|
444
|
+
rule(:listType) do
|
|
445
|
+
(tLIST >> boundSpec.maybe >> tOF >> tUNIQUE.maybe >> instantiableType).as(:listType)
|
|
446
|
+
end
|
|
447
|
+
rule(:literal) do
|
|
448
|
+
(binaryLiteral | logicalLiteral | realLiteral | integerLiteral | stringLiteral).as(:literal)
|
|
449
|
+
end
|
|
450
|
+
rule(:localDecl) do
|
|
451
|
+
(tLOCAL >> localVariable.repeat(1).as(:localVariable) >> tEND_LOCAL >> op_delim).as(:localDecl)
|
|
452
|
+
end
|
|
453
|
+
rule(:localVariable) do
|
|
454
|
+
((variableId >> (op_comma >> variableId).repeat).as(:listOf_variableId) >>
|
|
455
|
+
op_colon >> parameterType >>
|
|
456
|
+
(op_decl >> expression).maybe >> op_delim).as(:localVariable)
|
|
457
|
+
end
|
|
458
|
+
rule(:logicalExpression) { expression.as(:logicalExpression) }
|
|
459
|
+
rule(:logicalLiteral) do
|
|
460
|
+
(tFALSE | tTRUE | tUNKNOWN).as(:logicalLiteral)
|
|
461
|
+
end
|
|
462
|
+
rule(:logicalType) { tLOGICAL.as(:logicalType) }
|
|
463
|
+
rule(:multiplicationLikeOp) do
|
|
464
|
+
(op_asterisk | op_slash | tDIV | tMOD | tAND | op_double_pipe).as(:multiplicationLikeOp)
|
|
465
|
+
end
|
|
466
|
+
rule(:namedTypeOrRename) do
|
|
467
|
+
(namedTypes >> (tAS >> (entityId | typeId)).maybe).as(:namedTypeOrRename)
|
|
468
|
+
end
|
|
469
|
+
rule(:namedTypes) { (entityRef | typeRef).as(:namedTypes) }
|
|
470
|
+
rule(:nullStmt) { op_delim.as(:nullStmt) }
|
|
471
|
+
rule(:numberType) { tNUMBER.as(:numberType) }
|
|
472
|
+
rule(:numericExpression) { simpleExpression.as(:numericExpression) }
|
|
473
|
+
rule(:octet) { hexDigit >> hexDigit }
|
|
474
|
+
rule(:oneOf) do
|
|
475
|
+
(tONEOF >> op_leftparen >> (supertypeExpression >>
|
|
476
|
+
(op_comma >> supertypeExpression).repeat).as(:listOf_supertypeExpression) >> op_rightparen).as(:oneOf)
|
|
477
|
+
end
|
|
478
|
+
rule(:op_asterisk) { cstr("*").as(:op_asterisk) }
|
|
479
|
+
rule(:op_colon) { cstr(":").as(:op_colon) }
|
|
480
|
+
rule(:op_colon_equals_colon) { cstr(":=:").as(:op_colon_equals_colon) }
|
|
481
|
+
rule(:op_colon_less_greater_colon) do
|
|
482
|
+
cstr(":<>:").as(:op_colon_less_greater_colon)
|
|
483
|
+
end
|
|
484
|
+
rule(:op_comma) { cstr(",").as(:op_comma) }
|
|
485
|
+
rule(:op_decl) { cstr(":=").as(:op_decl) }
|
|
486
|
+
rule(:op_delim) { cstr(";").as(:op_delim) }
|
|
487
|
+
rule(:op_double_asterisk) { cstr("**").as(:op_double_asterisk) }
|
|
488
|
+
rule(:op_double_backslash) { cstr("\\").as(:op_double_backslash) }
|
|
489
|
+
rule(:op_double_pipe) { cstr("||").as(:op_double_pipe) }
|
|
490
|
+
rule(:op_equals) { cstr("=").as(:op_equals) }
|
|
491
|
+
rule(:op_greater_equal) { cstr(">=").as(:op_greater_equal) }
|
|
492
|
+
rule(:op_greater_than) { cstr(">").as(:op_greater_than) }
|
|
493
|
+
rule(:op_leftbracket) { cstr("[").as(:op_leftbracket) }
|
|
494
|
+
rule(:op_left_curly_brace) { cstr("{").as(:op_left_curly_brace) }
|
|
495
|
+
rule(:op_leftparen) { cstr("(").as(:op_leftparen) }
|
|
496
|
+
rule(:op_less_equal) { cstr("<=").as(:op_less_equal) }
|
|
497
|
+
rule(:op_less_greater) { cstr("<>").as(:op_less_greater) }
|
|
498
|
+
rule(:op_less_than) { cstr("<").as(:op_less_than) }
|
|
499
|
+
rule(:op_minus) { cstr("-").as(:op_minus) }
|
|
500
|
+
rule(:op_period) { cstr(".").as(:op_period) }
|
|
501
|
+
rule(:op_pipe) { cstr("|").as(:op_pipe) }
|
|
502
|
+
rule(:op_plus) { cstr("+").as(:op_plus) }
|
|
503
|
+
rule(:op_query_begin) { cstr("<*").as(:op_query_begin) }
|
|
504
|
+
rule(:op_query_end) { cstr("*>").as(:op_query_end) }
|
|
505
|
+
rule(:op_question_mark) { cstr("?").as(:op_question_mark) }
|
|
506
|
+
rule(:op_rightbracket) { cstr("]").as(:op_rightbracket) }
|
|
507
|
+
rule(:op_right_curly_brace) { cstr("}").as(:op_right_curly_brace) }
|
|
508
|
+
rule(:op_rightparen) { cstr(")").as(:op_rightparen) }
|
|
509
|
+
rule(:op_slash) { cstr("/").as(:op_slash) }
|
|
510
|
+
rule(:parameter) { expression.as(:parameter) }
|
|
511
|
+
rule(:parameterId) { simpleId.as(:parameterId) }
|
|
512
|
+
rule(:parameterRef) { parameterId.as(:parameterRef) }
|
|
513
|
+
rule(:parameterType) do
|
|
514
|
+
(generalizedTypes | namedTypes | simpleTypes).as(:parameterType)
|
|
515
|
+
end
|
|
516
|
+
rule(:population) { entityRef.as(:population) }
|
|
517
|
+
rule(:precisionSpec) { numericExpression.as(:precisionSpec) }
|
|
518
|
+
rule(:primary) do
|
|
519
|
+
(literal | (qualifiableFactor >> qualifier.repeat.as(:qualifier))).as(:primary)
|
|
520
|
+
end
|
|
521
|
+
rule(:procedureCallStmt) do
|
|
522
|
+
((builtInProcedure | procedureRef) >> actualParameterList.maybe >> op_delim).as(:procedureCallStmt)
|
|
523
|
+
end
|
|
524
|
+
rule(:procedureDecl) do
|
|
525
|
+
(procedureHead >> algorithmHead >> stmt.repeat.as(:stmt) >> tEND_PROCEDURE >> op_delim).as(:procedureDecl)
|
|
526
|
+
end
|
|
527
|
+
rule(:procedureHeadParameter) do
|
|
528
|
+
(tVAR.maybe >> formalParameter).as(:procedureHeadParameter)
|
|
529
|
+
end
|
|
530
|
+
rule(:procedureHead) do
|
|
531
|
+
(tPROCEDURE >> procedureId >>
|
|
532
|
+
# syntax 316: the parameter list is optional within the
|
|
533
|
+
# parentheses, so PROCEDURE p() is legal (#558)
|
|
534
|
+
(op_leftparen >> (procedureHeadParameter >>
|
|
535
|
+
(op_delim >> procedureHeadParameter).repeat).as(:listOf_procedureHeadParameter).maybe >> op_rightparen).maybe.as(:function_head_parameter_group) >> op_delim.as(:op_delim2)).as(:procedureHead)
|
|
536
|
+
end
|
|
537
|
+
rule(:procedureId) { simpleId.as(:procedureId) }
|
|
538
|
+
rule(:procedureRef) { procedureId.as(:procedureRef) }
|
|
539
|
+
rule(:qualifiableFactor) do
|
|
540
|
+
(functionCall | attributeRef | constantFactor | generalRef | population).as(:qualifiableFactor)
|
|
541
|
+
end
|
|
542
|
+
rule(:qualifiedAttribute) do
|
|
543
|
+
(tSELF >> groupQualifier >> attributeQualifier).as(:qualifiedAttribute)
|
|
544
|
+
end
|
|
545
|
+
rule(:qualifier) do
|
|
546
|
+
(attributeQualifier | groupQualifier | indexQualifier).as(:qualifier)
|
|
547
|
+
end
|
|
548
|
+
rule(:queryExpression) do
|
|
549
|
+
(tQUERY >> op_leftparen >> variableId >> op_query_begin >> aggregateSource >> op_pipe >> logicalExpression >> op_rightparen).as(:queryExpression)
|
|
550
|
+
end
|
|
551
|
+
rule(:realLiteral) do
|
|
552
|
+
cts((digits >> str(".") >> digits.maybe >> (match["eE"] >> sign.maybe >> digits).maybe).as(:str)).as(:realLiteral)
|
|
553
|
+
end
|
|
554
|
+
rule(:realType) do
|
|
555
|
+
(tREAL >> (op_leftparen >> precisionSpec >> op_rightparen).maybe).as(:realType)
|
|
556
|
+
end
|
|
557
|
+
rule(:redeclaredAttribute) do
|
|
558
|
+
(qualifiedAttribute >> (tRENAMED >> attributeId).maybe).as(:redeclaredAttribute)
|
|
559
|
+
end
|
|
560
|
+
rule(:referenceClause) do
|
|
561
|
+
(tREFERENCE >> tFROM >> schemaRef >>
|
|
562
|
+
(op_leftparen >> (resourceOrRename >> (op_comma >> resourceOrRename).repeat).as(:listOf_resourceOrRename) >> op_rightparen).maybe >> op_delim).as(:referenceClause)
|
|
563
|
+
end
|
|
564
|
+
rule(:referencedAttribute) do
|
|
565
|
+
(attributeRef | qualifiedAttribute).as(:referencedAttribute)
|
|
566
|
+
end
|
|
567
|
+
rule(:relOpExtended) { (relOp | tIN | tLIKE).as(:relOpExtended) }
|
|
568
|
+
rule(:relOp) do
|
|
569
|
+
(op_less_equal | op_greater_equal | op_less_greater | op_less_than | op_greater_than | op_equals |
|
|
570
|
+
op_colon_less_greater_colon | op_colon_equals_colon).as(:relOp)
|
|
571
|
+
end
|
|
572
|
+
rule(:renameId) do
|
|
573
|
+
(constantId | entityId | functionId | procedureId | typeId).as(:renameId)
|
|
574
|
+
end
|
|
575
|
+
rule(:repeatControl) do
|
|
576
|
+
(incrementControl.maybe >> whileControl.maybe >> untilControl.maybe).as(:repeatControl)
|
|
577
|
+
end
|
|
578
|
+
rule(:repeatStmt) do
|
|
579
|
+
(tREPEAT >> repeatControl >> op_delim >> stmt.repeat(1).as(:stmt) >> tEND_REPEAT >> op_delim.as(:op_delim2)).as(:repeatStmt)
|
|
580
|
+
end
|
|
581
|
+
rule(:repetition) { numericExpression.as(:repetition) }
|
|
582
|
+
rule(:resourceOrRename) do
|
|
583
|
+
(resourceRef >> (tAS >> renameId).maybe).as(:resourceOrRename)
|
|
584
|
+
end
|
|
585
|
+
rule(:resourceRef) do
|
|
586
|
+
(constantRef | entityRef | functionRef | procedureRef | typeRef).as(:resourceRef)
|
|
587
|
+
end
|
|
588
|
+
rule(:returnStmt) do
|
|
589
|
+
(tRETURN >> (op_leftparen >> expression >> op_rightparen).maybe >> op_delim).as(:returnStmt)
|
|
590
|
+
end
|
|
591
|
+
rule(:ruleDecl) do
|
|
592
|
+
(ruleHead >> algorithmHead >> stmt.repeat.as(:stmt) >> whereClause >> tEND_RULE >> op_delim).as(:ruleDecl)
|
|
593
|
+
end
|
|
594
|
+
rule(:ruleHead) do
|
|
595
|
+
(tRULE >> ruleId >> tFOR >> op_leftparen >>
|
|
596
|
+
(entityRef >> (op_comma >> entityRef).repeat).as(:listOf_entityRef) >> op_rightparen >> op_delim).as(:ruleHead)
|
|
597
|
+
end
|
|
598
|
+
rule(:ruleId) { simpleId.as(:ruleId) }
|
|
599
|
+
rule(:ruleLabelId) { simpleId.as(:ruleLabelId) }
|
|
600
|
+
rule(:ruleLabelRef) { ruleLabelId.as(:ruleLabelRef) }
|
|
601
|
+
rule(:ruleRef) { ruleId.as(:ruleRef) }
|
|
602
|
+
rule(:schemaBodyDeclaration) do
|
|
603
|
+
(declaration | ruleDecl).as(:schemaBodyDeclaration)
|
|
604
|
+
end
|
|
605
|
+
rule(:schemaBody) do
|
|
606
|
+
(interfaceSpecification.repeat.as(:interfaceSpecification) >> constantDecl.maybe >>
|
|
607
|
+
schemaBodyDeclaration.repeat.as(:schemaBodyDeclaration)).as(:schemaBody)
|
|
608
|
+
end
|
|
609
|
+
rule(:schemaDecl) do
|
|
610
|
+
(tSCHEMA >> schemaId >> schemaVersionId.maybe >> op_delim >> schemaBody >> tEND_SCHEMA >> op_delim.as(:op_delim2)).as(:schemaDecl)
|
|
611
|
+
end
|
|
612
|
+
rule(:schemaId) { simpleId.as(:schemaId) }
|
|
613
|
+
rule(:schemaRef) { schemaId.as(:schemaRef) }
|
|
614
|
+
rule(:schemaVersionId) { stringLiteral.as(:schemaVersionId) }
|
|
615
|
+
rule(:selectExtension) do
|
|
616
|
+
(tBASED_ON >> typeRef >> (tWITH >> selectList).maybe).as(:selectExtension)
|
|
617
|
+
end
|
|
618
|
+
rule(:selectList) do
|
|
619
|
+
(op_leftparen >> (namedTypes >> (op_comma >> namedTypes).repeat).as(:listOf_namedTypes) >> op_rightparen).as(:selectList)
|
|
620
|
+
end
|
|
621
|
+
rule(:selector) { expression.as(:selector) }
|
|
622
|
+
rule(:selectType) do
|
|
623
|
+
((tEXTENSIBLE >> tGENERIC_ENTITY.maybe).maybe >> tSELECT >> (selectList | selectExtension).maybe).as(:selectType)
|
|
624
|
+
end
|
|
625
|
+
rule(:setType) do
|
|
626
|
+
(tSET >> boundSpec.maybe >> tOF >> instantiableType).as(:setType)
|
|
627
|
+
end
|
|
628
|
+
rule(:sign) { match["+-"] }
|
|
629
|
+
rule(:simpleExpression) do
|
|
630
|
+
(term >> (addLikeOp.as(:operator) >> term).as(:item).repeat.as(:rhs)).as(:simpleExpression)
|
|
631
|
+
end
|
|
632
|
+
rule(:simpleFactor) do
|
|
633
|
+
(simpleFactorExpression | aggregateInitializer | entityConstructor | interval | queryExpression | stringLiteral |
|
|
634
|
+
simpleFactorUnaryExpression | enumerationReference).as(:simpleFactor)
|
|
635
|
+
end
|
|
636
|
+
rule(:simpleFactorExpression) do
|
|
637
|
+
((op_leftparen >> expression >> op_rightparen) | primary).as(:simpleFactorExpression)
|
|
638
|
+
end
|
|
639
|
+
rule(:simpleFactorUnaryExpression) do
|
|
640
|
+
(unaryOp >> simpleFactorExpression).as(:simpleFactorUnaryExpression)
|
|
641
|
+
end
|
|
642
|
+
rule(:simpleId) do
|
|
643
|
+
# One quantified Re, not lead >> tail-repeat: under skip
|
|
644
|
+
# injection the DSL interleaves trivia before the tail
|
|
645
|
+
# repetition, so a two-atom ident would absorb the following
|
|
646
|
+
# whitespace-separated identifier ("RULE r FOR (e)" parses
|
|
647
|
+
# "r FOR" as one simpleId). A quantified Re consumes the
|
|
648
|
+
# whole identifier in a single step — parsanol GH-69.
|
|
649
|
+
anyKeyword.absent? >> cts(match("[a-zA-Z_][a-zA-Z0-9_]*").as(:str)).as(:simpleId)
|
|
650
|
+
end
|
|
651
|
+
rule(:simpleStringLiteral) do
|
|
652
|
+
cts((str("'") >> (str("'").absent? >> any).repeat >> str("'")).as(:str)).as(:simpleStringLiteral)
|
|
653
|
+
end
|
|
654
|
+
rule(:simpleTypes) do
|
|
655
|
+
(binaryType | booleanType | integerType | logicalType | numberType | realType | stringType).as(:simpleTypes)
|
|
656
|
+
end
|
|
657
|
+
rule(:skipStmt) { (tSKIP >> op_delim).as(:skipStmt) }
|
|
658
|
+
rule(:space) { match[" \r\n\t\f"] | embeddedRemark | tailRemark }
|
|
659
|
+
rule(:spaces) { space.repeat.as(:spaces) }
|
|
660
|
+
rule(:stmt) do
|
|
661
|
+
(aliasStmt | assignmentStmt | caseStmt | compoundStmt | escapeStmt | ifStmt |
|
|
662
|
+
nullStmt | procedureCallStmt | repeatStmt | returnStmt | skipStmt).as(:stmt)
|
|
663
|
+
end
|
|
664
|
+
rule(:stringLiteral) do
|
|
665
|
+
(simpleStringLiteral | encodedStringLiteral).as(:stringLiteral)
|
|
666
|
+
end
|
|
667
|
+
rule(:stringType) { (tSTRING >> widthSpec.maybe).as(:stringType) }
|
|
668
|
+
rule(:subsuper) do
|
|
669
|
+
(supertypeConstraint.maybe >> subtypeDeclaration.maybe).as(:subsuper)
|
|
670
|
+
end
|
|
671
|
+
rule(:subtypeConstraintBody) do
|
|
672
|
+
(abstractSupertype.maybe >> totalOver.maybe >> (supertypeExpression >> op_delim).maybe).as(:subtypeConstraintBody)
|
|
673
|
+
end
|
|
674
|
+
rule(:subtypeConstraintDecl) do
|
|
675
|
+
(subtypeConstraintHead >> subtypeConstraintBody >> tEND_SUBTYPE_CONSTRAINT >> op_delim).as(:subtypeConstraintDecl)
|
|
676
|
+
end
|
|
677
|
+
rule(:subtypeConstraintHead) do
|
|
678
|
+
(tSUBTYPE_CONSTRAINT >> subtypeConstraintId >> tFOR >> entityRef >> op_delim).as(:subtypeConstraintHead)
|
|
679
|
+
end
|
|
680
|
+
rule(:subtypeConstraintId) { simpleId.as(:subtypeConstraintId) }
|
|
681
|
+
rule(:subtypeConstraintRef) do
|
|
682
|
+
subtypeConstraintId.as(:subtypeConstraintRef)
|
|
683
|
+
end
|
|
684
|
+
rule(:subtypeConstraint) do
|
|
685
|
+
(tOF >> op_leftparen >> supertypeExpression >> op_rightparen).as(:subtypeConstraint)
|
|
686
|
+
end
|
|
687
|
+
rule(:subtypeDeclaration) do
|
|
688
|
+
(tSUBTYPE >> tOF >> op_leftparen >> entityRef >> (op_comma >> entityRef).repeat >> op_rightparen).as(:listOf_entityRef).as(:subtypeDeclaration)
|
|
689
|
+
end
|
|
690
|
+
rule(:supertypeConstraint) do
|
|
691
|
+
(abstractSupertypeDeclaration | abstractEntityDeclaration | supertypeRule).as(:supertypeConstraint)
|
|
692
|
+
end
|
|
693
|
+
rule(:supertypeExpression) do
|
|
694
|
+
(supertypeFactor >> (tANDOR.as(:operator) >> supertypeFactor).as(:item).repeat.as(:rhs)).as(:supertypeExpression)
|
|
695
|
+
end
|
|
696
|
+
rule(:supertypeFactor) do
|
|
697
|
+
(supertypeTerm >> (tAND.as(:operator) >> supertypeTerm).as(:item).repeat.as(:rhs)).as(:supertypeFactor)
|
|
698
|
+
end
|
|
699
|
+
rule(:supertypeRule) do
|
|
700
|
+
(tSUPERTYPE >> subtypeConstraint).as(:supertypeRule)
|
|
701
|
+
end
|
|
702
|
+
rule(:supertypeTerm) do
|
|
703
|
+
(entityRef | oneOf | (op_leftparen >> supertypeExpression >> op_rightparen)).as(:supertypeTerm)
|
|
704
|
+
end
|
|
705
|
+
rule(:syntax) do
|
|
706
|
+
# zero-or-more: remark-only fragments (no SCHEMA wrapper)
|
|
707
|
+
# parse to an empty model so the facade raises the clean
|
|
708
|
+
# "no schema found" error (#537 part 2) instead of a dump
|
|
709
|
+
(spaces.as(:spaces) >> schemaDecl.repeat(0).as(:schemaDecl) >> spaces.as(:trailer)).as(:syntax)
|
|
710
|
+
end
|
|
711
|
+
rule(:tailRemark) do
|
|
712
|
+
(str("--") >> (str("\n").absent? >> any).repeat >> str("\n").maybe).as(:tailRemark)
|
|
713
|
+
end
|
|
714
|
+
rule(:term) do
|
|
715
|
+
(factor >> (multiplicationLikeOp >> factor).as(:item).repeat.as(:rhs)).as(:term)
|
|
716
|
+
end
|
|
717
|
+
rule(:totalOver) do
|
|
718
|
+
(tTOTAL_OVER >> op_leftparen >> (entityRef >> (op_comma >> entityRef).repeat).as(:listOf_entityRef) >> op_rightparen >> op_delim).as(:totalOver)
|
|
719
|
+
end
|
|
720
|
+
rule(:typeDecl) do
|
|
721
|
+
(tTYPE >> typeId >> op_equals >> underlyingType >> op_delim >> whereClause.maybe >> tEND_TYPE >> op_delim.as(:op_delim2)).as(:typeDecl)
|
|
722
|
+
end
|
|
723
|
+
rule(:typeId) { simpleId.as(:typeId) }
|
|
724
|
+
rule(:typeLabelId) { simpleId.as(:typeLabelId) }
|
|
725
|
+
rule(:typeLabelRef) { typeLabelId.as(:typeLabelRef) }
|
|
726
|
+
rule(:typeLabel) { (typeLabelId | typeLabelRef).as(:typeLabel) }
|
|
727
|
+
rule(:typeRef) { typeId.as(:typeRef) }
|
|
728
|
+
rule(:unaryOp) { (op_plus | op_minus | tNOT).as(:unaryOp) }
|
|
729
|
+
rule(:underlyingType) do
|
|
730
|
+
(concreteTypes | constructedTypes).as(:underlyingType)
|
|
731
|
+
end
|
|
732
|
+
rule(:uniqueClause) do
|
|
733
|
+
(tUNIQUE >> (uniqueRule >> op_delim >> (uniqueRule >> op_delim.as(:op_delim2)).repeat).as(:listOf_uniqueRule)).as(:uniqueClause)
|
|
734
|
+
end
|
|
735
|
+
rule(:uniqueRule) do
|
|
736
|
+
((ruleLabelId >> op_colon).maybe >> (referencedAttribute >> (op_comma >> referencedAttribute).repeat).as(:listOf_referencedAttribute)).as(:uniqueRule)
|
|
737
|
+
end
|
|
738
|
+
rule(:untilControl) { (tUNTIL >> logicalExpression).as(:untilControl) }
|
|
739
|
+
rule(:useClause) do
|
|
740
|
+
(tUSE >> tFROM >> schemaRef >>
|
|
741
|
+
(op_leftparen >> (namedTypeOrRename >> (op_comma >>
|
|
742
|
+
namedTypeOrRename).repeat).as(:listOf_namedTypeOrRename) >> op_rightparen).maybe >> op_delim).as(:useClause)
|
|
743
|
+
end
|
|
744
|
+
rule(:variableId) { simpleId.as(:variableId) }
|
|
745
|
+
rule(:variableRef) { variableId.as(:variableRef) }
|
|
746
|
+
rule(:whereClause) do
|
|
747
|
+
(tWHERE >> (domainRule >> op_delim).repeat.as(:listOf_domainRule)).as(:whereClause)
|
|
748
|
+
end
|
|
749
|
+
rule(:whileControl) { (tWHILE >> logicalExpression).as(:whileControl) }
|
|
750
|
+
rule(:width) { numericExpression.as(:width) }
|
|
751
|
+
rule(:widthSpec) do
|
|
752
|
+
(op_leftparen >> width >> op_rightparen >> tFIXED.maybe).as(:widthSpec)
|
|
753
|
+
end
|
|
754
|
+
end
|
|
755
|
+
end
|
|
756
|
+
end
|
|
757
|
+
end
|