@fraczak/k 1.0.0

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/parser.js ADDED
@@ -0,0 +1,703 @@
1
+ /* parser generated by jison 0.4.18 */
2
+ /*
3
+ Returns a Parser object of the following structure:
4
+
5
+ Parser: {
6
+ yy: {}
7
+ }
8
+
9
+ Parser.prototype: {
10
+ yy: {},
11
+ trace: function(),
12
+ symbols_: {associative list: name ==> number},
13
+ terminals_: {associative list: number ==> name},
14
+ productions_: [...],
15
+ performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
16
+ table: [...],
17
+ defaultActions: {...},
18
+ parseError: function(str, hash),
19
+ parse: function(input),
20
+
21
+ lexer: {
22
+ EOF: 1,
23
+ parseError: function(str, hash),
24
+ setInput: function(input),
25
+ input: function(),
26
+ unput: function(str),
27
+ more: function(),
28
+ less: function(n),
29
+ pastInput: function(),
30
+ upcomingInput: function(),
31
+ showPosition: function(),
32
+ test_match: function(regex_match_array, rule_index),
33
+ next: function(),
34
+ lex: function(),
35
+ begin: function(condition),
36
+ popState: function(),
37
+ _currentRules: function(),
38
+ topState: function(),
39
+ pushState: function(condition),
40
+
41
+ options: {
42
+ ranges: boolean (optional: true ==> token location info will include a .range[] member)
43
+ flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
44
+ backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
45
+ },
46
+
47
+ performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
48
+ rules: [...],
49
+ conditions: {associative list: name ==> set},
50
+ }
51
+ }
52
+
53
+
54
+ token location info (@$, _$, etc.): {
55
+ first_line: n,
56
+ last_line: n,
57
+ first_column: n,
58
+ last_column: n,
59
+ range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
60
+ }
61
+
62
+
63
+ the parseError function receives a 'hash' object with these members for lexer and parser errors: {
64
+ text: (matched text)
65
+ token: (the produced terminal token, if any)
66
+ line: (yylineno)
67
+ }
68
+ while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
69
+ loc: (yylloc)
70
+ expected: (string describing the set of expected tokens)
71
+ recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
72
+ }
73
+ */
74
+ var parser = (function(){
75
+ var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,12],$V1=[1,13],$V2=[1,14],$V3=[1,4],$V4=[1,5],$V5=[1,6],$V6=[1,8],$V7=[1,11],$V8=[4,6,8,11,13,16,18,19,20,21,22,23,26],$V9=[2,24],$Va=[2,10],$Vb=[2,13],$Vc=[4,6,8,11,13,15,16,18,19,20,21,22,23,26],$Vd=[15,26],$Ve=[18,20,26],$Vf=[4,6,8,13,16,19,21,23],$Vg=[2,22],$Vh=[2,23];
76
+ var parser = {trace: function trace () { },
77
+ yy: {},
78
+ symbols_: {"error":2,"name":3,"NAME":4,"str":5,"STRING":6,"int":7,"INT":8,"input_with_eof":9,"comp":10,"EOF":11,"exp":12,"LC":13,"labelled":14,"RC":15,"LB":16,"list":17,"RB":18,"LA":19,"RA":20,"LP":21,"RP":22,"DOT":23,"non_empty_labelled":24,"comp_label":25,"COMMA":26,"non_empty_list":27,"$accept":0,"$end":1},
79
+ terminals_: {2:"error",4:"NAME",6:"STRING",8:"INT",11:"EOF",13:"LC",15:"RC",16:"LB",18:"RB",19:"LA",20:"RA",21:"LP",22:"RP",23:"DOT",26:"COMMA"},
80
+ productions_: [0,[3,1],[5,1],[7,1],[9,2],[10,1],[10,2],[12,3],[12,3],[12,3],[12,1],[12,2],[12,3],[12,1],[12,1],[12,2],[12,2],[12,2],[14,0],[14,1],[24,1],[24,3],[25,2],[25,2],[17,0],[17,1],[27,1],[27,3]],
81
+ performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
82
+ /* this == yyval */
83
+
84
+ var $0 = $$.length - 1;
85
+ switch (yystate) {
86
+ case 1:
87
+ this.$ = String(yytext);
88
+ break;
89
+ case 2:
90
+ this.$ = String(yytext).slice(1,-1);
91
+ break;
92
+ case 3:
93
+ this.$ = parseInt(String(yytext));
94
+ break;
95
+ case 4:
96
+
97
+ // console.log(JSON.stringify($$[$0-1], "", 2));
98
+ return $$[$0-1];
99
+
100
+ break;
101
+ case 5: case 19: case 25:
102
+ this.$ = $$[$0];
103
+ break;
104
+ case 6:
105
+ this.$ = s.comp($$[$0-1], $$[$0]);
106
+ break;
107
+ case 7:
108
+ this.$ = $$[$0-1];
109
+ break;
110
+ case 8:
111
+ this.$ = {op: "vector", vector: $$[$0-1]};
112
+ break;
113
+ case 9:
114
+ this.$ = {op: "union", union: $$[$0-1]};
115
+ break;
116
+ case 10:
117
+ this.$ = {op: "ref", ref: $$[$0]};
118
+ break;
119
+ case 11:
120
+ this.$ = s.identity;
121
+ break;
122
+ case 12:
123
+ this.$ = $$[$0-1];
124
+ break;
125
+ case 13:
126
+ this.$ = {op: "str", str: $$[$0]};
127
+ break;
128
+ case 14:
129
+ this.$ = {op: "int", int: $$[$0]};
130
+ break;
131
+ case 15: case 16: case 17:
132
+ this.$ = {op: "dot", dot: $$[$0]};
133
+ break;
134
+ case 18:
135
+ this.$ = {op: "product", product: []};
136
+ break;
137
+ case 20:
138
+ this.$ = {op: "product", product: [$$[$0]]};
139
+ break;
140
+ case 21:
141
+ $$[$0-2].product = [].concat($$[$0-2].product,$$[$0]); this.$ = $$[$0-2];
142
+ break;
143
+ case 22: case 23:
144
+ this.$ = {label: $$[$0], exp: $$[$0-1]};
145
+ break;
146
+ case 24:
147
+ this.$ = [];
148
+ break;
149
+ case 26:
150
+ this.$ = [$$[$0]];
151
+ break;
152
+ case 27:
153
+ this.$ = [].concat($$[$0-2],$$[$0]);
154
+ break;
155
+ }
156
+ },
157
+ table: [{3:7,4:$V0,5:9,6:$V1,7:10,8:$V2,9:1,10:2,12:3,13:$V3,16:$V4,19:$V5,21:$V6,23:$V7},{1:[3]},{3:7,4:$V0,5:9,6:$V1,7:10,8:$V2,11:[1,15],12:16,13:$V3,16:$V4,19:$V5,21:$V6,23:$V7},o($V8,[2,5]),{3:7,4:$V0,5:9,6:$V1,7:10,8:$V2,10:20,12:3,13:$V3,14:17,15:[2,18],16:$V4,19:$V5,21:$V6,23:$V7,24:18,25:19},{3:7,4:$V0,5:9,6:$V1,7:10,8:$V2,10:23,12:3,13:$V3,16:$V4,17:21,18:$V9,19:$V5,21:$V6,23:$V7,27:22},{3:7,4:$V0,5:9,6:$V1,7:10,8:$V2,10:23,12:3,13:$V3,16:$V4,17:24,19:$V5,20:$V9,21:$V6,23:$V7,27:22},o($V8,$Va),{3:7,4:$V0,5:9,6:$V1,7:10,8:$V2,10:26,12:3,13:$V3,16:$V4,19:$V5,21:$V6,22:[1,25],23:$V7},o($V8,$Vb),o($V8,[2,14]),{3:29,4:$V0,5:28,6:$V1,7:27,8:$V2},o($Vc,[2,1]),o($Vc,[2,2]),o($V8,[2,3]),{1:[2,4]},o($V8,[2,6]),{15:[1,30]},{15:[2,19],26:[1,31]},o($Vd,[2,20]),{3:32,4:$V0,5:33,6:$V1,7:10,8:$V2,12:16,13:$V3,16:$V4,19:$V5,21:$V6,23:$V7},{18:[1,34]},o([18,20],[2,25],{26:[1,35]}),o($Ve,[2,26],{3:7,5:9,7:10,12:16,4:$V0,6:$V1,8:$V2,13:$V3,16:$V4,19:$V5,21:$V6,23:$V7}),{20:[1,36]},o($V8,[2,11]),{3:7,4:$V0,5:9,6:$V1,7:10,8:$V2,12:16,13:$V3,16:$V4,19:$V5,21:$V6,22:[1,37],23:$V7},o($V8,[2,15]),o($V8,[2,16]),o($V8,[2,17]),o($V8,[2,7]),{3:7,4:$V0,5:9,6:$V1,7:10,8:$V2,10:20,12:3,13:$V3,16:$V4,19:$V5,21:$V6,23:$V7,25:38},o($Vf,$Va,{15:$Vg,26:$Vg}),o($Vf,$Vb,{15:$Vh,26:$Vh}),o($V8,[2,8]),{3:7,4:$V0,5:9,6:$V1,7:10,8:$V2,10:39,12:3,13:$V3,16:$V4,19:$V5,21:$V6,23:$V7},o($V8,[2,9]),o($V8,[2,12]),o($Vd,[2,21]),o($Ve,[2,27],{3:7,5:9,7:10,12:16,4:$V0,6:$V1,8:$V2,13:$V3,16:$V4,19:$V5,21:$V6,23:$V7})],
158
+ defaultActions: {15:[2,4]},
159
+ parseError: function parseError (str, hash) {
160
+ if (hash.recoverable) {
161
+ this.trace(str);
162
+ } else {
163
+ var error = new Error(str);
164
+ error.hash = hash;
165
+ throw error;
166
+ }
167
+ },
168
+ parse: function parse(input) {
169
+ var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
170
+ var args = lstack.slice.call(arguments, 1);
171
+ var lexer = Object.create(this.lexer);
172
+ var sharedState = { yy: {} };
173
+ for (var k in this.yy) {
174
+ if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
175
+ sharedState.yy[k] = this.yy[k];
176
+ }
177
+ }
178
+ lexer.setInput(input, sharedState.yy);
179
+ sharedState.yy.lexer = lexer;
180
+ sharedState.yy.parser = this;
181
+ if (typeof lexer.yylloc == 'undefined') {
182
+ lexer.yylloc = {};
183
+ }
184
+ var yyloc = lexer.yylloc;
185
+ lstack.push(yyloc);
186
+ var ranges = lexer.options && lexer.options.ranges;
187
+ if (typeof sharedState.yy.parseError === 'function') {
188
+ this.parseError = sharedState.yy.parseError;
189
+ } else {
190
+ this.parseError = Object.getPrototypeOf(this).parseError;
191
+ }
192
+ function popStack(n) {
193
+ stack.length = stack.length - 2 * n;
194
+ vstack.length = vstack.length - n;
195
+ lstack.length = lstack.length - n;
196
+ }
197
+ _token_stack:
198
+ var lex = function () {
199
+ var token;
200
+ token = lexer.lex() || EOF;
201
+ if (typeof token !== 'number') {
202
+ token = self.symbols_[token] || token;
203
+ }
204
+ return token;
205
+ };
206
+ var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
207
+ while (true) {
208
+ state = stack[stack.length - 1];
209
+ if (this.defaultActions[state]) {
210
+ action = this.defaultActions[state];
211
+ } else {
212
+ if (symbol === null || typeof symbol == 'undefined') {
213
+ symbol = lex();
214
+ }
215
+ action = table[state] && table[state][symbol];
216
+ }
217
+ if (typeof action === 'undefined' || !action.length || !action[0]) {
218
+ var errStr = '';
219
+ expected = [];
220
+ for (p in table[state]) {
221
+ if (this.terminals_[p] && p > TERROR) {
222
+ expected.push('\'' + this.terminals_[p] + '\'');
223
+ }
224
+ }
225
+ if (lexer.showPosition) {
226
+ errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
227
+ } else {
228
+ errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
229
+ }
230
+ this.parseError(errStr, {
231
+ text: lexer.match,
232
+ token: this.terminals_[symbol] || symbol,
233
+ line: lexer.yylineno,
234
+ loc: yyloc,
235
+ expected: expected
236
+ });
237
+ }
238
+ if (action[0] instanceof Array && action.length > 1) {
239
+ throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
240
+ }
241
+ switch (action[0]) {
242
+ case 1:
243
+ stack.push(symbol);
244
+ vstack.push(lexer.yytext);
245
+ lstack.push(lexer.yylloc);
246
+ stack.push(action[1]);
247
+ symbol = null;
248
+ if (!preErrorSymbol) {
249
+ yyleng = lexer.yyleng;
250
+ yytext = lexer.yytext;
251
+ yylineno = lexer.yylineno;
252
+ yyloc = lexer.yylloc;
253
+ if (recovering > 0) {
254
+ recovering--;
255
+ }
256
+ } else {
257
+ symbol = preErrorSymbol;
258
+ preErrorSymbol = null;
259
+ }
260
+ break;
261
+ case 2:
262
+ len = this.productions_[action[1]][1];
263
+ yyval.$ = vstack[vstack.length - len];
264
+ yyval._$ = {
265
+ first_line: lstack[lstack.length - (len || 1)].first_line,
266
+ last_line: lstack[lstack.length - 1].last_line,
267
+ first_column: lstack[lstack.length - (len || 1)].first_column,
268
+ last_column: lstack[lstack.length - 1].last_column
269
+ };
270
+ if (ranges) {
271
+ yyval._$.range = [
272
+ lstack[lstack.length - (len || 1)].range[0],
273
+ lstack[lstack.length - 1].range[1]
274
+ ];
275
+ }
276
+ r = this.performAction.apply(yyval, [
277
+ yytext,
278
+ yyleng,
279
+ yylineno,
280
+ sharedState.yy,
281
+ action[1],
282
+ vstack,
283
+ lstack
284
+ ].concat(args));
285
+ if (typeof r !== 'undefined') {
286
+ return r;
287
+ }
288
+ if (len) {
289
+ stack = stack.slice(0, -1 * len * 2);
290
+ vstack = vstack.slice(0, -1 * len);
291
+ lstack = lstack.slice(0, -1 * len);
292
+ }
293
+ stack.push(this.productions_[action[1]][0]);
294
+ vstack.push(yyval.$);
295
+ lstack.push(yyval._$);
296
+ newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
297
+ stack.push(newState);
298
+ break;
299
+ case 3:
300
+ return true;
301
+ }
302
+ }
303
+ return true;
304
+ }};
305
+
306
+
307
+ var s = require("./symbol-table");
308
+
309
+
310
+ /* generated by jison-lex 0.3.4 */
311
+ var lexer = (function(){
312
+ var lexer = ({
313
+
314
+ EOF:1,
315
+
316
+ parseError:function parseError(str, hash) {
317
+ if (this.yy.parser) {
318
+ this.yy.parser.parseError(str, hash);
319
+ } else {
320
+ throw new Error(str);
321
+ }
322
+ },
323
+
324
+ // resets the lexer, sets new input
325
+ setInput:function (input, yy) {
326
+ this.yy = yy || this.yy || {};
327
+ this._input = input;
328
+ this._more = this._backtrack = this.done = false;
329
+ this.yylineno = this.yyleng = 0;
330
+ this.yytext = this.matched = this.match = '';
331
+ this.conditionStack = ['INITIAL'];
332
+ this.yylloc = {
333
+ first_line: 1,
334
+ first_column: 0,
335
+ last_line: 1,
336
+ last_column: 0
337
+ };
338
+ if (this.options.ranges) {
339
+ this.yylloc.range = [0,0];
340
+ }
341
+ this.offset = 0;
342
+ return this;
343
+ },
344
+
345
+ // consumes and returns one char from the input
346
+ input:function () {
347
+ var ch = this._input[0];
348
+ this.yytext += ch;
349
+ this.yyleng++;
350
+ this.offset++;
351
+ this.match += ch;
352
+ this.matched += ch;
353
+ var lines = ch.match(/(?:\r\n?|\n).*/g);
354
+ if (lines) {
355
+ this.yylineno++;
356
+ this.yylloc.last_line++;
357
+ } else {
358
+ this.yylloc.last_column++;
359
+ }
360
+ if (this.options.ranges) {
361
+ this.yylloc.range[1]++;
362
+ }
363
+
364
+ this._input = this._input.slice(1);
365
+ return ch;
366
+ },
367
+
368
+ // unshifts one char (or a string) into the input
369
+ unput:function (ch) {
370
+ var len = ch.length;
371
+ var lines = ch.split(/(?:\r\n?|\n)/g);
372
+
373
+ this._input = ch + this._input;
374
+ this.yytext = this.yytext.substr(0, this.yytext.length - len);
375
+ //this.yyleng -= len;
376
+ this.offset -= len;
377
+ var oldLines = this.match.split(/(?:\r\n?|\n)/g);
378
+ this.match = this.match.substr(0, this.match.length - 1);
379
+ this.matched = this.matched.substr(0, this.matched.length - 1);
380
+
381
+ if (lines.length - 1) {
382
+ this.yylineno -= lines.length - 1;
383
+ }
384
+ var r = this.yylloc.range;
385
+
386
+ this.yylloc = {
387
+ first_line: this.yylloc.first_line,
388
+ last_line: this.yylineno + 1,
389
+ first_column: this.yylloc.first_column,
390
+ last_column: lines ?
391
+ (lines.length === oldLines.length ? this.yylloc.first_column : 0)
392
+ + oldLines[oldLines.length - lines.length].length - lines[0].length :
393
+ this.yylloc.first_column - len
394
+ };
395
+
396
+ if (this.options.ranges) {
397
+ this.yylloc.range = [r[0], r[0] + this.yyleng - len];
398
+ }
399
+ this.yyleng = this.yytext.length;
400
+ return this;
401
+ },
402
+
403
+ // When called from action, caches matched text and appends it on next action
404
+ more:function () {
405
+ this._more = true;
406
+ return this;
407
+ },
408
+
409
+ // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
410
+ reject:function () {
411
+ if (this.options.backtrack_lexer) {
412
+ this._backtrack = true;
413
+ } else {
414
+ return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
415
+ text: "",
416
+ token: null,
417
+ line: this.yylineno
418
+ });
419
+
420
+ }
421
+ return this;
422
+ },
423
+
424
+ // retain first n characters of the match
425
+ less:function (n) {
426
+ this.unput(this.match.slice(n));
427
+ },
428
+
429
+ // displays already matched input, i.e. for error messages
430
+ pastInput:function () {
431
+ var past = this.matched.substr(0, this.matched.length - this.match.length);
432
+ return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
433
+ },
434
+
435
+ // displays upcoming input, i.e. for error messages
436
+ upcomingInput:function () {
437
+ var next = this.match;
438
+ if (next.length < 20) {
439
+ next += this._input.substr(0, 20-next.length);
440
+ }
441
+ return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
442
+ },
443
+
444
+ // displays the character position where the lexing error occurred, i.e. for error messages
445
+ showPosition:function () {
446
+ var pre = this.pastInput();
447
+ var c = new Array(pre.length + 1).join("-");
448
+ return pre + this.upcomingInput() + "\n" + c + "^";
449
+ },
450
+
451
+ // test the lexed token: return FALSE when not a match, otherwise return token
452
+ test_match:function(match, indexed_rule) {
453
+ var token,
454
+ lines,
455
+ backup;
456
+
457
+ if (this.options.backtrack_lexer) {
458
+ // save context
459
+ backup = {
460
+ yylineno: this.yylineno,
461
+ yylloc: {
462
+ first_line: this.yylloc.first_line,
463
+ last_line: this.last_line,
464
+ first_column: this.yylloc.first_column,
465
+ last_column: this.yylloc.last_column
466
+ },
467
+ yytext: this.yytext,
468
+ match: this.match,
469
+ matches: this.matches,
470
+ matched: this.matched,
471
+ yyleng: this.yyleng,
472
+ offset: this.offset,
473
+ _more: this._more,
474
+ _input: this._input,
475
+ yy: this.yy,
476
+ conditionStack: this.conditionStack.slice(0),
477
+ done: this.done
478
+ };
479
+ if (this.options.ranges) {
480
+ backup.yylloc.range = this.yylloc.range.slice(0);
481
+ }
482
+ }
483
+
484
+ lines = match[0].match(/(?:\r\n?|\n).*/g);
485
+ if (lines) {
486
+ this.yylineno += lines.length;
487
+ }
488
+ this.yylloc = {
489
+ first_line: this.yylloc.last_line,
490
+ last_line: this.yylineno + 1,
491
+ first_column: this.yylloc.last_column,
492
+ last_column: lines ?
493
+ lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length :
494
+ this.yylloc.last_column + match[0].length
495
+ };
496
+ this.yytext += match[0];
497
+ this.match += match[0];
498
+ this.matches = match;
499
+ this.yyleng = this.yytext.length;
500
+ if (this.options.ranges) {
501
+ this.yylloc.range = [this.offset, this.offset += this.yyleng];
502
+ }
503
+ this._more = false;
504
+ this._backtrack = false;
505
+ this._input = this._input.slice(match[0].length);
506
+ this.matched += match[0];
507
+ token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
508
+ if (this.done && this._input) {
509
+ this.done = false;
510
+ }
511
+ if (token) {
512
+ return token;
513
+ } else if (this._backtrack) {
514
+ // recover context
515
+ for (var k in backup) {
516
+ this[k] = backup[k];
517
+ }
518
+ return false; // rule action called reject() implying the next rule should be tested instead.
519
+ }
520
+ return false;
521
+ },
522
+
523
+ // return next match in input
524
+ next:function () {
525
+ if (this.done) {
526
+ return this.EOF;
527
+ }
528
+ if (!this._input) {
529
+ this.done = true;
530
+ }
531
+
532
+ var token,
533
+ match,
534
+ tempMatch,
535
+ index;
536
+ if (!this._more) {
537
+ this.yytext = '';
538
+ this.match = '';
539
+ }
540
+ var rules = this._currentRules();
541
+ for (var i = 0; i < rules.length; i++) {
542
+ tempMatch = this._input.match(this.rules[rules[i]]);
543
+ if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
544
+ match = tempMatch;
545
+ index = i;
546
+ if (this.options.backtrack_lexer) {
547
+ token = this.test_match(tempMatch, rules[i]);
548
+ if (token !== false) {
549
+ return token;
550
+ } else if (this._backtrack) {
551
+ match = false;
552
+ continue; // rule action called reject() implying a rule MISmatch.
553
+ } else {
554
+ // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
555
+ return false;
556
+ }
557
+ } else if (!this.options.flex) {
558
+ break;
559
+ }
560
+ }
561
+ }
562
+ if (match) {
563
+ token = this.test_match(match, rules[index]);
564
+ if (token !== false) {
565
+ return token;
566
+ }
567
+ // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
568
+ return false;
569
+ }
570
+ if (this._input === "") {
571
+ return this.EOF;
572
+ } else {
573
+ return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
574
+ text: "",
575
+ token: null,
576
+ line: this.yylineno
577
+ });
578
+ }
579
+ },
580
+
581
+ // return next match that has a token
582
+ lex:function lex () {
583
+ var r = this.next();
584
+ if (r) {
585
+ return r;
586
+ } else {
587
+ return this.lex();
588
+ }
589
+ },
590
+
591
+ // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
592
+ begin:function begin (condition) {
593
+ this.conditionStack.push(condition);
594
+ },
595
+
596
+ // pop the previously active lexer condition state off the condition stack
597
+ popState:function popState () {
598
+ var n = this.conditionStack.length - 1;
599
+ if (n > 0) {
600
+ return this.conditionStack.pop();
601
+ } else {
602
+ return this.conditionStack[0];
603
+ }
604
+ },
605
+
606
+ // produce the lexer rule set which is active for the currently active lexer condition state
607
+ _currentRules:function _currentRules () {
608
+ if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
609
+ return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
610
+ } else {
611
+ return this.conditions["INITIAL"].rules;
612
+ }
613
+ },
614
+
615
+ // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
616
+ topState:function topState (n) {
617
+ n = this.conditionStack.length - 1 - Math.abs(n || 0);
618
+ if (n >= 0) {
619
+ return this.conditionStack[n];
620
+ } else {
621
+ return "INITIAL";
622
+ }
623
+ },
624
+
625
+ // alias for begin(condition)
626
+ pushState:function pushState (condition) {
627
+ this.begin(condition);
628
+ },
629
+
630
+ // return the number of states currently on the stack
631
+ stateStackSize:function stateStackSize() {
632
+ return this.conditionStack.length;
633
+ },
634
+ options: {},
635
+ performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
636
+ var YYSTATE=YY_START;
637
+ switch($avoiding_name_collisions) {
638
+ case 0:/* c-comment */
639
+ break;
640
+ case 1:/* one line comment */
641
+ break;
642
+ case 2:/* blanks */
643
+ break;
644
+ case 3:return 19;
645
+ break;
646
+ case 4:return 13;
647
+ break;
648
+ case 5:return 16;
649
+ break;
650
+ case 6:return 21;
651
+ break;
652
+ case 7:return 20;
653
+ break;
654
+ case 8:return 15;
655
+ break;
656
+ case 9:return 18;
657
+ break;
658
+ case 10:return 22;
659
+ break;
660
+ case 11:return 23;
661
+ break;
662
+ case 12:return 26;
663
+ break;
664
+ case 13:return 6
665
+ break;
666
+ case 14:return 4;
667
+ break;
668
+ case 15:return 8;
669
+ break;
670
+ case 16:return 11;
671
+ break;
672
+ }
673
+ },
674
+ rules: [/^(?:[/][*]([*][^/]|[^*])*[*][/])/,/^(?:(\/\/|#|%|--)[^\n]*)/,/^(?:\s+)/,/^(?:<)/,/^(?:\{)/,/^(?:\[)/,/^(?:\()/,/^(?:>)/,/^(?:\})/,/^(?:\])/,/^(?:\))/,/^(?:\.)/,/^(?:,)/,/^(?:"[^\"\n]*"|'[^\'\n]*')/,/^(?:[a-zA-Z_][a-zA-Z0-9_]*)/,/^(?:0|[-]?[1-9][0-9]*)/,/^(?:$)/],
675
+ conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],"inclusive":true}}
676
+ });
677
+ return lexer;
678
+ })();
679
+ parser.lexer = lexer;
680
+ function Parser () {
681
+ this.yy = {};
682
+ }
683
+ Parser.prototype = parser;parser.Parser = Parser;
684
+ return new Parser;
685
+ })();
686
+
687
+
688
+ if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
689
+ exports.parser = parser;
690
+ exports.Parser = parser.Parser;
691
+ exports.parse = function () { return parser.parse.apply(parser, arguments); };
692
+ exports.main = function commonjsMain (args) {
693
+ if (!args[1]) {
694
+ console.log('Usage: '+args[0]+' FILE');
695
+ process.exit(1);
696
+ }
697
+ var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
698
+ return exports.parser.parse(source);
699
+ };
700
+ if (typeof module !== 'undefined' && require.main === module) {
701
+ exports.main(process.argv.slice(1));
702
+ }
703
+ }