@stordata/grammars 1.0.20230421155415
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/.eslintrc.json +13 -0
- package/.gitlab-ci.yml +49 -0
- package/.nvmrc +2 -0
- package/README.md +26 -0
- package/dist/main.cjs +2 -0
- package/dist/main.cjs.LICENSE.txt +1 -0
- package/generated/src/grammars/CustomMetric.interp +55 -0
- package/generated/src/grammars/CustomMetric.tokens +30 -0
- package/generated/src/grammars/CustomMetricLexer.interp +80 -0
- package/generated/src/grammars/CustomMetricLexer.js +94 -0
- package/generated/src/grammars/CustomMetricLexer.tokens +30 -0
- package/generated/src/grammars/CustomMetricListener.js +81 -0
- package/generated/src/grammars/CustomMetricParser.js +579 -0
- package/package.json +42 -0
- package/src/GrammarSyntaxError.js +10 -0
- package/src/ThrowingErrorListener.js +11 -0
- package/src/grammars/CustomMetric.g4 +38 -0
- package/src/grammars/parseCustomMetric.js +7 -0
- package/src/grammars/parseCustomMetric.spec.js +50 -0
- package/src/index.js +20 -0
- package/src/parse.js +18 -0
- package/src/walk.js +7 -0
- package/webpack.config.js +8 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
// Generated from src/grammars/CustomMetric.g4 by ANTLR 4.12.0
|
|
2
|
+
// jshint ignore: start
|
|
3
|
+
import antlr4 from 'antlr4';
|
|
4
|
+
import CustomMetricListener from './CustomMetricListener.js';
|
|
5
|
+
const serializedATN = [4,1,21,34,2,0,7,0,2,1,7,1,1,0,1,0,1,0,1,1,1,1,1,1,
|
|
6
|
+
1,1,1,1,1,1,1,1,3,1,15,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
7
|
+
1,5,1,29,8,1,10,1,12,1,32,9,1,1,1,0,1,2,2,0,2,0,0,37,0,4,1,0,0,0,2,14,1,
|
|
8
|
+
0,0,0,4,5,3,2,1,0,5,6,5,0,0,1,6,1,1,0,0,0,7,8,6,1,-1,0,8,9,5,10,0,0,9,10,
|
|
9
|
+
3,2,1,0,10,11,5,11,0,0,11,15,1,0,0,0,12,15,5,1,0,0,13,15,5,2,0,0,14,7,1,
|
|
10
|
+
0,0,0,14,12,1,0,0,0,14,13,1,0,0,0,15,30,1,0,0,0,16,17,10,7,0,0,17,18,5,4,
|
|
11
|
+
0,0,18,29,3,2,1,8,19,20,10,6,0,0,20,21,5,5,0,0,21,29,3,2,1,7,22,23,10,5,
|
|
12
|
+
0,0,23,24,5,6,0,0,24,29,3,2,1,6,25,26,10,4,0,0,26,27,5,7,0,0,27,29,3,2,1,
|
|
13
|
+
5,28,16,1,0,0,0,28,19,1,0,0,0,28,22,1,0,0,0,28,25,1,0,0,0,29,32,1,0,0,0,
|
|
14
|
+
30,28,1,0,0,0,30,31,1,0,0,0,31,3,1,0,0,0,32,30,1,0,0,0,3,14,28,30];
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const atn = new antlr4.atn.ATNDeserializer().deserialize(serializedATN);
|
|
18
|
+
|
|
19
|
+
const decisionsToDFA = atn.decisionToState.map( (ds, index) => new antlr4.dfa.DFA(ds, index) );
|
|
20
|
+
|
|
21
|
+
const sharedContextCache = new antlr4.atn.PredictionContextCache();
|
|
22
|
+
|
|
23
|
+
export default class CustomMetricParser extends antlr4.Parser {
|
|
24
|
+
|
|
25
|
+
static grammarFileName = "CustomMetric.g4";
|
|
26
|
+
static literalNames = [ null, null, null, null, null, null, null, null,
|
|
27
|
+
null, "'.'", "'('", "')'", "'+'", "'-'", "'*'",
|
|
28
|
+
"'/'", "'\"'", "' '" ];
|
|
29
|
+
static symbolicNames = [ null, "NUMBER", "STRING", "WHITESPACE", "ADD",
|
|
30
|
+
"SUBTRACT", "MULTIPLY", "DIVIDE", "DIGIT",
|
|
31
|
+
"DOT", "L_PARANT", "R_PARANT", "PLUS", "MINUS",
|
|
32
|
+
"STAR", "SLASH", "DQUOTE", "SPACE", "TAB",
|
|
33
|
+
"CR", "LF", "ANY" ];
|
|
34
|
+
static ruleNames = [ "all", "expression" ];
|
|
35
|
+
|
|
36
|
+
constructor(input) {
|
|
37
|
+
super(input);
|
|
38
|
+
this._interp = new antlr4.atn.ParserATNSimulator(this, atn, decisionsToDFA, sharedContextCache);
|
|
39
|
+
this.ruleNames = CustomMetricParser.ruleNames;
|
|
40
|
+
this.literalNames = CustomMetricParser.literalNames;
|
|
41
|
+
this.symbolicNames = CustomMetricParser.symbolicNames;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
sempred(localctx, ruleIndex, predIndex) {
|
|
45
|
+
switch(ruleIndex) {
|
|
46
|
+
case 1:
|
|
47
|
+
return this.expression_sempred(localctx, predIndex);
|
|
48
|
+
default:
|
|
49
|
+
throw "No predicate with index:" + ruleIndex;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
expression_sempred(localctx, predIndex) {
|
|
54
|
+
switch(predIndex) {
|
|
55
|
+
case 0:
|
|
56
|
+
return this.precpred(this._ctx, 7);
|
|
57
|
+
case 1:
|
|
58
|
+
return this.precpred(this._ctx, 6);
|
|
59
|
+
case 2:
|
|
60
|
+
return this.precpred(this._ctx, 5);
|
|
61
|
+
case 3:
|
|
62
|
+
return this.precpred(this._ctx, 4);
|
|
63
|
+
default:
|
|
64
|
+
throw "No predicate with index:" + predIndex;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
all() {
|
|
72
|
+
let localctx = new AllContext(this, this._ctx, this.state);
|
|
73
|
+
this.enterRule(localctx, 0, CustomMetricParser.RULE_all);
|
|
74
|
+
try {
|
|
75
|
+
this.enterOuterAlt(localctx, 1);
|
|
76
|
+
this.state = 4;
|
|
77
|
+
this.expression(0);
|
|
78
|
+
this.state = 5;
|
|
79
|
+
this.match(CustomMetricParser.EOF);
|
|
80
|
+
} catch (re) {
|
|
81
|
+
if(re instanceof antlr4.error.RecognitionException) {
|
|
82
|
+
localctx.exception = re;
|
|
83
|
+
this._errHandler.reportError(this, re);
|
|
84
|
+
this._errHandler.recover(this, re);
|
|
85
|
+
} else {
|
|
86
|
+
throw re;
|
|
87
|
+
}
|
|
88
|
+
} finally {
|
|
89
|
+
this.exitRule();
|
|
90
|
+
}
|
|
91
|
+
return localctx;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
expression(_p) {
|
|
96
|
+
if(_p===undefined) {
|
|
97
|
+
_p = 0;
|
|
98
|
+
}
|
|
99
|
+
const _parentctx = this._ctx;
|
|
100
|
+
const _parentState = this.state;
|
|
101
|
+
let localctx = new ExpressionContext(this, this._ctx, _parentState);
|
|
102
|
+
let _prevctx = localctx;
|
|
103
|
+
const _startState = 2;
|
|
104
|
+
this.enterRecursionRule(localctx, 2, CustomMetricParser.RULE_expression, _p);
|
|
105
|
+
try {
|
|
106
|
+
this.enterOuterAlt(localctx, 1);
|
|
107
|
+
this.state = 14;
|
|
108
|
+
this._errHandler.sync(this);
|
|
109
|
+
switch(this._input.LA(1)) {
|
|
110
|
+
case 10:
|
|
111
|
+
localctx = new WrappedExpressionContext(this, localctx);
|
|
112
|
+
this._ctx = localctx;
|
|
113
|
+
_prevctx = localctx;
|
|
114
|
+
|
|
115
|
+
this.state = 8;
|
|
116
|
+
this.match(CustomMetricParser.L_PARANT);
|
|
117
|
+
this.state = 9;
|
|
118
|
+
this.expression(0);
|
|
119
|
+
this.state = 10;
|
|
120
|
+
this.match(CustomMetricParser.R_PARANT);
|
|
121
|
+
break;
|
|
122
|
+
case 1:
|
|
123
|
+
localctx = new NumberContext(this, localctx);
|
|
124
|
+
this._ctx = localctx;
|
|
125
|
+
_prevctx = localctx;
|
|
126
|
+
this.state = 12;
|
|
127
|
+
this.match(CustomMetricParser.NUMBER);
|
|
128
|
+
break;
|
|
129
|
+
case 2:
|
|
130
|
+
localctx = new StringContext(this, localctx);
|
|
131
|
+
this._ctx = localctx;
|
|
132
|
+
_prevctx = localctx;
|
|
133
|
+
this.state = 13;
|
|
134
|
+
this.match(CustomMetricParser.STRING);
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
throw new antlr4.error.NoViableAltException(this);
|
|
138
|
+
}
|
|
139
|
+
this._ctx.stop = this._input.LT(-1);
|
|
140
|
+
this.state = 30;
|
|
141
|
+
this._errHandler.sync(this);
|
|
142
|
+
var _alt = this._interp.adaptivePredict(this._input,2,this._ctx)
|
|
143
|
+
while(_alt!=2 && _alt!=antlr4.atn.ATN.INVALID_ALT_NUMBER) {
|
|
144
|
+
if(_alt===1) {
|
|
145
|
+
if(this._parseListeners!==null) {
|
|
146
|
+
this.triggerExitRuleEvent();
|
|
147
|
+
}
|
|
148
|
+
_prevctx = localctx;
|
|
149
|
+
this.state = 28;
|
|
150
|
+
this._errHandler.sync(this);
|
|
151
|
+
var la_ = this._interp.adaptivePredict(this._input,1,this._ctx);
|
|
152
|
+
switch(la_) {
|
|
153
|
+
case 1:
|
|
154
|
+
localctx = new AdditionContext(this, new ExpressionContext(this, _parentctx, _parentState));
|
|
155
|
+
localctx.left = _prevctx;
|
|
156
|
+
this.pushNewRecursionContext(localctx, _startState, CustomMetricParser.RULE_expression);
|
|
157
|
+
this.state = 16;
|
|
158
|
+
if (!( this.precpred(this._ctx, 7))) {
|
|
159
|
+
throw new antlr4.error.FailedPredicateException(this, "this.precpred(this._ctx, 7)");
|
|
160
|
+
}
|
|
161
|
+
this.state = 17;
|
|
162
|
+
this.match(CustomMetricParser.ADD);
|
|
163
|
+
this.state = 18;
|
|
164
|
+
localctx.right = this.expression(8);
|
|
165
|
+
break;
|
|
166
|
+
|
|
167
|
+
case 2:
|
|
168
|
+
localctx = new SubtractionContext(this, new ExpressionContext(this, _parentctx, _parentState));
|
|
169
|
+
localctx.left = _prevctx;
|
|
170
|
+
this.pushNewRecursionContext(localctx, _startState, CustomMetricParser.RULE_expression);
|
|
171
|
+
this.state = 19;
|
|
172
|
+
if (!( this.precpred(this._ctx, 6))) {
|
|
173
|
+
throw new antlr4.error.FailedPredicateException(this, "this.precpred(this._ctx, 6)");
|
|
174
|
+
}
|
|
175
|
+
this.state = 20;
|
|
176
|
+
this.match(CustomMetricParser.SUBTRACT);
|
|
177
|
+
this.state = 21;
|
|
178
|
+
localctx.right = this.expression(7);
|
|
179
|
+
break;
|
|
180
|
+
|
|
181
|
+
case 3:
|
|
182
|
+
localctx = new MultiplicationContext(this, new ExpressionContext(this, _parentctx, _parentState));
|
|
183
|
+
localctx.left = _prevctx;
|
|
184
|
+
this.pushNewRecursionContext(localctx, _startState, CustomMetricParser.RULE_expression);
|
|
185
|
+
this.state = 22;
|
|
186
|
+
if (!( this.precpred(this._ctx, 5))) {
|
|
187
|
+
throw new antlr4.error.FailedPredicateException(this, "this.precpred(this._ctx, 5)");
|
|
188
|
+
}
|
|
189
|
+
this.state = 23;
|
|
190
|
+
this.match(CustomMetricParser.MULTIPLY);
|
|
191
|
+
this.state = 24;
|
|
192
|
+
localctx.right = this.expression(6);
|
|
193
|
+
break;
|
|
194
|
+
|
|
195
|
+
case 4:
|
|
196
|
+
localctx = new DivisionContext(this, new ExpressionContext(this, _parentctx, _parentState));
|
|
197
|
+
localctx.left = _prevctx;
|
|
198
|
+
this.pushNewRecursionContext(localctx, _startState, CustomMetricParser.RULE_expression);
|
|
199
|
+
this.state = 25;
|
|
200
|
+
if (!( this.precpred(this._ctx, 4))) {
|
|
201
|
+
throw new antlr4.error.FailedPredicateException(this, "this.precpred(this._ctx, 4)");
|
|
202
|
+
}
|
|
203
|
+
this.state = 26;
|
|
204
|
+
this.match(CustomMetricParser.DIVIDE);
|
|
205
|
+
this.state = 27;
|
|
206
|
+
localctx.right = this.expression(5);
|
|
207
|
+
break;
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
this.state = 32;
|
|
212
|
+
this._errHandler.sync(this);
|
|
213
|
+
_alt = this._interp.adaptivePredict(this._input,2,this._ctx);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
} catch( error) {
|
|
217
|
+
if(error instanceof antlr4.error.RecognitionException) {
|
|
218
|
+
localctx.exception = error;
|
|
219
|
+
this._errHandler.reportError(this, error);
|
|
220
|
+
this._errHandler.recover(this, error);
|
|
221
|
+
} else {
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
} finally {
|
|
225
|
+
this.unrollRecursionContexts(_parentctx)
|
|
226
|
+
}
|
|
227
|
+
return localctx;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
CustomMetricParser.EOF = antlr4.Token.EOF;
|
|
234
|
+
CustomMetricParser.NUMBER = 1;
|
|
235
|
+
CustomMetricParser.STRING = 2;
|
|
236
|
+
CustomMetricParser.WHITESPACE = 3;
|
|
237
|
+
CustomMetricParser.ADD = 4;
|
|
238
|
+
CustomMetricParser.SUBTRACT = 5;
|
|
239
|
+
CustomMetricParser.MULTIPLY = 6;
|
|
240
|
+
CustomMetricParser.DIVIDE = 7;
|
|
241
|
+
CustomMetricParser.DIGIT = 8;
|
|
242
|
+
CustomMetricParser.DOT = 9;
|
|
243
|
+
CustomMetricParser.L_PARANT = 10;
|
|
244
|
+
CustomMetricParser.R_PARANT = 11;
|
|
245
|
+
CustomMetricParser.PLUS = 12;
|
|
246
|
+
CustomMetricParser.MINUS = 13;
|
|
247
|
+
CustomMetricParser.STAR = 14;
|
|
248
|
+
CustomMetricParser.SLASH = 15;
|
|
249
|
+
CustomMetricParser.DQUOTE = 16;
|
|
250
|
+
CustomMetricParser.SPACE = 17;
|
|
251
|
+
CustomMetricParser.TAB = 18;
|
|
252
|
+
CustomMetricParser.CR = 19;
|
|
253
|
+
CustomMetricParser.LF = 20;
|
|
254
|
+
CustomMetricParser.ANY = 21;
|
|
255
|
+
|
|
256
|
+
CustomMetricParser.RULE_all = 0;
|
|
257
|
+
CustomMetricParser.RULE_expression = 1;
|
|
258
|
+
|
|
259
|
+
class AllContext extends antlr4.ParserRuleContext {
|
|
260
|
+
|
|
261
|
+
constructor(parser, parent, invokingState) {
|
|
262
|
+
if(parent===undefined) {
|
|
263
|
+
parent = null;
|
|
264
|
+
}
|
|
265
|
+
if(invokingState===undefined || invokingState===null) {
|
|
266
|
+
invokingState = -1;
|
|
267
|
+
}
|
|
268
|
+
super(parent, invokingState);
|
|
269
|
+
this.parser = parser;
|
|
270
|
+
this.ruleIndex = CustomMetricParser.RULE_all;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
expression() {
|
|
274
|
+
return this.getTypedRuleContext(ExpressionContext,0);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
EOF() {
|
|
278
|
+
return this.getToken(CustomMetricParser.EOF, 0);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
enterRule(listener) {
|
|
282
|
+
if(listener instanceof CustomMetricListener ) {
|
|
283
|
+
listener.enterAll(this);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
exitRule(listener) {
|
|
288
|
+
if(listener instanceof CustomMetricListener ) {
|
|
289
|
+
listener.exitAll(this);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
class ExpressionContext extends antlr4.ParserRuleContext {
|
|
299
|
+
|
|
300
|
+
constructor(parser, parent, invokingState) {
|
|
301
|
+
if(parent===undefined) {
|
|
302
|
+
parent = null;
|
|
303
|
+
}
|
|
304
|
+
if(invokingState===undefined || invokingState===null) {
|
|
305
|
+
invokingState = -1;
|
|
306
|
+
}
|
|
307
|
+
super(parent, invokingState);
|
|
308
|
+
this.parser = parser;
|
|
309
|
+
this.ruleIndex = CustomMetricParser.RULE_expression;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
copyFrom(ctx) {
|
|
315
|
+
super.copyFrom(ctx);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
class AdditionContext extends ExpressionContext {
|
|
322
|
+
|
|
323
|
+
constructor(parser, ctx) {
|
|
324
|
+
super(parser);
|
|
325
|
+
this.left = null;;
|
|
326
|
+
this.right = null;;
|
|
327
|
+
super.copyFrom(ctx);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
ADD() {
|
|
331
|
+
return this.getToken(CustomMetricParser.ADD, 0);
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
expression = function(i) {
|
|
335
|
+
if(i===undefined) {
|
|
336
|
+
i = null;
|
|
337
|
+
}
|
|
338
|
+
if(i===null) {
|
|
339
|
+
return this.getTypedRuleContexts(ExpressionContext);
|
|
340
|
+
} else {
|
|
341
|
+
return this.getTypedRuleContext(ExpressionContext,i);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
enterRule(listener) {
|
|
346
|
+
if(listener instanceof CustomMetricListener ) {
|
|
347
|
+
listener.enterAddition(this);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
exitRule(listener) {
|
|
352
|
+
if(listener instanceof CustomMetricListener ) {
|
|
353
|
+
listener.exitAddition(this);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
CustomMetricParser.AdditionContext = AdditionContext;
|
|
361
|
+
|
|
362
|
+
class MultiplicationContext extends ExpressionContext {
|
|
363
|
+
|
|
364
|
+
constructor(parser, ctx) {
|
|
365
|
+
super(parser);
|
|
366
|
+
this.left = null;;
|
|
367
|
+
this.right = null;;
|
|
368
|
+
super.copyFrom(ctx);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
MULTIPLY() {
|
|
372
|
+
return this.getToken(CustomMetricParser.MULTIPLY, 0);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
expression = function(i) {
|
|
376
|
+
if(i===undefined) {
|
|
377
|
+
i = null;
|
|
378
|
+
}
|
|
379
|
+
if(i===null) {
|
|
380
|
+
return this.getTypedRuleContexts(ExpressionContext);
|
|
381
|
+
} else {
|
|
382
|
+
return this.getTypedRuleContext(ExpressionContext,i);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
enterRule(listener) {
|
|
387
|
+
if(listener instanceof CustomMetricListener ) {
|
|
388
|
+
listener.enterMultiplication(this);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
exitRule(listener) {
|
|
393
|
+
if(listener instanceof CustomMetricListener ) {
|
|
394
|
+
listener.exitMultiplication(this);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
CustomMetricParser.MultiplicationContext = MultiplicationContext;
|
|
402
|
+
|
|
403
|
+
class SubtractionContext extends ExpressionContext {
|
|
404
|
+
|
|
405
|
+
constructor(parser, ctx) {
|
|
406
|
+
super(parser);
|
|
407
|
+
this.left = null;;
|
|
408
|
+
this.right = null;;
|
|
409
|
+
super.copyFrom(ctx);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
SUBTRACT() {
|
|
413
|
+
return this.getToken(CustomMetricParser.SUBTRACT, 0);
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
expression = function(i) {
|
|
417
|
+
if(i===undefined) {
|
|
418
|
+
i = null;
|
|
419
|
+
}
|
|
420
|
+
if(i===null) {
|
|
421
|
+
return this.getTypedRuleContexts(ExpressionContext);
|
|
422
|
+
} else {
|
|
423
|
+
return this.getTypedRuleContext(ExpressionContext,i);
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
enterRule(listener) {
|
|
428
|
+
if(listener instanceof CustomMetricListener ) {
|
|
429
|
+
listener.enterSubtraction(this);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
exitRule(listener) {
|
|
434
|
+
if(listener instanceof CustomMetricListener ) {
|
|
435
|
+
listener.exitSubtraction(this);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
CustomMetricParser.SubtractionContext = SubtractionContext;
|
|
443
|
+
|
|
444
|
+
class NumberContext extends ExpressionContext {
|
|
445
|
+
|
|
446
|
+
constructor(parser, ctx) {
|
|
447
|
+
super(parser);
|
|
448
|
+
super.copyFrom(ctx);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
NUMBER() {
|
|
452
|
+
return this.getToken(CustomMetricParser.NUMBER, 0);
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
enterRule(listener) {
|
|
456
|
+
if(listener instanceof CustomMetricListener ) {
|
|
457
|
+
listener.enterNumber(this);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
exitRule(listener) {
|
|
462
|
+
if(listener instanceof CustomMetricListener ) {
|
|
463
|
+
listener.exitNumber(this);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
CustomMetricParser.NumberContext = NumberContext;
|
|
471
|
+
|
|
472
|
+
class WrappedExpressionContext extends ExpressionContext {
|
|
473
|
+
|
|
474
|
+
constructor(parser, ctx) {
|
|
475
|
+
super(parser);
|
|
476
|
+
super.copyFrom(ctx);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
L_PARANT() {
|
|
480
|
+
return this.getToken(CustomMetricParser.L_PARANT, 0);
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
expression() {
|
|
484
|
+
return this.getTypedRuleContext(ExpressionContext,0);
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
R_PARANT() {
|
|
488
|
+
return this.getToken(CustomMetricParser.R_PARANT, 0);
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
enterRule(listener) {
|
|
492
|
+
if(listener instanceof CustomMetricListener ) {
|
|
493
|
+
listener.enterWrappedExpression(this);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
exitRule(listener) {
|
|
498
|
+
if(listener instanceof CustomMetricListener ) {
|
|
499
|
+
listener.exitWrappedExpression(this);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
CustomMetricParser.WrappedExpressionContext = WrappedExpressionContext;
|
|
507
|
+
|
|
508
|
+
class DivisionContext extends ExpressionContext {
|
|
509
|
+
|
|
510
|
+
constructor(parser, ctx) {
|
|
511
|
+
super(parser);
|
|
512
|
+
this.left = null;;
|
|
513
|
+
this.right = null;;
|
|
514
|
+
super.copyFrom(ctx);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
DIVIDE() {
|
|
518
|
+
return this.getToken(CustomMetricParser.DIVIDE, 0);
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
expression = function(i) {
|
|
522
|
+
if(i===undefined) {
|
|
523
|
+
i = null;
|
|
524
|
+
}
|
|
525
|
+
if(i===null) {
|
|
526
|
+
return this.getTypedRuleContexts(ExpressionContext);
|
|
527
|
+
} else {
|
|
528
|
+
return this.getTypedRuleContext(ExpressionContext,i);
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
enterRule(listener) {
|
|
533
|
+
if(listener instanceof CustomMetricListener ) {
|
|
534
|
+
listener.enterDivision(this);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
exitRule(listener) {
|
|
539
|
+
if(listener instanceof CustomMetricListener ) {
|
|
540
|
+
listener.exitDivision(this);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
CustomMetricParser.DivisionContext = DivisionContext;
|
|
548
|
+
|
|
549
|
+
class StringContext extends ExpressionContext {
|
|
550
|
+
|
|
551
|
+
constructor(parser, ctx) {
|
|
552
|
+
super(parser);
|
|
553
|
+
super.copyFrom(ctx);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
STRING() {
|
|
557
|
+
return this.getToken(CustomMetricParser.STRING, 0);
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
enterRule(listener) {
|
|
561
|
+
if(listener instanceof CustomMetricListener ) {
|
|
562
|
+
listener.enterString(this);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
exitRule(listener) {
|
|
567
|
+
if(listener instanceof CustomMetricListener ) {
|
|
568
|
+
listener.exitString(this);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
CustomMetricParser.StringContext = StringContext;
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
CustomMetricParser.AllContext = AllContext;
|
|
579
|
+
CustomMetricParser.ExpressionContext = ExpressionContext;
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stordata/grammars",
|
|
3
|
+
"version":"1.0.20230421155415",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/main.cjs",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "ssh://git@gitlab.stordata.fr:2200/stordata/grammars.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"antlr",
|
|
12
|
+
"stordata",
|
|
13
|
+
"grammars"
|
|
14
|
+
],
|
|
15
|
+
"author": "La team d'en bas <teamdenbas@stordata.fr>",
|
|
16
|
+
"license": "UNLICENCED",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "webpack",
|
|
23
|
+
"test": "mocha src/**/*.spec.js",
|
|
24
|
+
"lint": "eslint webpack.config.js src/**/*.js",
|
|
25
|
+
"antlr": "antlr4 -Dlanguage=JavaScript -o generated src/grammars/CustomMetric.g4",
|
|
26
|
+
"clean": "rm dist/ -fR; rm generated/ -fR"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">= 18"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"antlr4": "4.12.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@stordata/eslint-config": "1.0.20230408020835",
|
|
36
|
+
"chai": "4.3.7",
|
|
37
|
+
"eslint": "8.38.0",
|
|
38
|
+
"mocha": "10.2.0",
|
|
39
|
+
"webpack": "5.80.0",
|
|
40
|
+
"webpack-cli": "5.0.1"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ErrorListener } from 'antlr4';
|
|
2
|
+
|
|
3
|
+
import GrammarSyntaxError from './GrammarSyntaxError.js';
|
|
4
|
+
|
|
5
|
+
export default class ThrowingErrorListener extends ErrorListener {
|
|
6
|
+
|
|
7
|
+
syntaxError(recognizer, offendingSymbol, line, column, msg, e) {
|
|
8
|
+
throw new GrammarSyntaxError(msg, line, column, e);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
grammar CustomMetric;
|
|
2
|
+
|
|
3
|
+
all: expression EOF; // Will parse all input as an expression. Mind the EOF token
|
|
4
|
+
|
|
5
|
+
expression: left=expression ADD right=expression # Addition
|
|
6
|
+
| left=expression SUBTRACT right=expression # Subtraction
|
|
7
|
+
| left=expression MULTIPLY right=expression # Multiplication
|
|
8
|
+
| left=expression DIVIDE right=expression # Division
|
|
9
|
+
| L_PARANT expression R_PARANT # WrappedExpression
|
|
10
|
+
| NUMBER # Number
|
|
11
|
+
| STRING # String
|
|
12
|
+
;
|
|
13
|
+
|
|
14
|
+
NUMBER: DIGIT+(DOT DIGIT+)?;
|
|
15
|
+
STRING: DQUOTE ANY+? DQUOTE;
|
|
16
|
+
WHITESPACE: (SPACE | TAB | CR | LF)+ -> skip;
|
|
17
|
+
|
|
18
|
+
ADD: PLUS;
|
|
19
|
+
SUBTRACT: MINUS;
|
|
20
|
+
MULTIPLY: STAR;
|
|
21
|
+
DIVIDE: SLASH;
|
|
22
|
+
|
|
23
|
+
DIGIT: [0-9];
|
|
24
|
+
DOT: '.';
|
|
25
|
+
L_PARANT: '(';
|
|
26
|
+
R_PARANT: ')';
|
|
27
|
+
PLUS: '+';
|
|
28
|
+
MINUS: '-';
|
|
29
|
+
STAR: '*';
|
|
30
|
+
SLASH: '/';
|
|
31
|
+
DQUOTE: '"';
|
|
32
|
+
|
|
33
|
+
SPACE: ' ';
|
|
34
|
+
TAB: [\t];
|
|
35
|
+
CR: [\r];
|
|
36
|
+
LF: [\n];
|
|
37
|
+
|
|
38
|
+
ANY: .;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import parse from '../parse.js';
|
|
2
|
+
import CustomMetricLexer from '../../generated/src/grammars/CustomMetricLexer.js';
|
|
3
|
+
import CustomMetricParser from '../../generated/src/grammars/CustomMetricParser.js';
|
|
4
|
+
|
|
5
|
+
export default function parseCustomMetric(input) {
|
|
6
|
+
return parse(input, CustomMetricLexer, CustomMetricParser);
|
|
7
|
+
}
|