@tuprolog/arg2p-core 0.7.1 → 0.7.3

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.
package/2p-parser-core.js CHANGED
@@ -1,13 +1,925 @@
1
1
  (function (root, factory) {
2
2
  if (typeof define === 'function' && define.amd)
3
- define(['exports'], factory);
3
+ define(['exports', '@tuprolog/parser-utils', 'antlr4', 'antlr4/src/antlr4/error', 'antlr4/src/antlr4/atn', './kotlin-kotlin-stdlib.js', './2p-core.js', './2p-parser-js.js', './kt-math.js'], factory);
4
4
  else if (typeof exports === 'object')
5
- factory(module.exports);
6
- else
7
- root['2p-parser-core'] = factory(typeof this['2p-parser-core'] === 'undefined' ? {} : this['2p-parser-core']);
8
- }(this, function (_) {
5
+ factory(module.exports, require('@tuprolog/parser-utils'), require('antlr4'), require('antlr4/src/antlr4/error'), require('antlr4/src/antlr4/atn'), require('./kotlin-kotlin-stdlib.js'), require('./2p-core.js'), require('./2p-parser-js.js'), require('./kt-math.js'));
6
+ else {
7
+ if (typeof this['@tuprolog/parser-utils'] === 'undefined') {
8
+ throw new Error("Error loading module '2p-parser-core'. Its dependency '@tuprolog/parser-utils' was not found. Please, check whether '@tuprolog/parser-utils' is loaded prior to '2p-parser-core'.");
9
+ }
10
+ if (typeof antlr4 === 'undefined') {
11
+ throw new Error("Error loading module '2p-parser-core'. Its dependency 'antlr4' was not found. Please, check whether 'antlr4' is loaded prior to '2p-parser-core'.");
12
+ }
13
+ if (typeof this['antlr4/src/antlr4/error'] === 'undefined') {
14
+ throw new Error("Error loading module '2p-parser-core'. Its dependency 'antlr4/src/antlr4/error' was not found. Please, check whether 'antlr4/src/antlr4/error' is loaded prior to '2p-parser-core'.");
15
+ }
16
+ if (typeof this['antlr4/src/antlr4/atn'] === 'undefined') {
17
+ throw new Error("Error loading module '2p-parser-core'. Its dependency 'antlr4/src/antlr4/atn' was not found. Please, check whether 'antlr4/src/antlr4/atn' is loaded prior to '2p-parser-core'.");
18
+ }
19
+ if (typeof this['kotlin-kotlin-stdlib'] === 'undefined') {
20
+ throw new Error("Error loading module '2p-parser-core'. Its dependency 'kotlin-kotlin-stdlib' was not found. Please, check whether 'kotlin-kotlin-stdlib' is loaded prior to '2p-parser-core'.");
21
+ }
22
+ if (typeof this['2p-core'] === 'undefined') {
23
+ throw new Error("Error loading module '2p-parser-core'. Its dependency '2p-core' was not found. Please, check whether '2p-core' is loaded prior to '2p-parser-core'.");
24
+ }
25
+ if (typeof this['2p-parser-js'] === 'undefined') {
26
+ throw new Error("Error loading module '2p-parser-core'. Its dependency '2p-parser-js' was not found. Please, check whether '2p-parser-js' is loaded prior to '2p-parser-core'.");
27
+ }
28
+ if (typeof this['kt-math'] === 'undefined') {
29
+ throw new Error("Error loading module '2p-parser-core'. Its dependency 'kt-math' was not found. Please, check whether 'kt-math' is loaded prior to '2p-parser-core'.");
30
+ }
31
+ root['2p-parser-core'] = factory(typeof this['2p-parser-core'] === 'undefined' ? {} : this['2p-parser-core'], this['@tuprolog/parser-utils'], antlr4, this['antlr4/src/antlr4/error'], this['antlr4/src/antlr4/atn'], this['kotlin-kotlin-stdlib'], this['2p-core'], this['2p-parser-js'], this['kt-math']);
32
+ }
33
+ }(this, function (_, $module$_tuprolog_parser_utils_xy31vy, $module$antlr4, $module$antlr4_src_antlr4_error_s9pni7, $module$antlr4_src_antlr4_atn_66gh9q, kotlin_kotlin, kotlin_it_unibo_tuprolog_core, kotlin_it_unibo_tuprolog_parser_js, kotlin_io_github_gciatto_kt_math) {
9
34
  'use strict';
35
+ //region block: imports
36
+ var PrologParserListener = $module$_tuprolog_parser_utils_xy31vy.PrologParserListener;
37
+ var Associativity = $module$_tuprolog_parser_utils_xy31vy.Associativity;
38
+ var Token = $module$antlr4.Token;
39
+ var RecognitionException = $module$antlr4_src_antlr4_error_s9pni7.RecognitionException;
40
+ var PredictionMode = $module$antlr4_src_antlr4_atn_66gh9q.PredictionMode;
41
+ var PrologParser = $module$_tuprolog_parser_utils_xy31vy.PrologParser;
42
+ var InputStream = $module$antlr4.InputStream;
43
+ var PrologLexer = $module$_tuprolog_parser_utils_xy31vy.PrologLexer;
44
+ var CommonTokenStream = $module$antlr4.CommonTokenStream;
45
+ var BailErrorStrategy = $module$antlr4_src_antlr4_error_s9pni7.BailErrorStrategy;
46
+ var PrologParserVisitor = $module$_tuprolog_parser_utils_xy31vy.PrologParserVisitor;
47
+ var VOID = kotlin_kotlin.$_$.d;
48
+ var captureStack = kotlin_kotlin.$_$.r4;
49
+ var protoOf = kotlin_kotlin.$_$.s5;
50
+ var classMeta = kotlin_kotlin.$_$.w4;
51
+ var setMetadataFor = kotlin_kotlin.$_$.t5;
52
+ var TuPrologException = kotlin_it_unibo_tuprolog_core.$_$.x;
53
+ var TuPrologException_init_$Init$ = kotlin_it_unibo_tuprolog_core.$_$.b;
54
+ var ensureNotNull = kotlin_kotlin.$_$.k9;
55
+ var replace = kotlin_kotlin.$_$.k8;
56
+ var _Char___init__impl__6a9atx = kotlin_kotlin.$_$.f1;
57
+ var Char = kotlin_kotlin.$_$.w8;
58
+ var toString = kotlin_kotlin.$_$.j1;
59
+ var Struct = kotlin_it_unibo_tuprolog_core.$_$.l1;
60
+ var isInterface = kotlin_kotlin.$_$.i5;
61
+ var Numeric = kotlin_it_unibo_tuprolog_core.$_$.i1;
62
+ var Atom = kotlin_it_unibo_tuprolog_core.$_$.a1;
63
+ var Clause = kotlin_it_unibo_tuprolog_core.$_$.b1;
64
+ var getKClass = kotlin_kotlin.$_$.c;
65
+ var Companion_instance = kotlin_it_unibo_tuprolog_core.$_$.j;
66
+ var Unit_instance = kotlin_kotlin.$_$.r1;
67
+ var objectMeta = kotlin_kotlin.$_$.r5;
68
+ var THROW_CCE = kotlin_kotlin.$_$.h9;
69
+ var contains = kotlin_kotlin.$_$.i2;
70
+ var Directive = kotlin_it_unibo_tuprolog_core.$_$.d1;
71
+ var Companion_getInstance = kotlin_it_unibo_tuprolog_core.$_$.g;
72
+ var map = kotlin_kotlin.$_$.j7;
73
+ var Operator = kotlin_it_unibo_tuprolog_core.$_$.z;
74
+ var List = kotlin_it_unibo_tuprolog_core.$_$.h1;
75
+ var toString_0 = kotlin_kotlin.$_$.x5;
76
+ var coerceAtLeast = kotlin_kotlin.$_$.i6;
77
+ var isRecognitionException = kotlin_it_unibo_tuprolog_parser_js.$_$.b;
78
+ var isParseCancellationException = kotlin_it_unibo_tuprolog_parser_js.$_$.a;
79
+ var generateSequence = kotlin_kotlin.$_$.d7;
80
+ var takeWhile = kotlin_kotlin.$_$.r7;
81
+ var to = kotlin_kotlin.$_$.s9;
82
+ var Companion_getInstance_0 = kotlin_io_github_gciatto_kt_math.$_$.e;
83
+ var charSequenceGet = kotlin_kotlin.$_$.u4;
84
+ var Char__toInt_impl_vasixd = kotlin_kotlin.$_$.i1;
85
+ var contains_0 = kotlin_kotlin.$_$.d8;
86
+ var plus = kotlin_kotlin.$_$.o9;
87
+ var ArrayList_init_$Create$ = kotlin_kotlin.$_$.e;
88
+ var IllegalStateException_init_$Create$ = kotlin_kotlin.$_$.v;
89
+ var listOf = kotlin_kotlin.$_$.d3;
90
+ var asList = kotlin_kotlin.$_$.a2;
91
+ var plus_0 = kotlin_kotlin.$_$.v3;
92
+ var collectionSizeOrDefault = kotlin_kotlin.$_$.g2;
93
+ var toList = kotlin_kotlin.$_$.e4;
94
+ var flatMap = kotlin_kotlin.$_$.b7;
95
+ var asSequence = kotlin_kotlin.$_$.e2;
96
+ var toList_0 = kotlin_kotlin.$_$.v7;
97
+ var sequenceOf = kotlin_kotlin.$_$.o7;
98
+ var asSequence_0 = kotlin_kotlin.$_$.f2;
99
+ var plus_1 = kotlin_kotlin.$_$.n7;
100
+ var Companion_instance_0 = kotlin_it_unibo_tuprolog_core.$_$.q;
101
+ var IllegalArgumentException_init_$Create$ = kotlin_kotlin.$_$.s;
102
+ var Term = kotlin_it_unibo_tuprolog_core.$_$.j2;
103
+ var Companion_getInstance_1 = kotlin_it_unibo_tuprolog_core.$_$.l;
104
+ var Companion_getInstance_2 = kotlin_it_unibo_tuprolog_core.$_$.o;
105
+ var NumberFormatException = kotlin_kotlin.$_$.e9;
106
+ //endregion
10
107
  //region block: pre-declaration
108
+ setMetadataFor(ParseException, 'ParseException', classMeta, TuPrologException);
109
+ setMetadataFor(InvalidTermTypeException, 'InvalidTermTypeException', classMeta, ParseException);
110
+ setMetadataFor(Companion, 'Companion', objectMeta);
111
+ setMetadataFor(DynamicOpListener, 'DynamicOpListener', classMeta, PrologParserListener);
112
+ setMetadataFor(PrologParserFactory$newErrorListener$1, VOID, classMeta);
113
+ setMetadataFor(PrologParserFactory, 'PrologParserFactory', objectMeta);
114
+ setMetadataFor(PrologVisitor, 'PrologVisitor', classMeta, PrologParserVisitor, VOID, PrologVisitor);
115
+ //endregion
116
+ function InvalidTermTypeException(input, term, type, offendingSymbol, line, column, message, throwable) {
117
+ var tmp;
118
+ if (offendingSymbol === VOID) {
119
+ var tmp0_elvis_lhs = (!(input == null) ? typeof input === 'string' : false) ? input : null;
120
+ tmp = tmp0_elvis_lhs == null ? term.toString() : tmp0_elvis_lhs;
121
+ } else {
122
+ tmp = offendingSymbol;
123
+ }
124
+ offendingSymbol = tmp;
125
+ line = line === VOID ? 1 : line;
126
+ column = column === VOID ? 1 : column;
127
+ message = message === VOID ? 'Expected ' + type.n6() + ', got: ' + offendingSymbol : message;
128
+ throwable = throwable === VOID ? null : throwable;
129
+ ParseException.call(this, input, offendingSymbol, line, column, message, throwable);
130
+ captureStack(this, InvalidTermTypeException);
131
+ this.f35_1 = term;
132
+ this.g35_1 = type;
133
+ }
134
+ function ParseException(input, offendingSymbol, line, column, message, throwable) {
135
+ TuPrologException_init_$Init$(message, throwable, this);
136
+ captureStack(this, ParseException);
137
+ this.input = input;
138
+ this.offendingSymbol = offendingSymbol;
139
+ this.line = line;
140
+ this.column = column;
141
+ this.clauseIndex = -1;
142
+ }
143
+ protoOf(ParseException).h35 = function (_set____db54di) {
144
+ this.input = _set____db54di;
145
+ };
146
+ protoOf(ParseException).i35 = function () {
147
+ return this.input;
148
+ };
149
+ protoOf(ParseException).j35 = function (_set____db54di) {
150
+ this.offendingSymbol = _set____db54di;
151
+ };
152
+ protoOf(ParseException).k35 = function () {
153
+ return this.offendingSymbol;
154
+ };
155
+ protoOf(ParseException).l35 = function (_set____db54di) {
156
+ this.line = _set____db54di;
157
+ };
158
+ protoOf(ParseException).m35 = function () {
159
+ return this.line;
160
+ };
161
+ protoOf(ParseException).n35 = function (_set____db54di) {
162
+ this.column = _set____db54di;
163
+ };
164
+ protoOf(ParseException).o35 = function () {
165
+ return this.column;
166
+ };
167
+ protoOf(ParseException).p35 = function (_set____db54di) {
168
+ this.clauseIndex = _set____db54di;
169
+ };
170
+ protoOf(ParseException).q35 = function () {
171
+ return this.clauseIndex;
172
+ };
173
+ protoOf(ParseException).toString = function () {
174
+ return "ParseException{message='" + replace(ensureNotNull(this.message), '\\n', '\\\\n') + new Char(_Char___init__impl__6a9atx(39)) + ', line=' + this.line + ', column=' + this.column + ", offendingSymbol='" + this.offendingSymbol + new Char(_Char___init__impl__6a9atx(39)) + toString(_Char___init__impl__6a9atx(125));
175
+ };
176
+ function get_isOpDirective(_this__u8e3s4) {
177
+ var tmp;
178
+ var tmp_0;
179
+ var tmp_1;
180
+ var tmp_2;
181
+ var tmp_3;
182
+ if (isInterface(_this__u8e3s4, Struct)) {
183
+ tmp_3 = _this__u8e3s4.eu() === 3;
184
+ } else {
185
+ tmp_3 = false;
186
+ }
187
+ if (tmp_3) {
188
+ tmp_2 = _this__u8e3s4.ku() === 'op';
189
+ } else {
190
+ tmp_2 = false;
191
+ }
192
+ if (tmp_2) {
193
+ tmp_1 = _this__u8e3s4.ov();
194
+ } else {
195
+ tmp_1 = false;
196
+ }
197
+ if (tmp_1) {
198
+ var tmp_4 = _this__u8e3s4.get(0);
199
+ tmp_0 = isInterface(tmp_4, Numeric);
200
+ } else {
201
+ tmp_0 = false;
202
+ }
203
+ if (tmp_0) {
204
+ var tmp_5 = _this__u8e3s4.get(1);
205
+ tmp = isInterface(tmp_5, Atom);
206
+ } else {
207
+ tmp = false;
208
+ }
209
+ return tmp;
210
+ }
211
+ function termToClause(_this__u8e3s4, source, line, column) {
212
+ source = source === VOID ? null : source;
213
+ line = line === VOID ? 0 : line;
214
+ column = column === VOID ? 0 : column;
215
+ var tmp;
216
+ if (isInterface(_this__u8e3s4, Clause)) {
217
+ tmp = _this__u8e3s4;
218
+ } else {
219
+ if (isInterface(_this__u8e3s4, Struct)) {
220
+ tmp = Companion_instance.of(_this__u8e3s4);
221
+ } else {
222
+ throw new InvalidTermTypeException(source, _this__u8e3s4, getKClass(Clause), VOID, line, column);
223
+ }
224
+ }
225
+ return tmp;
226
+ }
227
+ function toAssociativity(_this__u8e3s4) {
228
+ return _this__u8e3s4.toString();
229
+ }
230
+ function DynamicOpListener$Companion$of$lambda($this$$receiver, it) {
231
+ return Unit_instance;
232
+ }
233
+ function onOperatorDefined($this, operator) {
234
+ $this.r35_1.addOperator(operator.g1g_1, toAssociativity(operator.h1g_1), operator.i1g_1);
235
+ $this.s35_1($this.r35_1, operator);
236
+ }
237
+ function Companion() {
238
+ }
239
+ protoOf(Companion).t35 = function (parser) {
240
+ return new DynamicOpListener(parser, DynamicOpListener$Companion$of$lambda);
241
+ };
242
+ var Companion_instance_1;
243
+ function Companion_getInstance_3() {
244
+ return Companion_instance_1;
245
+ }
246
+ function DynamicOpListener$exitClause$lambda(it) {
247
+ return isInterface(it, Atom) ? it : THROW_CCE();
248
+ }
249
+ function DynamicOpListener(parser, operatorDefinedCallback) {
250
+ PrologParserListener.call(this);
251
+ this.r35_1 = parser;
252
+ this.s35_1 = operatorDefinedCallback;
253
+ }
254
+ protoOf(DynamicOpListener).u35 = function (ctx) {
255
+ var expr = ctx.expression();
256
+ if (ctx.exception != null) {
257
+ return Unit_instance;
258
+ }
259
+ var tmp;
260
+ var tmp_0;
261
+ if (!(expr._op == null)) {
262
+ var tmp0_safe_receiver = expr._op;
263
+ var tmp1_safe_receiver = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.symbol;
264
+ tmp_0 = ':-' === (tmp1_safe_receiver == null ? null : tmp1_safe_receiver.text);
265
+ } else {
266
+ tmp_0 = false;
267
+ }
268
+ if (tmp_0) {
269
+ tmp = contains(Associativity.PREFIX, expr.associativity);
270
+ } else {
271
+ tmp = false;
272
+ }
273
+ if (tmp) {
274
+ var tmp_1 = ctx.accept(new PrologVisitor());
275
+ var directive = isInterface(tmp_1, Directive) ? tmp_1 : THROW_CCE();
276
+ var op = directive.rw();
277
+ if (get_isOpDirective(op)) {
278
+ // Inline function 'kotlin.math.min' call
279
+ // Inline function 'kotlin.math.max' call
280
+ var tmp_2 = (isInterface(op, Struct) ? op : THROW_CCE()).get(0);
281
+ var b = (isInterface(tmp_2, Numeric) ? tmp_2 : THROW_CCE()).sy().toInt();
282
+ var b_0 = Math.max(0, b);
283
+ var priority = Math.min(1200, b_0);
284
+ var specifier = Companion_getInstance().fromTerm(op.get(1));
285
+ var operator = op.get(2);
286
+ if (isInterface(operator, Atom)) {
287
+ onOperatorDefined(this, new Operator(operator.q2(), specifier, priority));
288
+ } else {
289
+ if (isInterface(operator, List)) {
290
+ var tmp$ret$3;
291
+ $l$block: {
292
+ // Inline function 'kotlin.sequences.all' call
293
+ var tmp0_iterator = operator.at().o();
294
+ while (tmp0_iterator.p()) {
295
+ var element = tmp0_iterator.r();
296
+ // Inline function 'it.unibo.tuprolog.core.parsing.DynamicOpListener.exitClause.<anonymous>' call
297
+ if (!isInterface(element, Atom)) {
298
+ tmp$ret$3 = false;
299
+ break $l$block;
300
+ }
301
+ }
302
+ tmp$ret$3 = true;
303
+ }
304
+ if (tmp$ret$3) {
305
+ var tmp_3 = operator.at();
306
+ var tmp2_iterator = map(tmp_3, DynamicOpListener$exitClause$lambda).o();
307
+ while (tmp2_iterator.p()) {
308
+ var it = tmp2_iterator.r();
309
+ onOperatorDefined(this, new Operator(it.q2(), specifier, priority));
310
+ }
311
+ }
312
+ }
313
+ }
314
+ }
315
+ }
316
+ };
317
+ protoOf(DynamicOpListener).exitClause = function (ctx) {
318
+ return this.u35(ctx);
319
+ };
320
+ function parseException(token, message) {
321
+ return new ParseException(null, token.text, token.line, token.column, message, null);
322
+ }
323
+ function symbolToString($this, obj) {
324
+ var tmp;
325
+ if (obj instanceof Token) {
326
+ tmp = obj.text;
327
+ } else {
328
+ tmp = toString_0(obj);
329
+ }
330
+ return tmp;
331
+ }
332
+ function newErrorListener($this, whileParsing) {
333
+ return new PrologParserFactory$newErrorListener$1(whileParsing);
334
+ }
335
+ function parseClause($this, parserAndErrorStrategy, source) {
336
+ var mark = -1;
337
+ var index = -1;
338
+ var parser = parserAndErrorStrategy.md_1;
339
+ var tmp;
340
+ try {
341
+ mark = parser.getTokenStream().mark();
342
+ index = coerceAtLeast(parser.getTokenStream().index, 0);
343
+ tmp = parser.optClause();
344
+ } catch ($p) {
345
+ var tmp_0;
346
+ var e = $p;
347
+ var tmp_1;
348
+ if (isParseCancellationException(e) ? parser._interp.predictionMode === PredictionMode.SLL : false) {
349
+ parser.getTokenStream().seek(index);
350
+ parser._interp.predictionMode = PredictionMode.LL;
351
+ parser._errHandler = parserAndErrorStrategy.nd_1;
352
+ parser.addErrorListener(newErrorListener($this, source));
353
+ tmp_1 = parseClause($this, parserAndErrorStrategy, source);
354
+ } else if (e.clause !== null ? isRecognitionException(e.cause) : false) {
355
+ var tmp_2 = e.cause;
356
+ throw tmp_2 instanceof RecognitionException ? tmp_2 : THROW_CCE();
357
+ } else {
358
+ throw e instanceof Error ? e : THROW_CCE();
359
+ }
360
+ tmp_0 = tmp_1;
361
+ tmp = tmp_0;
362
+ }
363
+ finally {
364
+ parser.getTokenStream().release(mark);
365
+ }
366
+ return tmp;
367
+ }
368
+ function parseClauses($this, parser, source) {
369
+ var tmp = generateSequence(0, PrologParserFactory$parseClauses$lambda);
370
+ var tmp_0 = map(tmp, PrologParserFactory$parseClauses$lambda_0(parser, source));
371
+ var tmp_1 = takeWhile(tmp_0, PrologParserFactory$parseClauses$lambda_1);
372
+ return map(tmp_1, PrologParserFactory$parseClauses$lambda_2);
373
+ }
374
+ function PrologParserFactory$newErrorListener$1($whileParsing) {
375
+ this.v35_1 = $whileParsing;
376
+ }
377
+ protoOf(PrologParserFactory$newErrorListener$1).syntaxError = function (recognizer, offendingSymbol, line, column, msg, e) {
378
+ if (recognizer instanceof PrologParser) {
379
+ recognizer.removeParseListeners();
380
+ }
381
+ throw new ParseException(this.v35_1, symbolToString(this, offendingSymbol), line, column + 1 | 0, msg, e);
382
+ };
383
+ function PrologParserFactory$parseClauses$lambda(it) {
384
+ return it + 1 | 0;
385
+ }
386
+ function PrologParserFactory$parseClauses$lambda_0($parser, $source) {
387
+ return function (it) {
388
+ var tmp;
389
+ try {
390
+ tmp = parseClause(PrologParserFactory_instance, $parser, $source);
391
+ } catch ($p) {
392
+ var tmp_0;
393
+ if ($p instanceof ParseException) {
394
+ var e = $p;
395
+ e.clauseIndex = it;
396
+ throw e;
397
+ } else {
398
+ throw $p;
399
+ }
400
+ }
401
+ return tmp;
402
+ };
403
+ }
404
+ function PrologParserFactory$parseClauses$lambda_1(it) {
405
+ return !it.isOver;
406
+ }
407
+ function PrologParserFactory$parseClauses$lambda_2(it) {
408
+ return it.clause();
409
+ }
410
+ function PrologParserFactory() {
411
+ }
412
+ protoOf(PrologParserFactory).w35 = function (source, withOperators) {
413
+ var parser = this.x35(source, withOperators);
414
+ return parseClauses(this, parser, source);
415
+ };
416
+ protoOf(PrologParserFactory).x35 = function (source, operators) {
417
+ var stream = new InputStream(source);
418
+ var lexer = new PrologLexer(stream);
419
+ lexer.removeErrorListeners();
420
+ var tokenStream = new CommonTokenStream(lexer);
421
+ var parser = new PrologParser(tokenStream);
422
+ parser.removeErrorListeners();
423
+ var originalErrorStrategy = parser._errHandler;
424
+ parser._errHandler = new BailErrorStrategy();
425
+ parser._interp.predictionMode = PredictionMode.SLL;
426
+ return to(this.y35(parser, operators), originalErrorStrategy);
427
+ };
428
+ protoOf(PrologParserFactory).y35 = function (prologParser, operators) {
429
+ // Inline function 'kotlin.collections.forEach' call
430
+ var tmp0_iterator = operators.o();
431
+ while (tmp0_iterator.p()) {
432
+ var element = tmp0_iterator.r();
433
+ // Inline function 'it.unibo.tuprolog.core.parsing.PrologParserFactory.addOperators.<anonymous>' call
434
+ prologParser.addOperator(element.g1g_1, toAssociativity(element.h1g_1), element.i1g_1);
435
+ }
436
+ prologParser.addParseListener(Companion_instance_1.t35(prologParser));
437
+ return prologParser;
438
+ };
439
+ var PrologParserFactory_instance;
440
+ function PrologParserFactory_getInstance() {
441
+ return PrologParserFactory_instance;
442
+ }
443
+ function parseInteger($this, ctx) {
444
+ var str = ctx.value.text;
445
+ var base;
446
+ var clean;
447
+ if (ctx.isBin) {
448
+ base = 2;
449
+ // Inline function 'kotlin.text.substring' call
450
+ // Inline function 'kotlin.js.asDynamic' call
451
+ clean = str.substring(2);
452
+ } else if (ctx.isOct) {
453
+ base = 8;
454
+ // Inline function 'kotlin.text.substring' call
455
+ // Inline function 'kotlin.js.asDynamic' call
456
+ clean = str.substring(2);
457
+ } else if (ctx.isHex) {
458
+ base = 16;
459
+ // Inline function 'kotlin.text.substring' call
460
+ // Inline function 'kotlin.js.asDynamic' call
461
+ clean = str.substring(2);
462
+ } else if (ctx.isChar) {
463
+ // Inline function 'kotlin.text.substring' call
464
+ // Inline function 'kotlin.js.asDynamic' call
465
+ clean = str.substring(2);
466
+ if (!(clean.length === 1)) {
467
+ throw parseException(ctx.value, 'Invalid character literal: ' + ctx.value.text);
468
+ }
469
+ // Inline function 'kotlin.with' call
470
+ var tmp = Companion_getInstance_0();
471
+ // Inline function 'kotlin.code' call
472
+ var this_0 = charSequenceGet(clean, 0);
473
+ var tmp$ret$8 = Char__toInt_impl_vasixd(this_0);
474
+ // Inline function 'kotlin.contracts.contract' call
475
+ // Inline function 'it.unibo.tuprolog.core.parsing.PrologVisitor.parseInteger.<anonymous>' call
476
+ var $this$with = tmp.of(tmp$ret$8);
477
+ var tmp_0;
478
+ var tmp0_safe_receiver = ctx.sign;
479
+ var tmp1_safe_receiver = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.text;
480
+ var tmp2_elvis_lhs = tmp1_safe_receiver == null ? null : contains_0(tmp1_safe_receiver, '-');
481
+ if (tmp2_elvis_lhs == null ? false : tmp2_elvis_lhs) {
482
+ tmp_0 = $this$with.unaryMinus();
483
+ } else {
484
+ tmp_0 = $this$with;
485
+ }
486
+ return tmp_0;
487
+ } else {
488
+ base = 10;
489
+ clean = str;
490
+ }
491
+ if (!(ctx.sign == null)) {
492
+ var tmp0_safe_receiver_0 = ctx.sign;
493
+ clean = plus(tmp0_safe_receiver_0 == null ? null : tmp0_safe_receiver_0.text, clean);
494
+ }
495
+ return Companion_getInstance_0().parseWithRadix(clean, base);
496
+ }
497
+ function visitPostfixExpression($this, ctx) {
498
+ var tmp0_safe_receiver = ctx.left;
499
+ var tmp = ensureNotNull(tmp0_safe_receiver == null ? null : tmp0_safe_receiver.accept($this));
500
+ // Inline function 'kotlin.collections.map' call
501
+ var this_0 = ctx.operators;
502
+ // Inline function 'kotlin.collections.mapTo' call
503
+ var destination = ArrayList_init_$Create$(this_0.length);
504
+ var inductionVariable = 0;
505
+ var last = this_0.length;
506
+ while (inductionVariable < last) {
507
+ var item = this_0[inductionVariable];
508
+ inductionVariable = inductionVariable + 1 | 0;
509
+ // Inline function 'it.unibo.tuprolog.core.parsing.PrologVisitor.visitPostfixExpression.<anonymous>' call
510
+ var tmp$ret$0 = item.symbol.text;
511
+ destination.l(tmp$ret$0);
512
+ }
513
+ return postfix($this, tmp, destination);
514
+ }
515
+ function postfix($this, term, ops) {
516
+ var operator = ops.o();
517
+ var result = $this.z35_1.structOf(operator.r(), [term]);
518
+ while (operator.p()) {
519
+ result = $this.z35_1.structOf(operator.r(), [result]);
520
+ }
521
+ return result;
522
+ }
523
+ function visitPrefixExpression($this, ctx) {
524
+ var tmp = ctx.right[0].accept($this);
525
+ // Inline function 'kotlin.collections.map' call
526
+ var this_0 = ctx.operators;
527
+ // Inline function 'kotlin.collections.mapTo' call
528
+ var destination = ArrayList_init_$Create$(this_0.length);
529
+ var inductionVariable = 0;
530
+ var last = this_0.length;
531
+ while (inductionVariable < last) {
532
+ var item = this_0[inductionVariable];
533
+ inductionVariable = inductionVariable + 1 | 0;
534
+ // Inline function 'it.unibo.tuprolog.core.parsing.PrologVisitor.visitPrefixExpression.<anonymous>' call
535
+ var tmp$ret$0 = item.symbol.text;
536
+ destination.l(tmp$ret$0);
537
+ }
538
+ return prefix($this, tmp, destination);
539
+ }
540
+ function prefix($this, term, ops) {
541
+ var i = ops.u() - 1 | 0;
542
+ var tmp0 = i;
543
+ i = tmp0 - 1 | 0;
544
+ var result = $this.z35_1.structOf(ops.a1(tmp0), [term]);
545
+ while (i >= 0) {
546
+ result = $this.z35_1.structOf(ops.a1(i), [result]);
547
+ i = i - 1 | 0;
548
+ }
549
+ return result;
550
+ }
551
+ function visitInfixExpression($this, ctx) {
552
+ var tmp0_subject = ctx.associativity;
553
+ var tmp;
554
+ if (tmp0_subject === Associativity.XFY) {
555
+ tmp = visitInfixRightAssociativeExpression($this, ctx);
556
+ } else if (tmp0_subject === Associativity.YFX) {
557
+ tmp = visitInfixLeftAssociativeExpression($this, ctx);
558
+ } else if (tmp0_subject === Associativity.XFX) {
559
+ tmp = visitInfixNonAssociativeExpression($this, ctx);
560
+ } else {
561
+ var message = 'Non-infix associativity ' + ctx.associativity + ' in infix expression';
562
+ throw IllegalStateException_init_$Create$(toString_0(message));
563
+ }
564
+ return tmp;
565
+ }
566
+ function visitInfixNonAssociativeExpression($this, ctx) {
567
+ // Inline function 'kotlin.collections.map' call
568
+ var this_0 = plus_0(listOf(ensureNotNull(ctx.left)), asList(ctx.right));
569
+ // Inline function 'kotlin.collections.mapTo' call
570
+ var destination = ArrayList_init_$Create$(collectionSizeOrDefault(this_0, 10));
571
+ var tmp0_iterator = this_0.o();
572
+ while (tmp0_iterator.p()) {
573
+ var item = tmp0_iterator.r();
574
+ // Inline function 'it.unibo.tuprolog.core.parsing.PrologVisitor.visitInfixNonAssociativeExpression.<anonymous>' call
575
+ var tmp$ret$0 = item.accept($this);
576
+ destination.l(tmp$ret$0);
577
+ }
578
+ var operands = destination;
579
+ // Inline function 'kotlin.collections.map' call
580
+ var this_1 = ctx.operators;
581
+ // Inline function 'kotlin.collections.mapTo' call
582
+ var destination_0 = ArrayList_init_$Create$(this_1.length);
583
+ var inductionVariable = 0;
584
+ var last = this_1.length;
585
+ while (inductionVariable < last) {
586
+ var item_0 = this_1[inductionVariable];
587
+ inductionVariable = inductionVariable + 1 | 0;
588
+ // Inline function 'it.unibo.tuprolog.core.parsing.PrologVisitor.visitInfixNonAssociativeExpression.<anonymous>' call
589
+ var tmp$ret$3 = item_0.symbol.text;
590
+ destination_0.l(tmp$ret$3);
591
+ }
592
+ var operators = destination_0;
593
+ return infixNonAssociative($this, operands, operators);
594
+ }
595
+ function infixNonAssociative($this, terms, ops) {
596
+ return $this.z35_1.structOf(ops.a1(0), [terms.a1(0), terms.a1(1)]);
597
+ }
598
+ function handleOuters($this, expression, outers) {
599
+ var result = expression;
600
+ var tmp0_iterator = outers.o();
601
+ while (tmp0_iterator.p()) {
602
+ var o = tmp0_iterator.r();
603
+ var tmp = listOf(result);
604
+ // Inline function 'kotlin.collections.map' call
605
+ var this_0 = o.right;
606
+ // Inline function 'kotlin.collections.mapTo' call
607
+ var destination = ArrayList_init_$Create$(this_0.length);
608
+ var inductionVariable = 0;
609
+ var last = this_0.length;
610
+ while (inductionVariable < last) {
611
+ var item = this_0[inductionVariable];
612
+ inductionVariable = inductionVariable + 1 | 0;
613
+ // Inline function 'it.unibo.tuprolog.core.parsing.PrologVisitor.handleOuters.<anonymous>' call
614
+ var tmp$ret$0 = item.accept($this);
615
+ destination.l(tmp$ret$0);
616
+ }
617
+ var operands = plus_0(tmp, destination);
618
+ // Inline function 'kotlin.collections.map' call
619
+ var this_1 = o.operators;
620
+ // Inline function 'kotlin.collections.mapTo' call
621
+ var destination_0 = ArrayList_init_$Create$(this_1.length);
622
+ var inductionVariable_0 = 0;
623
+ var last_0 = this_1.length;
624
+ while (inductionVariable_0 < last_0) {
625
+ var item_0 = this_1[inductionVariable_0];
626
+ inductionVariable_0 = inductionVariable_0 + 1 | 0;
627
+ // Inline function 'it.unibo.tuprolog.core.parsing.PrologVisitor.handleOuters.<anonymous>' call
628
+ var tmp$ret$3 = item_0.symbol.text;
629
+ destination_0.l(tmp$ret$3);
630
+ }
631
+ var operators = destination_0;
632
+ var associativity = o.associativity;
633
+ var tmp_0;
634
+ if (associativity === Associativity.XFY) {
635
+ tmp_0 = infixRight($this, operands, operators);
636
+ } else if (associativity === Associativity.XF ? true : associativity === Associativity.YF) {
637
+ tmp_0 = postfix($this, result, operators);
638
+ } else if (associativity === Associativity.XFX) {
639
+ tmp_0 = infixNonAssociative($this, operands, operators);
640
+ } else if (associativity === Associativity.YFX) {
641
+ tmp_0 = infixLeft($this, operands, operators);
642
+ } else if (associativity === Associativity.FX ? true : associativity === Associativity.FY) {
643
+ tmp_0 = prefix($this, result, operators);
644
+ } else {
645
+ var message = 'Invalid associativity: ' + associativity;
646
+ throw IllegalStateException_init_$Create$(toString_0(message));
647
+ }
648
+ result = tmp_0;
649
+ }
650
+ return result;
651
+ }
652
+ function infixRight($this, terms, ops) {
653
+ var i = terms.u() - 1 | 0;
654
+ var j = ops.u() - 1 | 0;
655
+ var tmp0 = j;
656
+ j = tmp0 - 1 | 0;
657
+ var result = $this.z35_1.structOf(ops.a1(tmp0), [terms.a1(i - 1 | 0), terms.a1(i)]);
658
+ i = i - 2 | 0;
659
+ while (i >= 0) {
660
+ var tmp1 = j;
661
+ j = tmp1 - 1 | 0;
662
+ result = $this.z35_1.structOf(ops.a1(tmp1), [terms.a1(i), result]);
663
+ i = i - 1 | 0;
664
+ }
665
+ return result;
666
+ }
667
+ function infixLeft($this, terms, ops) {
668
+ var i = 0;
669
+ var j = 0;
670
+ var tmp0 = j;
671
+ j = tmp0 + 1 | 0;
672
+ var tmp = ops.a1(tmp0);
673
+ var tmp1 = i;
674
+ i = tmp1 + 1 | 0;
675
+ var tmp_0 = terms.a1(tmp1);
676
+ var tmp2 = i;
677
+ i = tmp2 + 1 | 0;
678
+ var result = $this.z35_1.structOf(tmp, [tmp_0, terms.a1(tmp2)]);
679
+ while (i < terms.u()) {
680
+ var tmp3 = j;
681
+ j = tmp3 + 1 | 0;
682
+ result = $this.z35_1.structOf(ops.a1(tmp3), [result, terms.a1(i)]);
683
+ i = i + 1 | 0;
684
+ }
685
+ return result;
686
+ }
687
+ function listOfOperands($this, ctx) {
688
+ // Inline function 'kotlin.collections.map' call
689
+ var this_0 = plus_0(listOf(ctx.left), toList(ctx.right));
690
+ // Inline function 'kotlin.collections.mapTo' call
691
+ var destination = ArrayList_init_$Create$(collectionSizeOrDefault(this_0, 10));
692
+ var tmp0_iterator = this_0.o();
693
+ while (tmp0_iterator.p()) {
694
+ var item = tmp0_iterator.r();
695
+ // Inline function 'it.unibo.tuprolog.core.parsing.PrologVisitor.listOfOperands.<anonymous>' call
696
+ var tmp$ret$0 = ensureNotNull(item).accept($this);
697
+ destination.l(tmp$ret$0);
698
+ }
699
+ return destination;
700
+ }
701
+ function listOfOperators($this, ctx) {
702
+ // Inline function 'kotlin.collections.map' call
703
+ var this_0 = ctx.operators;
704
+ // Inline function 'kotlin.collections.mapTo' call
705
+ var destination = ArrayList_init_$Create$(this_0.length);
706
+ var inductionVariable = 0;
707
+ var last = this_0.length;
708
+ while (inductionVariable < last) {
709
+ var item = this_0[inductionVariable];
710
+ inductionVariable = inductionVariable + 1 | 0;
711
+ // Inline function 'it.unibo.tuprolog.core.parsing.PrologVisitor.listOfOperators.<anonymous>' call
712
+ var tmp$ret$0 = item.symbol.text;
713
+ destination.l(tmp$ret$0);
714
+ }
715
+ return destination;
716
+ }
717
+ function visitInfixRightAssociativeExpression($this, ctx) {
718
+ return infixRight($this, listOfOperands($this, ctx), listOfOperators($this, ctx));
719
+ }
720
+ function visitInfixLeftAssociativeExpression($this, ctx) {
721
+ return infixLeft($this, listOfOperands($this, ctx), listOfOperators($this, ctx));
722
+ }
723
+ function flatten($this, outers) {
724
+ // Inline function 'kotlin.sequences.asSequence' call
725
+ var tmp = outers;
726
+ return flatMap(tmp, PrologVisitor$flatten$lambda($this));
727
+ }
728
+ function flatten_0($this, outers) {
729
+ return toList_0(flatten($this, asSequence(outers)));
730
+ }
731
+ function PrologVisitor$visitExpression$ref($boundThis) {
732
+ var l = function (p0) {
733
+ return $boundThis.a36(p0);
734
+ };
735
+ l.callableName = 'visitExpression';
736
+ return l;
737
+ }
738
+ function PrologVisitor$flatten$lambda(this$0) {
739
+ return function (it) {
740
+ return plus_1(sequenceOf([it]), flatten(this$0, asSequence_0(it.outers)));
741
+ };
742
+ }
743
+ function PrologVisitor(scope) {
744
+ scope = scope === VOID ? Companion_instance_0.empty() : scope;
745
+ PrologParserVisitor.call(this);
746
+ this.z35_1 = scope;
747
+ }
748
+ protoOf(PrologVisitor).b36 = function (ctx) {
749
+ return this.c36(ctx.term());
750
+ };
751
+ protoOf(PrologVisitor).visitSingletonTerm = function (ctx) {
752
+ return this.b36(ctx);
753
+ };
754
+ protoOf(PrologVisitor).d36 = function (ctx) {
755
+ return this.a36(ctx.expression());
756
+ };
757
+ protoOf(PrologVisitor).visitSingletonExpression = function (ctx) {
758
+ return this.d36(ctx);
759
+ };
760
+ protoOf(PrologVisitor).e36 = function (ctx) {
761
+ return termToClause(ctx.expression().accept(this), null, ensureNotNull(ctx.start).line, ensureNotNull(ctx.start).column);
762
+ };
763
+ protoOf(PrologVisitor).visitClause = function (ctx) {
764
+ return this.e36(ctx);
765
+ };
766
+ protoOf(PrologVisitor).a36 = function (ctx) {
767
+ var tmp;
768
+ if (ctx.isTerm) {
769
+ tmp = this.c36(ensureNotNull(ctx.left));
770
+ } else if (contains(Associativity.INFIX, ctx.associativity)) {
771
+ tmp = visitInfixExpression(this, ctx);
772
+ } else if (contains(Associativity.POSTFIX, ctx.associativity)) {
773
+ tmp = visitPostfixExpression(this, ctx);
774
+ } else if (contains(Associativity.PREFIX, ctx.associativity)) {
775
+ tmp = visitPrefixExpression(this, ctx);
776
+ } else {
777
+ throw IllegalArgumentException_init_$Create$('Associativity unknown: ' + ctx.associativity + ' INFIX=' + Associativity.INFIX + ' PREFIX=' + Associativity.PREFIX + ' POSTFIX=' + Associativity.POSTFIX);
778
+ }
779
+ return handleOuters(this, tmp, flatten_0(this, asList(ctx.outers)));
780
+ };
781
+ protoOf(PrologVisitor).visitExpression = function (ctx) {
782
+ return this.a36(ctx);
783
+ };
784
+ protoOf(PrologVisitor).c36 = function (ctx) {
785
+ var tmp;
786
+ if (ctx.isExpr) {
787
+ tmp = this.a36(ctx.expression());
788
+ } else {
789
+ var tmp_0 = ctx.children[0].accept(this);
790
+ tmp = (!(tmp_0 == null) ? isInterface(tmp_0, Term) : false) ? tmp_0 : THROW_CCE();
791
+ }
792
+ return tmp;
793
+ };
794
+ protoOf(PrologVisitor).visitTerm = function (ctx) {
795
+ return this.c36(ctx);
796
+ };
797
+ protoOf(PrologVisitor).f36 = function (ctx) {
798
+ var value = parseInteger(this, ctx);
799
+ return Companion_getInstance_1().ofBigInteger(value);
800
+ };
801
+ protoOf(PrologVisitor).visitInteger = function (ctx) {
802
+ return this.f36(ctx);
803
+ };
804
+ protoOf(PrologVisitor).g36 = function (ctx) {
805
+ var tmp = ctx.children[0].accept(this);
806
+ return (!(tmp == null) ? isInterface(tmp, Term) : false) ? tmp : THROW_CCE();
807
+ };
808
+ protoOf(PrologVisitor).visitNumber = function (ctx) {
809
+ return this.g36(ctx);
810
+ };
811
+ protoOf(PrologVisitor).h36 = function (ctx) {
812
+ var raw = ctx.value.text;
813
+ if (!(ctx.sign == null)) {
814
+ var tmp0_safe_receiver = ctx.sign;
815
+ raw = plus(tmp0_safe_receiver == null ? null : tmp0_safe_receiver.text, raw);
816
+ }
817
+ var tmp;
818
+ try {
819
+ tmp = Companion_getInstance_2().parse(raw);
820
+ } catch ($p) {
821
+ var tmp_0;
822
+ if ($p instanceof NumberFormatException) {
823
+ var notAFloating = $p;
824
+ throw parseException(ctx.value, 'Invalid real number format: ' + ctx.value.text);
825
+ } else {
826
+ throw $p;
827
+ }
828
+ }
829
+ return tmp;
830
+ };
831
+ protoOf(PrologVisitor).visitReal = function (ctx) {
832
+ return this.h36(ctx);
833
+ };
834
+ protoOf(PrologVisitor).i36 = function (ctx) {
835
+ var tmp;
836
+ if (ctx.isAnonymous) {
837
+ tmp = this.z35_1.anonymous();
838
+ } else {
839
+ tmp = this.z35_1.varOf(ctx.value.text);
840
+ }
841
+ return tmp;
842
+ };
843
+ protoOf(PrologVisitor).visitVariable = function (ctx) {
844
+ return this.i36(ctx);
845
+ };
846
+ protoOf(PrologVisitor).j36 = function (ctx) {
847
+ var tmp;
848
+ if (ctx.isList) {
849
+ tmp = this.z35_1.logicListOf([]);
850
+ } else if (ctx.isBlock) {
851
+ tmp = this.z35_1.blockOf([]);
852
+ } else if (ctx.arity === 0) {
853
+ tmp = this.z35_1.atomOf(ctx.functor.text);
854
+ } else {
855
+ var tmp_0 = ctx.functor.text;
856
+ var tmp_1 = asSequence_0(ctx.args);
857
+ tmp = this.z35_1.structOfSequence(tmp_0, map(tmp_1, PrologVisitor$visitExpression$ref(this)));
858
+ }
859
+ return tmp;
860
+ };
861
+ protoOf(PrologVisitor).visitStructure = function (ctx) {
862
+ return this.j36(ctx);
863
+ };
864
+ protoOf(PrologVisitor).k36 = function (ctx) {
865
+ // Inline function 'kotlin.collections.map' call
866
+ var this_0 = ctx.items;
867
+ // Inline function 'kotlin.collections.mapTo' call
868
+ var destination = ArrayList_init_$Create$(this_0.length);
869
+ var inductionVariable = 0;
870
+ var last = this_0.length;
871
+ while (inductionVariable < last) {
872
+ var item = this_0[inductionVariable];
873
+ inductionVariable = inductionVariable + 1 | 0;
874
+ var tmp$ret$0 = this.a36(item);
875
+ destination.l(tmp$ret$0);
876
+ }
877
+ var terms = destination;
878
+ var tmp;
879
+ if (ctx.hasTail) {
880
+ var tmp0_safe_receiver = ctx.tail;
881
+ tmp = this.z35_1.b10(terms, tmp0_safe_receiver == null ? null : tmp0_safe_receiver.accept(this));
882
+ } else {
883
+ tmp = this.z35_1.logicListOfIterable(terms);
884
+ }
885
+ return tmp;
886
+ };
887
+ protoOf(PrologVisitor).visitList = function (ctx) {
888
+ return this.k36(ctx);
889
+ };
890
+ protoOf(PrologVisitor).l36 = function (ctx) {
891
+ var tmp;
892
+ if (ctx.length === 1) {
893
+ tmp = this.z35_1.blockOf([ctx.items[0].accept(this)]);
894
+ } else {
895
+ // Inline function 'kotlin.collections.map' call
896
+ var this_0 = ctx.items;
897
+ // Inline function 'kotlin.collections.mapTo' call
898
+ var destination = ArrayList_init_$Create$(this_0.length);
899
+ var inductionVariable = 0;
900
+ var last = this_0.length;
901
+ while (inductionVariable < last) {
902
+ var item = this_0[inductionVariable];
903
+ inductionVariable = inductionVariable + 1 | 0;
904
+ var tmp$ret$0 = this.a36(item);
905
+ destination.l(tmp$ret$0);
906
+ }
907
+ tmp = this.z35_1.blockOfIterable(destination);
908
+ }
909
+ return tmp;
910
+ };
911
+ protoOf(PrologVisitor).visitBlock = function (ctx) {
912
+ return this.l36(ctx);
913
+ };
914
+ //region block: init
915
+ Companion_instance_1 = new Companion();
916
+ PrologParserFactory_instance = new PrologParserFactory();
917
+ //endregion
918
+ //region block: exports
919
+ _.$_$ = _.$_$ || {};
920
+ _.$_$.a = PrologParserFactory_instance;
921
+ _.$_$.b = PrologVisitor;
922
+ _.$_$.c = termToClause;
11
923
  //endregion
12
924
  return _;
13
925
  }));