1 |
|
---|
2 | /* parser generated by jison 0.6.1-215 */
|
---|
3 |
|
---|
4 | /*
|
---|
5 | * Returns a Parser object of the following structure:
|
---|
6 | *
|
---|
7 | * Parser: {
|
---|
8 | * yy: {} The so-called "shared state" or rather the *source* of it;
|
---|
9 | * the real "shared state" `yy` passed around to
|
---|
10 | * the rule actions, etc. is a derivative/copy of this one,
|
---|
11 | * not a direct reference!
|
---|
12 | * }
|
---|
13 | *
|
---|
14 | * Parser.prototype: {
|
---|
15 | * yy: {},
|
---|
16 | * EOF: 1,
|
---|
17 | * TERROR: 2,
|
---|
18 | *
|
---|
19 | * trace: function(errorMessage, ...),
|
---|
20 | *
|
---|
21 | * JisonParserError: function(msg, hash),
|
---|
22 | *
|
---|
23 | * quoteName: function(name),
|
---|
24 | * Helper function which can be overridden by user code later on: put suitable
|
---|
25 | * quotes around literal IDs in a description string.
|
---|
26 | *
|
---|
27 | * originalQuoteName: function(name),
|
---|
28 | * The basic quoteName handler provided by JISON.
|
---|
29 | * `cleanupAfterParse()` will clean up and reset `quoteName()` to reference this function
|
---|
30 | * at the end of the `parse()`.
|
---|
31 | *
|
---|
32 | * describeSymbol: function(symbol),
|
---|
33 | * Return a more-or-less human-readable description of the given symbol, when
|
---|
34 | * available, or the symbol itself, serving as its own 'description' for lack
|
---|
35 | * of something better to serve up.
|
---|
36 | *
|
---|
37 | * Return NULL when the symbol is unknown to the parser.
|
---|
38 | *
|
---|
39 | * symbols_: {associative list: name ==> number},
|
---|
40 | * terminals_: {associative list: number ==> name},
|
---|
41 | * nonterminals: {associative list: rule-name ==> {associative list: number ==> rule-alt}},
|
---|
42 | * terminal_descriptions_: (if there are any) {associative list: number ==> description},
|
---|
43 | * productions_: [...],
|
---|
44 | *
|
---|
45 | * performAction: function parser__performAction(yytext, yyleng, yylineno, yyloc, yystate, yysp, yyvstack, yylstack, yystack, yysstack),
|
---|
46 | *
|
---|
47 | * The function parameters and `this` have the following value/meaning:
|
---|
48 | * - `this` : reference to the `yyval` internal object, which has members (`$` and `_$`)
|
---|
49 | * to store/reference the rule value `$$` and location info `@$`.
|
---|
50 | *
|
---|
51 | * One important thing to note about `this` a.k.a. `yyval`: every *reduce* action gets
|
---|
52 | * to see the same object via the `this` reference, i.e. if you wish to carry custom
|
---|
53 | * data from one reduce action through to the next within a single parse run, then you
|
---|
54 | * may get nasty and use `yyval` a.k.a. `this` for storing you own semi-permanent data.
|
---|
55 | *
|
---|
56 | * `this.yy` is a direct reference to the `yy` shared state object.
|
---|
57 | *
|
---|
58 | * `%parse-param`-specified additional `parse()` arguments have been added to this `yy`
|
---|
59 | * object at `parse()` start and are therefore available to the action code via the
|
---|
60 | * same named `yy.xxxx` attributes (where `xxxx` represents a identifier name from
|
---|
61 | * the %parse-param` list.
|
---|
62 | *
|
---|
63 | * - `yytext` : reference to the lexer value which belongs to the last lexer token used
|
---|
64 | * to match this rule. This is *not* the look-ahead token, but the last token
|
---|
65 | * that's actually part of this rule.
|
---|
66 | *
|
---|
67 | * Formulated another way, `yytext` is the value of the token immediately preceeding
|
---|
68 | * the current look-ahead token.
|
---|
69 | * Caveats apply for rules which don't require look-ahead, such as epsilon rules.
|
---|
70 | *
|
---|
71 | * - `yyleng` : ditto as `yytext`, only now for the lexer.yyleng value.
|
---|
72 | *
|
---|
73 | * - `yylineno`: ditto as `yytext`, only now for the lexer.yylineno value.
|
---|
74 | *
|
---|
75 | * - `yyloc` : ditto as `yytext`, only now for the lexer.yylloc lexer token location info.
|
---|
76 | *
|
---|
77 | * WARNING: since jison 0.4.18-186 this entry may be NULL/UNDEFINED instead
|
---|
78 | * of an empty object when no suitable location info can be provided.
|
---|
79 | *
|
---|
80 | * - `yystate` : the current parser state number, used internally for dispatching and
|
---|
81 | * executing the action code chunk matching the rule currently being reduced.
|
---|
82 | *
|
---|
83 | * - `yysp` : the current state stack position (a.k.a. 'stack pointer')
|
---|
84 | *
|
---|
85 | * This one comes in handy when you are going to do advanced things to the parser
|
---|
86 | * stacks, all of which are accessible from your action code (see the next entries below).
|
---|
87 | *
|
---|
88 | * Also note that you can access this and other stack index values using the new double-hash
|
---|
89 | * syntax, i.e. `##$ === ##0 === yysp`, while `##1` is the stack index for all things
|
---|
90 | * related to the first rule term, just like you have `$1`, `@1` and `#1`.
|
---|
91 | * This is made available to write very advanced grammar action rules, e.g. when you want
|
---|
92 | * to investigate the parse state stack in your action code, which would, for example,
|
---|
93 | * be relevant when you wish to implement error diagnostics and reporting schemes similar
|
---|
94 | * to the work described here:
|
---|
95 | *
|
---|
96 | * + Pottier, F., 2016. Reachability and error diagnosis in LR(1) automata.
|
---|
97 | * In Journées Francophones des Languages Applicatifs.
|
---|
98 | *
|
---|
99 | * + Jeffery, C.L., 2003. Generating LR syntax error messages from examples.
|
---|
100 | * ACM Transactions on Programming Languages and Systems (TOPLAS), 25(5), pp.631–640.
|
---|
101 | *
|
---|
102 | * - `yyrulelength`: the current rule's term count, i.e. the number of entries occupied on the stack.
|
---|
103 | *
|
---|
104 | * This one comes in handy when you are going to do advanced things to the parser
|
---|
105 | * stacks, all of which are accessible from your action code (see the next entries below).
|
---|
106 | *
|
---|
107 | * - `yyvstack`: reference to the parser value stack. Also accessed via the `$1` etc.
|
---|
108 | * constructs.
|
---|
109 | *
|
---|
110 | * - `yylstack`: reference to the parser token location stack. Also accessed via
|
---|
111 | * the `@1` etc. constructs.
|
---|
112 | *
|
---|
113 | * WARNING: since jison 0.4.18-186 this array MAY contain slots which are
|
---|
114 | * UNDEFINED rather than an empty (location) object, when the lexer/parser
|
---|
115 | * action code did not provide a suitable location info object when such a
|
---|
116 | * slot was filled!
|
---|
117 | *
|
---|
118 | * - `yystack` : reference to the parser token id stack. Also accessed via the
|
---|
119 | * `#1` etc. constructs.
|
---|
120 | *
|
---|
121 | * Note: this is a bit of a **white lie** as we can statically decode any `#n` reference to
|
---|
122 | * its numeric token id value, hence that code wouldn't need the `yystack` but *you* might
|
---|
123 | * want access this array for your own purposes, such as error analysis as mentioned above!
|
---|
124 | *
|
---|
125 | * Note that this stack stores the current stack of *tokens*, that is the sequence of
|
---|
126 | * already parsed=reduced *nonterminals* (tokens representing rules) and *terminals*
|
---|
127 | * (lexer tokens *shifted* onto the stack until the rule they belong to is found and
|
---|
128 | * *reduced*.
|
---|
129 | *
|
---|
130 | * - `yysstack`: reference to the parser state stack. This one carries the internal parser
|
---|
131 | * *states* such as the one in `yystate`, which are used to represent
|
---|
132 | * the parser state machine in the *parse table*. *Very* *internal* stuff,
|
---|
133 | * what can I say? If you access this one, you're clearly doing wicked things
|
---|
134 | *
|
---|
135 | * - `...` : the extra arguments you specified in the `%parse-param` statement in your
|
---|
136 | * grammar definition file.
|
---|
137 | *
|
---|
138 | * table: [...],
|
---|
139 | * State transition table
|
---|
140 | * ----------------------
|
---|
141 | *
|
---|
142 | * index levels are:
|
---|
143 | * - `state` --> hash table
|
---|
144 | * - `symbol` --> action (number or array)
|
---|
145 | *
|
---|
146 | * If the `action` is an array, these are the elements' meaning:
|
---|
147 | * - index [0]: 1 = shift, 2 = reduce, 3 = accept
|
---|
148 | * - index [1]: GOTO `state`
|
---|
149 | *
|
---|
150 | * If the `action` is a number, it is the GOTO `state`
|
---|
151 | *
|
---|
152 | * defaultActions: {...},
|
---|
153 | *
|
---|
154 | * parseError: function(str, hash, ExceptionClass),
|
---|
155 | * yyError: function(str, ...),
|
---|
156 | * yyRecovering: function(),
|
---|
157 | * yyErrOk: function(),
|
---|
158 | * yyClearIn: function(),
|
---|
159 | *
|
---|
160 | * constructParseErrorInfo: function(error_message, exception_object, expected_token_set, is_recoverable),
|
---|
161 | * Helper function **which will be set up during the first invocation of the `parse()` method**.
|
---|
162 | * Produces a new errorInfo 'hash object' which can be passed into `parseError()`.
|
---|
163 | * See it's use in this parser kernel in many places; example usage:
|
---|
164 | *
|
---|
165 | * var infoObj = parser.constructParseErrorInfo('fail!', null,
|
---|
166 | * parser.collect_expected_token_set(state), true);
|
---|
167 | * var retVal = parser.parseError(infoObj.errStr, infoObj, parser.JisonParserError);
|
---|
168 | *
|
---|
169 | * originalParseError: function(str, hash, ExceptionClass),
|
---|
170 | * The basic `parseError` handler provided by JISON.
|
---|
171 | * `cleanupAfterParse()` will clean up and reset `parseError()` to reference this function
|
---|
172 | * at the end of the `parse()`.
|
---|
173 | *
|
---|
174 | * options: { ... parser %options ... },
|
---|
175 | *
|
---|
176 | * parse: function(input[, args...]),
|
---|
177 | * Parse the given `input` and return the parsed value (or `true` when none was provided by
|
---|
178 | * the root action, in which case the parser is acting as a *matcher*).
|
---|
179 | * You MAY use the additional `args...` parameters as per `%parse-param` spec of this grammar:
|
---|
180 | * these extra `args...` are added verbatim to the `yy` object reference as member variables.
|
---|
181 | *
|
---|
182 | * WARNING:
|
---|
183 | * Parser's additional `args...` parameters (via `%parse-param`) MAY conflict with
|
---|
184 | * any attributes already added to `yy` by the jison run-time;
|
---|
185 | * when such a collision is detected an exception is thrown to prevent the generated run-time
|
---|
186 | * from silently accepting this confusing and potentially hazardous situation!
|
---|
187 | *
|
---|
188 | * The lexer MAY add its own set of additional parameters (via the `%parse-param` line in
|
---|
189 | * the lexer section of the grammar spec): these will be inserted in the `yy` shared state
|
---|
190 | * object and any collision with those will be reported by the lexer via a thrown exception.
|
---|
191 | *
|
---|
192 | * cleanupAfterParse: function(resultValue, invoke_post_methods, do_not_nuke_errorinfos),
|
---|
193 | * Helper function **which will be set up during the first invocation of the `parse()` method**.
|
---|
194 | * This helper API is invoked at the end of the `parse()` call, unless an exception was thrown
|
---|
195 | * and `%options no-try-catch` has been defined for this grammar: in that case this helper MAY
|
---|
196 | * be invoked by calling user code to ensure the `post_parse` callbacks are invoked and
|
---|
197 | * the internal parser gets properly garbage collected under these particular circumstances.
|
---|
198 | *
|
---|
199 | * yyMergeLocationInfo: function(first_index, last_index, first_yylloc, last_yylloc, dont_look_back),
|
---|
200 | * Helper function **which will be set up during the first invocation of the `parse()` method**.
|
---|
201 | * This helper API can be invoked to calculate a spanning `yylloc` location info object.
|
---|
202 | *
|
---|
203 | * Note: %epsilon rules MAY specify no `first_index` and `first_yylloc`, in which case
|
---|
204 | * this function will attempt to obtain a suitable location marker by inspecting the location stack
|
---|
205 | * backwards.
|
---|
206 | *
|
---|
207 | * For more info see the documentation comment further below, immediately above this function's
|
---|
208 | * implementation.
|
---|
209 | *
|
---|
210 | * lexer: {
|
---|
211 | * yy: {...}, A reference to the so-called "shared state" `yy` once
|
---|
212 | * received via a call to the `.setInput(input, yy)` lexer API.
|
---|
213 | * EOF: 1,
|
---|
214 | * ERROR: 2,
|
---|
215 | * JisonLexerError: function(msg, hash),
|
---|
216 | * parseError: function(str, hash, ExceptionClass),
|
---|
217 | * setInput: function(input, [yy]),
|
---|
218 | * input: function(),
|
---|
219 | * unput: function(str),
|
---|
220 | * more: function(),
|
---|
221 | * reject: function(),
|
---|
222 | * less: function(n),
|
---|
223 | * pastInput: function(n),
|
---|
224 | * upcomingInput: function(n),
|
---|
225 | * showPosition: function(),
|
---|
226 | * test_match: function(regex_match_array, rule_index, ...),
|
---|
227 | * next: function(...),
|
---|
228 | * lex: function(...),
|
---|
229 | * begin: function(condition),
|
---|
230 | * pushState: function(condition),
|
---|
231 | * popState: function(),
|
---|
232 | * topState: function(),
|
---|
233 | * _currentRules: function(),
|
---|
234 | * stateStackSize: function(),
|
---|
235 | * cleanupAfterLex: function()
|
---|
236 | *
|
---|
237 | * options: { ... lexer %options ... },
|
---|
238 | *
|
---|
239 | * performAction: function(yy, yy_, $avoiding_name_collisions, YY_START, ...),
|
---|
240 | * rules: [...],
|
---|
241 | * conditions: {associative list: name ==> set},
|
---|
242 | * }
|
---|
243 | * }
|
---|
244 | *
|
---|
245 | *
|
---|
246 | * token location info (@$, _$, etc.): {
|
---|
247 | * first_line: n,
|
---|
248 | * last_line: n,
|
---|
249 | * first_column: n,
|
---|
250 | * last_column: n,
|
---|
251 | * range: [start_number, end_number]
|
---|
252 | * (where the numbers are indexes into the input string, zero-based)
|
---|
253 | * }
|
---|
254 | *
|
---|
255 | * ---
|
---|
256 | *
|
---|
257 | * The `parseError` function receives a 'hash' object with these members for lexer and
|
---|
258 | * parser errors:
|
---|
259 | *
|
---|
260 | * {
|
---|
261 | * text: (matched text)
|
---|
262 | * token: (the produced terminal token, if any)
|
---|
263 | * token_id: (the produced terminal token numeric ID, if any)
|
---|
264 | * line: (yylineno)
|
---|
265 | * loc: (yylloc)
|
---|
266 | * }
|
---|
267 | *
|
---|
268 | * parser (grammar) errors will also provide these additional members:
|
---|
269 | *
|
---|
270 | * {
|
---|
271 | * expected: (array describing the set of expected tokens;
|
---|
272 | * may be UNDEFINED when we cannot easily produce such a set)
|
---|
273 | * state: (integer (or array when the table includes grammar collisions);
|
---|
274 | * represents the current internal state of the parser kernel.
|
---|
275 | * can, for example, be used to pass to the `collect_expected_token_set()`
|
---|
276 | * API to obtain the expected token set)
|
---|
277 | * action: (integer; represents the current internal action which will be executed)
|
---|
278 | * new_state: (integer; represents the next/planned internal state, once the current
|
---|
279 | * action has executed)
|
---|
280 | * recoverable: (boolean: TRUE when the parser MAY have an error recovery rule
|
---|
281 | * available for this particular error)
|
---|
282 | * state_stack: (array: the current parser LALR/LR internal state stack; this can be used,
|
---|
283 | * for instance, for advanced error analysis and reporting)
|
---|
284 | * value_stack: (array: the current parser LALR/LR internal `$$` value stack; this can be used,
|
---|
285 | * for instance, for advanced error analysis and reporting)
|
---|
286 | * location_stack: (array: the current parser LALR/LR internal location stack; this can be used,
|
---|
287 | * for instance, for advanced error analysis and reporting)
|
---|
288 | * yy: (object: the current parser internal "shared state" `yy`
|
---|
289 | * as is also available in the rule actions; this can be used,
|
---|
290 | * for instance, for advanced error analysis and reporting)
|
---|
291 | * lexer: (reference to the current lexer instance used by the parser)
|
---|
292 | * parser: (reference to the current parser instance)
|
---|
293 | * }
|
---|
294 | *
|
---|
295 | * while `this` will reference the current parser instance.
|
---|
296 | *
|
---|
297 | * When `parseError` is invoked by the lexer, `this` will still reference the related *parser*
|
---|
298 | * instance, while these additional `hash` fields will also be provided:
|
---|
299 | *
|
---|
300 | * {
|
---|
301 | * lexer: (reference to the current lexer instance which reported the error)
|
---|
302 | * }
|
---|
303 | *
|
---|
304 | * When `parseError` is invoked by the parser due to a **JavaScript exception** being fired
|
---|
305 | * from either the parser or lexer, `this` will still reference the related *parser*
|
---|
306 | * instance, while these additional `hash` fields will also be provided:
|
---|
307 | *
|
---|
308 | * {
|
---|
309 | * exception: (reference to the exception thrown)
|
---|
310 | * }
|
---|
311 | *
|
---|
312 | * Please do note that in the latter situation, the `expected` field will be omitted as
|
---|
313 | * this type of failure is assumed not to be due to *parse errors* but rather due to user
|
---|
314 | * action code in either parser or lexer failing unexpectedly.
|
---|
315 | *
|
---|
316 | * ---
|
---|
317 | *
|
---|
318 | * You can specify parser options by setting / modifying the `.yy` object of your Parser instance.
|
---|
319 | * These options are available:
|
---|
320 | *
|
---|
321 | * ### options which are global for all parser instances
|
---|
322 | *
|
---|
323 | * Parser.pre_parse: function(yy)
|
---|
324 | * optional: you can specify a pre_parse() function in the chunk following
|
---|
325 | * the grammar, i.e. after the last `%%`.
|
---|
326 | * Parser.post_parse: function(yy, retval, parseInfo) { return retval; }
|
---|
327 | * optional: you can specify a post_parse() function in the chunk following
|
---|
328 | * the grammar, i.e. after the last `%%`. When it does not return any value,
|
---|
329 | * the parser will return the original `retval`.
|
---|
330 | *
|
---|
331 | * ### options which can be set up per parser instance
|
---|
332 | *
|
---|
333 | * yy: {
|
---|
334 | * pre_parse: function(yy)
|
---|
335 | * optional: is invoked before the parse cycle starts (and before the first
|
---|
336 | * invocation of `lex()`) but immediately after the invocation of
|
---|
337 | * `parser.pre_parse()`).
|
---|
338 | * post_parse: function(yy, retval, parseInfo) { return retval; }
|
---|
339 | * optional: is invoked when the parse terminates due to success ('accept')
|
---|
340 | * or failure (even when exceptions are thrown).
|
---|
341 | * `retval` contains the return value to be produced by `Parser.parse()`;
|
---|
342 | * this function can override the return value by returning another.
|
---|
343 | * When it does not return any value, the parser will return the original
|
---|
344 | * `retval`.
|
---|
345 | * This function is invoked immediately before `parser.post_parse()`.
|
---|
346 | *
|
---|
347 | * parseError: function(str, hash, ExceptionClass)
|
---|
348 | * optional: overrides the default `parseError` function.
|
---|
349 | * quoteName: function(name),
|
---|
350 | * optional: overrides the default `quoteName` function.
|
---|
351 | * }
|
---|
352 | *
|
---|
353 | * parser.lexer.options: {
|
---|
354 | * pre_lex: function()
|
---|
355 | * optional: is invoked before the lexer is invoked to produce another token.
|
---|
356 | * `this` refers to the Lexer object.
|
---|
357 | * post_lex: function(token) { return token; }
|
---|
358 | * optional: is invoked when the lexer has produced a token `token`;
|
---|
359 | * this function can override the returned token value by returning another.
|
---|
360 | * When it does not return any (truthy) value, the lexer will return
|
---|
361 | * the original `token`.
|
---|
362 | * `this` refers to the Lexer object.
|
---|
363 | *
|
---|
364 | * ranges: boolean
|
---|
365 | * optional: `true` ==> token location info will include a .range[] member.
|
---|
366 | * flex: boolean
|
---|
367 | * optional: `true` ==> flex-like lexing behaviour where the rules are tested
|
---|
368 | * exhaustively to find the longest match.
|
---|
369 | * backtrack_lexer: boolean
|
---|
370 | * optional: `true` ==> lexer regexes are tested in order and for invoked;
|
---|
371 | * the lexer terminates the scan when a token is returned by the action code.
|
---|
372 | * xregexp: boolean
|
---|
373 | * optional: `true` ==> lexer rule regexes are "extended regex format" requiring the
|
---|
374 | * `XRegExp` library. When this `%option` has not been specified at compile time, all lexer
|
---|
375 | * rule regexes have been written as standard JavaScript RegExp expressions.
|
---|
376 | * }
|
---|
377 | */
|
---|
378 |
|
---|
379 |
|
---|
380 |
|
---|
381 | var parser = (function () {
|
---|
382 |
|
---|
383 |
|
---|
384 | // See also:
|
---|
385 | // http://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript/#35881508
|
---|
386 | // but we keep the prototype.constructor and prototype.name assignment lines too for compatibility
|
---|
387 | // with userland code which might access the derived class in a 'classic' way.
|
---|
388 | function JisonParserError(msg, hash) {
|
---|
389 | Object.defineProperty(this, 'name', {
|
---|
390 | enumerable: false,
|
---|
391 | writable: false,
|
---|
392 | value: 'JisonParserError'
|
---|
393 | });
|
---|
394 |
|
---|
395 | if (msg == null) msg = '???';
|
---|
396 |
|
---|
397 | Object.defineProperty(this, 'message', {
|
---|
398 | enumerable: false,
|
---|
399 | writable: true,
|
---|
400 | value: msg
|
---|
401 | });
|
---|
402 |
|
---|
403 | this.hash = hash;
|
---|
404 |
|
---|
405 | var stacktrace;
|
---|
406 | if (hash && hash.exception instanceof Error) {
|
---|
407 | var ex2 = hash.exception;
|
---|
408 | this.message = ex2.message || msg;
|
---|
409 | stacktrace = ex2.stack;
|
---|
410 | }
|
---|
411 | if (!stacktrace) {
|
---|
412 | if (Error.hasOwnProperty('captureStackTrace')) { // V8/Chrome engine
|
---|
413 | Error.captureStackTrace(this, this.constructor);
|
---|
414 | } else {
|
---|
415 | stacktrace = (new Error(msg)).stack;
|
---|
416 | }
|
---|
417 | }
|
---|
418 | if (stacktrace) {
|
---|
419 | Object.defineProperty(this, 'stack', {
|
---|
420 | enumerable: false,
|
---|
421 | writable: false,
|
---|
422 | value: stacktrace
|
---|
423 | });
|
---|
424 | }
|
---|
425 | }
|
---|
426 |
|
---|
427 | if (typeof Object.setPrototypeOf === 'function') {
|
---|
428 | Object.setPrototypeOf(JisonParserError.prototype, Error.prototype);
|
---|
429 | } else {
|
---|
430 | JisonParserError.prototype = Object.create(Error.prototype);
|
---|
431 | }
|
---|
432 | JisonParserError.prototype.constructor = JisonParserError;
|
---|
433 | JisonParserError.prototype.name = 'JisonParserError';
|
---|
434 |
|
---|
435 |
|
---|
436 |
|
---|
437 |
|
---|
438 | // helper: reconstruct the productions[] table
|
---|
439 | function bp(s) {
|
---|
440 | var rv = [];
|
---|
441 | var p = s.pop;
|
---|
442 | var r = s.rule;
|
---|
443 | for (var i = 0, l = p.length; i < l; i++) {
|
---|
444 | rv.push([
|
---|
445 | p[i],
|
---|
446 | r[i]
|
---|
447 | ]);
|
---|
448 | }
|
---|
449 | return rv;
|
---|
450 | }
|
---|
451 |
|
---|
452 |
|
---|
453 |
|
---|
454 | // helper: reconstruct the defaultActions[] table
|
---|
455 | function bda(s) {
|
---|
456 | var rv = {};
|
---|
457 | var d = s.idx;
|
---|
458 | var g = s.goto;
|
---|
459 | for (var i = 0, l = d.length; i < l; i++) {
|
---|
460 | var j = d[i];
|
---|
461 | rv[j] = g[i];
|
---|
462 | }
|
---|
463 | return rv;
|
---|
464 | }
|
---|
465 |
|
---|
466 |
|
---|
467 |
|
---|
468 | // helper: reconstruct the 'goto' table
|
---|
469 | function bt(s) {
|
---|
470 | var rv = [];
|
---|
471 | var d = s.len;
|
---|
472 | var y = s.symbol;
|
---|
473 | var t = s.type;
|
---|
474 | var a = s.state;
|
---|
475 | var m = s.mode;
|
---|
476 | var g = s.goto;
|
---|
477 | for (var i = 0, l = d.length; i < l; i++) {
|
---|
478 | var n = d[i];
|
---|
479 | var q = {};
|
---|
480 | for (var j = 0; j < n; j++) {
|
---|
481 | var z = y.shift();
|
---|
482 | switch (t.shift()) {
|
---|
483 | case 2:
|
---|
484 | q[z] = [
|
---|
485 | m.shift(),
|
---|
486 | g.shift()
|
---|
487 | ];
|
---|
488 | break;
|
---|
489 |
|
---|
490 | case 0:
|
---|
491 | q[z] = a.shift();
|
---|
492 | break;
|
---|
493 |
|
---|
494 | default:
|
---|
495 | // type === 1: accept
|
---|
496 | q[z] = [
|
---|
497 | 3
|
---|
498 | ];
|
---|
499 | }
|
---|
500 | }
|
---|
501 | rv.push(q);
|
---|
502 | }
|
---|
503 | return rv;
|
---|
504 | }
|
---|
505 |
|
---|
506 |
|
---|
507 |
|
---|
508 | // helper: runlength encoding with increment step: code, length: step (default step = 0)
|
---|
509 | // `this` references an array
|
---|
510 | function s(c, l, a) {
|
---|
511 | a = a || 0;
|
---|
512 | for (var i = 0; i < l; i++) {
|
---|
513 | this.push(c);
|
---|
514 | c += a;
|
---|
515 | }
|
---|
516 | }
|
---|
517 |
|
---|
518 | // helper: duplicate sequence from *relative* offset and length.
|
---|
519 | // `this` references an array
|
---|
520 | function c(i, l) {
|
---|
521 | i = this.length - i;
|
---|
522 | for (l += i; i < l; i++) {
|
---|
523 | this.push(this[i]);
|
---|
524 | }
|
---|
525 | }
|
---|
526 |
|
---|
527 | // helper: unpack an array using helpers and data, all passed in an array argument 'a'.
|
---|
528 | function u(a) {
|
---|
529 | var rv = [];
|
---|
530 | for (var i = 0, l = a.length; i < l; i++) {
|
---|
531 | var e = a[i];
|
---|
532 | // Is this entry a helper function?
|
---|
533 | if (typeof e === 'function') {
|
---|
534 | i++;
|
---|
535 | e.apply(rv, a[i]);
|
---|
536 | } else {
|
---|
537 | rv.push(e);
|
---|
538 | }
|
---|
539 | }
|
---|
540 | return rv;
|
---|
541 | }
|
---|
542 |
|
---|
543 |
|
---|
544 | var parser = {
|
---|
545 | // Code Generator Information Report
|
---|
546 | // ---------------------------------
|
---|
547 | //
|
---|
548 | // Options:
|
---|
549 | //
|
---|
550 | // default action mode: ............. ["classic","merge"]
|
---|
551 | // test-compile action mode: ........ "parser:*,lexer:*"
|
---|
552 | // try..catch: ...................... true
|
---|
553 | // default resolve on conflict: ..... true
|
---|
554 | // on-demand look-ahead: ............ false
|
---|
555 | // error recovery token skip maximum: 3
|
---|
556 | // yyerror in parse actions is: ..... NOT recoverable,
|
---|
557 | // yyerror in lexer actions and other non-fatal lexer are:
|
---|
558 | // .................................. NOT recoverable,
|
---|
559 | // debug grammar/output: ............ false
|
---|
560 | // has partial LR conflict upgrade: true
|
---|
561 | // rudimentary token-stack support: false
|
---|
562 | // parser table compression mode: ... 2
|
---|
563 | // export debug tables: ............. false
|
---|
564 | // export *all* tables: ............. false
|
---|
565 | // module type: ..................... commonjs
|
---|
566 | // parser engine type: .............. lalr
|
---|
567 | // output main() in the module: ..... true
|
---|
568 | // has user-specified main(): ....... false
|
---|
569 | // has user-specified require()/import modules for main():
|
---|
570 | // .................................. false
|
---|
571 | // number of expected conflicts: .... 0
|
---|
572 | //
|
---|
573 | //
|
---|
574 | // Parser Analysis flags:
|
---|
575 | //
|
---|
576 | // no significant actions (parser is a language matcher only):
|
---|
577 | // .................................. false
|
---|
578 | // uses yyleng: ..................... false
|
---|
579 | // uses yylineno: ................... false
|
---|
580 | // uses yytext: ..................... false
|
---|
581 | // uses yylloc: ..................... false
|
---|
582 | // uses ParseError API: ............. false
|
---|
583 | // uses YYERROR: .................... false
|
---|
584 | // uses YYRECOVERING: ............... false
|
---|
585 | // uses YYERROK: .................... false
|
---|
586 | // uses YYCLEARIN: .................. false
|
---|
587 | // tracks rule values: .............. true
|
---|
588 | // assigns rule values: ............. true
|
---|
589 | // uses location tracking: .......... false
|
---|
590 | // assigns location: ................ false
|
---|
591 | // uses yystack: .................... false
|
---|
592 | // uses yysstack: ................... false
|
---|
593 | // uses yysp: ....................... true
|
---|
594 | // uses yyrulelength: ............... false
|
---|
595 | // uses yyMergeLocationInfo API: .... false
|
---|
596 | // has error recovery: .............. false
|
---|
597 | // has error reporting: ............. false
|
---|
598 | //
|
---|
599 | // --------- END OF REPORT -----------
|
---|
600 |
|
---|
601 | trace: function no_op_trace() { },
|
---|
602 | JisonParserError: JisonParserError,
|
---|
603 | yy: {},
|
---|
604 | options: {
|
---|
605 | type: "lalr",
|
---|
606 | hasPartialLrUpgradeOnConflict: true,
|
---|
607 | errorRecoveryTokenDiscardCount: 3
|
---|
608 | },
|
---|
609 | symbols_: {
|
---|
610 | "$accept": 0,
|
---|
611 | "$end": 1,
|
---|
612 | "ADD": 6,
|
---|
613 | "ANGLE": 12,
|
---|
614 | "CALC": 3,
|
---|
615 | "CHS": 19,
|
---|
616 | "DIV": 9,
|
---|
617 | "EMS": 17,
|
---|
618 | "EOF": 1,
|
---|
619 | "EXS": 18,
|
---|
620 | "FREQ": 14,
|
---|
621 | "FUNCTION": 10,
|
---|
622 | "LENGTH": 11,
|
---|
623 | "LPAREN": 4,
|
---|
624 | "MUL": 8,
|
---|
625 | "NUMBER": 26,
|
---|
626 | "PERCENTAGE": 25,
|
---|
627 | "REMS": 20,
|
---|
628 | "RES": 15,
|
---|
629 | "RPAREN": 5,
|
---|
630 | "SUB": 7,
|
---|
631 | "TIME": 13,
|
---|
632 | "UNKNOWN_DIMENSION": 16,
|
---|
633 | "VHS": 21,
|
---|
634 | "VMAXS": 24,
|
---|
635 | "VMINS": 23,
|
---|
636 | "VWS": 22,
|
---|
637 | "dimension": 30,
|
---|
638 | "error": 2,
|
---|
639 | "expression": 27,
|
---|
640 | "function": 29,
|
---|
641 | "math_expression": 28,
|
---|
642 | "number": 31
|
---|
643 | },
|
---|
644 | terminals_: {
|
---|
645 | 1: "EOF",
|
---|
646 | 2: "error",
|
---|
647 | 3: "CALC",
|
---|
648 | 4: "LPAREN",
|
---|
649 | 5: "RPAREN",
|
---|
650 | 6: "ADD",
|
---|
651 | 7: "SUB",
|
---|
652 | 8: "MUL",
|
---|
653 | 9: "DIV",
|
---|
654 | 10: "FUNCTION",
|
---|
655 | 11: "LENGTH",
|
---|
656 | 12: "ANGLE",
|
---|
657 | 13: "TIME",
|
---|
658 | 14: "FREQ",
|
---|
659 | 15: "RES",
|
---|
660 | 16: "UNKNOWN_DIMENSION",
|
---|
661 | 17: "EMS",
|
---|
662 | 18: "EXS",
|
---|
663 | 19: "CHS",
|
---|
664 | 20: "REMS",
|
---|
665 | 21: "VHS",
|
---|
666 | 22: "VWS",
|
---|
667 | 23: "VMINS",
|
---|
668 | 24: "VMAXS",
|
---|
669 | 25: "PERCENTAGE",
|
---|
670 | 26: "NUMBER"
|
---|
671 | },
|
---|
672 | TERROR: 2,
|
---|
673 | EOF: 1,
|
---|
674 |
|
---|
675 | // internals: defined here so the object *structure* doesn't get modified by parse() et al,
|
---|
676 | // thus helping JIT compilers like Chrome V8.
|
---|
677 | originalQuoteName: null,
|
---|
678 | originalParseError: null,
|
---|
679 | cleanupAfterParse: null,
|
---|
680 | constructParseErrorInfo: null,
|
---|
681 | yyMergeLocationInfo: null,
|
---|
682 |
|
---|
683 | __reentrant_call_depth: 0, // INTERNAL USE ONLY
|
---|
684 | __error_infos: [], // INTERNAL USE ONLY: the set of parseErrorInfo objects created since the last cleanup
|
---|
685 | __error_recovery_infos: [], // INTERNAL USE ONLY: the set of parseErrorInfo objects created since the last cleanup
|
---|
686 |
|
---|
687 | // APIs which will be set up depending on user action code analysis:
|
---|
688 | //yyRecovering: 0,
|
---|
689 | //yyErrOk: 0,
|
---|
690 | //yyClearIn: 0,
|
---|
691 |
|
---|
692 | // Helper APIs
|
---|
693 | // -----------
|
---|
694 |
|
---|
695 | // Helper function which can be overridden by user code later on: put suitable quotes around
|
---|
696 | // literal IDs in a description string.
|
---|
697 | quoteName: function parser_quoteName(id_str) {
|
---|
698 | return '"' + id_str + '"';
|
---|
699 | },
|
---|
700 |
|
---|
701 | // Return the name of the given symbol (terminal or non-terminal) as a string, when available.
|
---|
702 | //
|
---|
703 | // Return NULL when the symbol is unknown to the parser.
|
---|
704 | getSymbolName: function parser_getSymbolName(symbol) {
|
---|
705 | if (this.terminals_[symbol]) {
|
---|
706 | return this.terminals_[symbol];
|
---|
707 | }
|
---|
708 |
|
---|
709 | // Otherwise... this might refer to a RULE token i.e. a non-terminal: see if we can dig that one up.
|
---|
710 | //
|
---|
711 | // An example of this may be where a rule's action code contains a call like this:
|
---|
712 | //
|
---|
713 | // parser.getSymbolName(#$)
|
---|
714 | //
|
---|
715 | // to obtain a human-readable name of the current grammar rule.
|
---|
716 | var s = this.symbols_;
|
---|
717 | for (var key in s) {
|
---|
718 | if (s[key] === symbol) {
|
---|
719 | return key;
|
---|
720 | }
|
---|
721 | }
|
---|
722 | return null;
|
---|
723 | },
|
---|
724 |
|
---|
725 | // Return a more-or-less human-readable description of the given symbol, when available,
|
---|
726 | // or the symbol itself, serving as its own 'description' for lack of something better to serve up.
|
---|
727 | //
|
---|
728 | // Return NULL when the symbol is unknown to the parser.
|
---|
729 | describeSymbol: function parser_describeSymbol(symbol) {
|
---|
730 | if (symbol !== this.EOF && this.terminal_descriptions_ && this.terminal_descriptions_[symbol]) {
|
---|
731 | return this.terminal_descriptions_[symbol];
|
---|
732 | }
|
---|
733 | else if (symbol === this.EOF) {
|
---|
734 | return 'end of input';
|
---|
735 | }
|
---|
736 | var id = this.getSymbolName(symbol);
|
---|
737 | if (id) {
|
---|
738 | return this.quoteName(id);
|
---|
739 | }
|
---|
740 | return null;
|
---|
741 | },
|
---|
742 |
|
---|
743 | // Produce a (more or less) human-readable list of expected tokens at the point of failure.
|
---|
744 | //
|
---|
745 | // The produced list may contain token or token set descriptions instead of the tokens
|
---|
746 | // themselves to help turning this output into something that easier to read by humans
|
---|
747 | // unless `do_not_describe` parameter is set, in which case a list of the raw, *numeric*,
|
---|
748 | // expected terminals and nonterminals is produced.
|
---|
749 | //
|
---|
750 | // The returned list (array) will not contain any duplicate entries.
|
---|
751 | collect_expected_token_set: function parser_collect_expected_token_set(state, do_not_describe) {
|
---|
752 | var TERROR = this.TERROR;
|
---|
753 | var tokenset = [];
|
---|
754 | var check = {};
|
---|
755 | // Has this (error?) state been outfitted with a custom expectations description text for human consumption?
|
---|
756 | // If so, use that one instead of the less palatable token set.
|
---|
757 | if (!do_not_describe && this.state_descriptions_ && this.state_descriptions_[state]) {
|
---|
758 | return [
|
---|
759 | this.state_descriptions_[state]
|
---|
760 | ];
|
---|
761 | }
|
---|
762 | for (var p in this.table[state]) {
|
---|
763 | p = +p;
|
---|
764 | if (p !== TERROR) {
|
---|
765 | var d = do_not_describe ? p : this.describeSymbol(p);
|
---|
766 | if (d && !check[d]) {
|
---|
767 | tokenset.push(d);
|
---|
768 | check[d] = true; // Mark this token description as already mentioned to prevent outputting duplicate entries.
|
---|
769 | }
|
---|
770 | }
|
---|
771 | }
|
---|
772 | return tokenset;
|
---|
773 | },
|
---|
774 | productions_: bp({
|
---|
775 | pop: u([
|
---|
776 | 27,
|
---|
777 | s,
|
---|
778 | [28, 9],
|
---|
779 | 29,
|
---|
780 | s,
|
---|
781 | [30, 17],
|
---|
782 | s,
|
---|
783 | [31, 3]
|
---|
784 | ]),
|
---|
785 | rule: u([
|
---|
786 | 2,
|
---|
787 | 4,
|
---|
788 | s,
|
---|
789 | [3, 5],
|
---|
790 | s,
|
---|
791 | [1, 19],
|
---|
792 | 2,
|
---|
793 | 2,
|
---|
794 | c,
|
---|
795 | [3, 3]
|
---|
796 | ])
|
---|
797 | }),
|
---|
798 | performAction: function parser__PerformAction(yystate /* action[1] */, yysp, yyvstack) {
|
---|
799 |
|
---|
800 | /* this == yyval */
|
---|
801 |
|
---|
802 | // the JS engine itself can go and remove these statements when `yy` turns out to be unused in any action code!
|
---|
803 | var yy = this.yy;
|
---|
804 | var yyparser = yy.parser;
|
---|
805 | var yylexer = yy.lexer;
|
---|
806 |
|
---|
807 |
|
---|
808 |
|
---|
809 | switch (yystate) {
|
---|
810 | case 0:
|
---|
811 | /*! Production:: $accept : expression $end */
|
---|
812 |
|
---|
813 | // default action (generated by JISON mode classic/merge :: 1,VT,VA,-,-,-,-,-,-):
|
---|
814 | this.$ = yyvstack[yysp - 1];
|
---|
815 | // END of default action (generated by JISON mode classic/merge :: 1,VT,VA,-,-,-,-,-,-)
|
---|
816 | break;
|
---|
817 |
|
---|
818 | case 1:
|
---|
819 | /*! Production:: expression : math_expression EOF */
|
---|
820 |
|
---|
821 | // default action (generated by JISON mode classic/merge :: 2,VT,VA,-,-,-,-,-,-):
|
---|
822 | this.$ = yyvstack[yysp - 1];
|
---|
823 | // END of default action (generated by JISON mode classic/merge :: 2,VT,VA,-,-,-,-,-,-)
|
---|
824 |
|
---|
825 |
|
---|
826 | return yyvstack[yysp - 1];
|
---|
827 | break;
|
---|
828 |
|
---|
829 | case 2:
|
---|
830 | /*! Production:: math_expression : CALC LPAREN math_expression RPAREN */
|
---|
831 | case 7:
|
---|
832 | /*! Production:: math_expression : LPAREN math_expression RPAREN */
|
---|
833 |
|
---|
834 | this.$ = yyvstack[yysp - 1];
|
---|
835 | break;
|
---|
836 |
|
---|
837 | case 3:
|
---|
838 | /*! Production:: math_expression : math_expression ADD math_expression */
|
---|
839 | case 4:
|
---|
840 | /*! Production:: math_expression : math_expression SUB math_expression */
|
---|
841 | case 5:
|
---|
842 | /*! Production:: math_expression : math_expression MUL math_expression */
|
---|
843 | case 6:
|
---|
844 | /*! Production:: math_expression : math_expression DIV math_expression */
|
---|
845 |
|
---|
846 | this.$ = { type: 'MathExpression', operator: yyvstack[yysp - 1], left: yyvstack[yysp - 2], right: yyvstack[yysp] };
|
---|
847 | break;
|
---|
848 |
|
---|
849 | case 8:
|
---|
850 | /*! Production:: math_expression : function */
|
---|
851 | case 9:
|
---|
852 | /*! Production:: math_expression : dimension */
|
---|
853 | case 10:
|
---|
854 | /*! Production:: math_expression : number */
|
---|
855 |
|
---|
856 | this.$ = yyvstack[yysp];
|
---|
857 | break;
|
---|
858 |
|
---|
859 | case 11:
|
---|
860 | /*! Production:: function : FUNCTION */
|
---|
861 |
|
---|
862 | this.$ = { type: 'Function', value: yyvstack[yysp] };
|
---|
863 | break;
|
---|
864 |
|
---|
865 | case 12:
|
---|
866 | /*! Production:: dimension : LENGTH */
|
---|
867 |
|
---|
868 | this.$ = { type: 'LengthValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
|
---|
869 | break;
|
---|
870 |
|
---|
871 | case 13:
|
---|
872 | /*! Production:: dimension : ANGLE */
|
---|
873 |
|
---|
874 | this.$ = { type: 'AngleValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
|
---|
875 | break;
|
---|
876 |
|
---|
877 | case 14:
|
---|
878 | /*! Production:: dimension : TIME */
|
---|
879 |
|
---|
880 | this.$ = { type: 'TimeValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
|
---|
881 | break;
|
---|
882 |
|
---|
883 | case 15:
|
---|
884 | /*! Production:: dimension : FREQ */
|
---|
885 |
|
---|
886 | this.$ = { type: 'FrequencyValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
|
---|
887 | break;
|
---|
888 |
|
---|
889 | case 16:
|
---|
890 | /*! Production:: dimension : RES */
|
---|
891 |
|
---|
892 | this.$ = { type: 'ResolutionValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
|
---|
893 | break;
|
---|
894 |
|
---|
895 | case 17:
|
---|
896 | /*! Production:: dimension : UNKNOWN_DIMENSION */
|
---|
897 |
|
---|
898 | this.$ = { type: 'UnknownDimension', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
|
---|
899 | break;
|
---|
900 |
|
---|
901 | case 18:
|
---|
902 | /*! Production:: dimension : EMS */
|
---|
903 |
|
---|
904 | this.$ = { type: 'EmValue', value: parseFloat(yyvstack[yysp]), unit: 'em' };
|
---|
905 | break;
|
---|
906 |
|
---|
907 | case 19:
|
---|
908 | /*! Production:: dimension : EXS */
|
---|
909 |
|
---|
910 | this.$ = { type: 'ExValue', value: parseFloat(yyvstack[yysp]), unit: 'ex' };
|
---|
911 | break;
|
---|
912 |
|
---|
913 | case 20:
|
---|
914 | /*! Production:: dimension : CHS */
|
---|
915 |
|
---|
916 | this.$ = { type: 'ChValue', value: parseFloat(yyvstack[yysp]), unit: 'ch' };
|
---|
917 | break;
|
---|
918 |
|
---|
919 | case 21:
|
---|
920 | /*! Production:: dimension : REMS */
|
---|
921 |
|
---|
922 | this.$ = { type: 'RemValue', value: parseFloat(yyvstack[yysp]), unit: 'rem' };
|
---|
923 | break;
|
---|
924 |
|
---|
925 | case 22:
|
---|
926 | /*! Production:: dimension : VHS */
|
---|
927 |
|
---|
928 | this.$ = { type: 'VhValue', value: parseFloat(yyvstack[yysp]), unit: 'vh' };
|
---|
929 | break;
|
---|
930 |
|
---|
931 | case 23:
|
---|
932 | /*! Production:: dimension : VWS */
|
---|
933 |
|
---|
934 | this.$ = { type: 'VwValue', value: parseFloat(yyvstack[yysp]), unit: 'vw' };
|
---|
935 | break;
|
---|
936 |
|
---|
937 | case 24:
|
---|
938 | /*! Production:: dimension : VMINS */
|
---|
939 |
|
---|
940 | this.$ = { type: 'VminValue', value: parseFloat(yyvstack[yysp]), unit: 'vmin' };
|
---|
941 | break;
|
---|
942 |
|
---|
943 | case 25:
|
---|
944 | /*! Production:: dimension : VMAXS */
|
---|
945 |
|
---|
946 | this.$ = { type: 'VmaxValue', value: parseFloat(yyvstack[yysp]), unit: 'vmax' };
|
---|
947 | break;
|
---|
948 |
|
---|
949 | case 26:
|
---|
950 | /*! Production:: dimension : PERCENTAGE */
|
---|
951 |
|
---|
952 | this.$ = { type: 'PercentageValue', value: parseFloat(yyvstack[yysp]), unit: '%' };
|
---|
953 | break;
|
---|
954 |
|
---|
955 | case 27:
|
---|
956 | /*! Production:: dimension : ADD dimension */
|
---|
957 |
|
---|
958 | var prev = yyvstack[yysp]; this.$ = prev;
|
---|
959 | break;
|
---|
960 |
|
---|
961 | case 28:
|
---|
962 | /*! Production:: dimension : SUB dimension */
|
---|
963 |
|
---|
964 | var prev = yyvstack[yysp]; prev.value *= -1; this.$ = prev;
|
---|
965 | break;
|
---|
966 |
|
---|
967 | case 29:
|
---|
968 | /*! Production:: number : NUMBER */
|
---|
969 | case 30:
|
---|
970 | /*! Production:: number : ADD NUMBER */
|
---|
971 |
|
---|
972 | this.$ = { type: 'Number', value: parseFloat(yyvstack[yysp]) };
|
---|
973 | break;
|
---|
974 |
|
---|
975 | case 31:
|
---|
976 | /*! Production:: number : SUB NUMBER */
|
---|
977 |
|
---|
978 | this.$ = { type: 'Number', value: parseFloat(yyvstack[yysp]) * -1 };
|
---|
979 | break;
|
---|
980 |
|
---|
981 | }
|
---|
982 | },
|
---|
983 | table: bt({
|
---|
984 | len: u([
|
---|
985 | 26,
|
---|
986 | 1,
|
---|
987 | 5,
|
---|
988 | 1,
|
---|
989 | 25,
|
---|
990 | s,
|
---|
991 | [0, 19],
|
---|
992 | 19,
|
---|
993 | 19,
|
---|
994 | 0,
|
---|
995 | 0,
|
---|
996 | s,
|
---|
997 | [25, 5],
|
---|
998 | 5,
|
---|
999 | 0,
|
---|
1000 | 0,
|
---|
1001 | 18,
|
---|
1002 | 18,
|
---|
1003 | 0,
|
---|
1004 | 0,
|
---|
1005 | 6,
|
---|
1006 | 6,
|
---|
1007 | 0,
|
---|
1008 | 0,
|
---|
1009 | c,
|
---|
1010 | [11, 3]
|
---|
1011 | ]),
|
---|
1012 | symbol: u([
|
---|
1013 | 3,
|
---|
1014 | 4,
|
---|
1015 | 6,
|
---|
1016 | 7,
|
---|
1017 | s,
|
---|
1018 | [10, 22, 1],
|
---|
1019 | 1,
|
---|
1020 | 1,
|
---|
1021 | s,
|
---|
1022 | [6, 4, 1],
|
---|
1023 | 4,
|
---|
1024 | c,
|
---|
1025 | [33, 21],
|
---|
1026 | c,
|
---|
1027 | [32, 4],
|
---|
1028 | 6,
|
---|
1029 | 7,
|
---|
1030 | c,
|
---|
1031 | [22, 16],
|
---|
1032 | 30,
|
---|
1033 | c,
|
---|
1034 | [19, 19],
|
---|
1035 | c,
|
---|
1036 | [63, 25],
|
---|
1037 | c,
|
---|
1038 | [25, 100],
|
---|
1039 | s,
|
---|
1040 | [5, 5, 1],
|
---|
1041 | c,
|
---|
1042 | [149, 17],
|
---|
1043 | c,
|
---|
1044 | [167, 18],
|
---|
1045 | 30,
|
---|
1046 | 1,
|
---|
1047 | c,
|
---|
1048 | [42, 5],
|
---|
1049 | c,
|
---|
1050 | [6, 6],
|
---|
1051 | c,
|
---|
1052 | [5, 5]
|
---|
1053 | ]),
|
---|
1054 | type: u([
|
---|
1055 | s,
|
---|
1056 | [2, 21],
|
---|
1057 | s,
|
---|
1058 | [0, 5],
|
---|
1059 | 1,
|
---|
1060 | s,
|
---|
1061 | [2, 27],
|
---|
1062 | s,
|
---|
1063 | [0, 4],
|
---|
1064 | c,
|
---|
1065 | [22, 19],
|
---|
1066 | c,
|
---|
1067 | [19, 37],
|
---|
1068 | c,
|
---|
1069 | [63, 25],
|
---|
1070 | c,
|
---|
1071 | [25, 103],
|
---|
1072 | c,
|
---|
1073 | [148, 19],
|
---|
1074 | c,
|
---|
1075 | [18, 18]
|
---|
1076 | ]),
|
---|
1077 | state: u([
|
---|
1078 | 1,
|
---|
1079 | 2,
|
---|
1080 | 5,
|
---|
1081 | 6,
|
---|
1082 | 7,
|
---|
1083 | 33,
|
---|
1084 | c,
|
---|
1085 | [4, 3],
|
---|
1086 | 34,
|
---|
1087 | 38,
|
---|
1088 | 40,
|
---|
1089 | c,
|
---|
1090 | [6, 3],
|
---|
1091 | 41,
|
---|
1092 | c,
|
---|
1093 | [4, 3],
|
---|
1094 | 42,
|
---|
1095 | c,
|
---|
1096 | [4, 3],
|
---|
1097 | 43,
|
---|
1098 | c,
|
---|
1099 | [4, 3],
|
---|
1100 | 44,
|
---|
1101 | c,
|
---|
1102 | [22, 5]
|
---|
1103 | ]),
|
---|
1104 | mode: u([
|
---|
1105 | s,
|
---|
1106 | [1, 228],
|
---|
1107 | s,
|
---|
1108 | [2, 4],
|
---|
1109 | c,
|
---|
1110 | [6, 8],
|
---|
1111 | s,
|
---|
1112 | [1, 5]
|
---|
1113 | ]),
|
---|
1114 | goto: u([
|
---|
1115 | 3,
|
---|
1116 | 4,
|
---|
1117 | 24,
|
---|
1118 | 25,
|
---|
1119 | s,
|
---|
1120 | [8, 16, 1],
|
---|
1121 | s,
|
---|
1122 | [26, 7, 1],
|
---|
1123 | c,
|
---|
1124 | [27, 21],
|
---|
1125 | 36,
|
---|
1126 | 37,
|
---|
1127 | c,
|
---|
1128 | [18, 15],
|
---|
1129 | 35,
|
---|
1130 | c,
|
---|
1131 | [18, 17],
|
---|
1132 | 39,
|
---|
1133 | c,
|
---|
1134 | [57, 21],
|
---|
1135 | c,
|
---|
1136 | [21, 84],
|
---|
1137 | 45,
|
---|
1138 | c,
|
---|
1139 | [168, 4],
|
---|
1140 | c,
|
---|
1141 | [128, 17],
|
---|
1142 | c,
|
---|
1143 | [17, 17],
|
---|
1144 | s,
|
---|
1145 | [3, 4],
|
---|
1146 | 30,
|
---|
1147 | 31,
|
---|
1148 | s,
|
---|
1149 | [4, 4],
|
---|
1150 | 30,
|
---|
1151 | 31,
|
---|
1152 | 46,
|
---|
1153 | c,
|
---|
1154 | [51, 4]
|
---|
1155 | ])
|
---|
1156 | }),
|
---|
1157 | defaultActions: bda({
|
---|
1158 | idx: u([
|
---|
1159 | s,
|
---|
1160 | [5, 19, 1],
|
---|
1161 | 26,
|
---|
1162 | 27,
|
---|
1163 | 34,
|
---|
1164 | 35,
|
---|
1165 | 38,
|
---|
1166 | 39,
|
---|
1167 | 42,
|
---|
1168 | 43,
|
---|
1169 | 45,
|
---|
1170 | 46
|
---|
1171 | ]),
|
---|
1172 | goto: u([
|
---|
1173 | s,
|
---|
1174 | [8, 19, 1],
|
---|
1175 | 29,
|
---|
1176 | 1,
|
---|
1177 | 27,
|
---|
1178 | 30,
|
---|
1179 | 28,
|
---|
1180 | 31,
|
---|
1181 | 5,
|
---|
1182 | 6,
|
---|
1183 | 7,
|
---|
1184 | 2
|
---|
1185 | ])
|
---|
1186 | }),
|
---|
1187 | parseError: function parseError(str, hash, ExceptionClass) {
|
---|
1188 | if (hash.recoverable) {
|
---|
1189 | if (typeof this.trace === 'function') {
|
---|
1190 | this.trace(str);
|
---|
1191 | }
|
---|
1192 | hash.destroy(); // destroy... well, *almost*!
|
---|
1193 | } else {
|
---|
1194 | if (typeof this.trace === 'function') {
|
---|
1195 | this.trace(str);
|
---|
1196 | }
|
---|
1197 | if (!ExceptionClass) {
|
---|
1198 | ExceptionClass = this.JisonParserError;
|
---|
1199 | }
|
---|
1200 | throw new ExceptionClass(str, hash);
|
---|
1201 | }
|
---|
1202 | },
|
---|
1203 | parse: function parse(input) {
|
---|
1204 | var self = this;
|
---|
1205 | var stack = new Array(128); // token stack: stores token which leads to state at the same index (column storage)
|
---|
1206 | var sstack = new Array(128); // state stack: stores states (column storage)
|
---|
1207 |
|
---|
1208 | var vstack = new Array(128); // semantic value stack
|
---|
1209 |
|
---|
1210 | var table = this.table;
|
---|
1211 | var sp = 0; // 'stack pointer': index into the stacks
|
---|
1212 |
|
---|
1213 |
|
---|
1214 |
|
---|
1215 |
|
---|
1216 |
|
---|
1217 | var symbol = 0;
|
---|
1218 |
|
---|
1219 |
|
---|
1220 |
|
---|
1221 | var TERROR = this.TERROR;
|
---|
1222 | var EOF = this.EOF;
|
---|
1223 | var ERROR_RECOVERY_TOKEN_DISCARD_COUNT = (this.options.errorRecoveryTokenDiscardCount | 0) || 3;
|
---|
1224 | var NO_ACTION = [0, 47 /* === table.length :: ensures that anyone using this new state will fail dramatically! */];
|
---|
1225 |
|
---|
1226 | var lexer;
|
---|
1227 | if (this.__lexer__) {
|
---|
1228 | lexer = this.__lexer__;
|
---|
1229 | } else {
|
---|
1230 | lexer = this.__lexer__ = Object.create(this.lexer);
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 | var sharedState_yy = {
|
---|
1234 | parseError: undefined,
|
---|
1235 | quoteName: undefined,
|
---|
1236 | lexer: undefined,
|
---|
1237 | parser: undefined,
|
---|
1238 | pre_parse: undefined,
|
---|
1239 | post_parse: undefined,
|
---|
1240 | pre_lex: undefined,
|
---|
1241 | post_lex: undefined // WARNING: must be written this way for the code expanders to work correctly in both ES5 and ES6 modes!
|
---|
1242 | };
|
---|
1243 |
|
---|
1244 | var ASSERT;
|
---|
1245 | if (typeof assert !== 'function') {
|
---|
1246 | ASSERT = function JisonAssert(cond, msg) {
|
---|
1247 | if (!cond) {
|
---|
1248 | throw new Error('assertion failed: ' + (msg || '***'));
|
---|
1249 | }
|
---|
1250 | };
|
---|
1251 | } else {
|
---|
1252 | ASSERT = assert;
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | this.yyGetSharedState = function yyGetSharedState() {
|
---|
1256 | return sharedState_yy;
|
---|
1257 | };
|
---|
1258 |
|
---|
1259 |
|
---|
1260 |
|
---|
1261 |
|
---|
1262 |
|
---|
1263 |
|
---|
1264 |
|
---|
1265 |
|
---|
1266 | function shallow_copy_noclobber(dst, src) {
|
---|
1267 | for (var k in src) {
|
---|
1268 | if (typeof dst[k] === 'undefined' && Object.prototype.hasOwnProperty.call(src, k)) {
|
---|
1269 | dst[k] = src[k];
|
---|
1270 | }
|
---|
1271 | }
|
---|
1272 | }
|
---|
1273 |
|
---|
1274 | // copy state
|
---|
1275 | shallow_copy_noclobber(sharedState_yy, this.yy);
|
---|
1276 |
|
---|
1277 | sharedState_yy.lexer = lexer;
|
---|
1278 | sharedState_yy.parser = this;
|
---|
1279 |
|
---|
1280 |
|
---|
1281 |
|
---|
1282 |
|
---|
1283 |
|
---|
1284 |
|
---|
1285 | // Does the shared state override the default `parseError` that already comes with this instance?
|
---|
1286 | if (typeof sharedState_yy.parseError === 'function') {
|
---|
1287 | this.parseError = function parseErrorAlt(str, hash, ExceptionClass) {
|
---|
1288 | if (!ExceptionClass) {
|
---|
1289 | ExceptionClass = this.JisonParserError;
|
---|
1290 | }
|
---|
1291 | return sharedState_yy.parseError.call(this, str, hash, ExceptionClass);
|
---|
1292 | };
|
---|
1293 | } else {
|
---|
1294 | this.parseError = this.originalParseError;
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | // Does the shared state override the default `quoteName` that already comes with this instance?
|
---|
1298 | if (typeof sharedState_yy.quoteName === 'function') {
|
---|
1299 | this.quoteName = function quoteNameAlt(id_str) {
|
---|
1300 | return sharedState_yy.quoteName.call(this, id_str);
|
---|
1301 | };
|
---|
1302 | } else {
|
---|
1303 | this.quoteName = this.originalQuoteName;
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | // set up the cleanup function; make it an API so that external code can re-use this one in case of
|
---|
1307 | // calamities or when the `%options no-try-catch` option has been specified for the grammar, in which
|
---|
1308 | // case this parse() API method doesn't come with a `finally { ... }` block any more!
|
---|
1309 | //
|
---|
1310 | // NOTE: as this API uses parse() as a closure, it MUST be set again on every parse() invocation,
|
---|
1311 | // or else your `sharedState`, etc. references will be *wrong*!
|
---|
1312 | this.cleanupAfterParse = function parser_cleanupAfterParse(resultValue, invoke_post_methods, do_not_nuke_errorinfos) {
|
---|
1313 | var rv;
|
---|
1314 |
|
---|
1315 | if (invoke_post_methods) {
|
---|
1316 | var hash;
|
---|
1317 |
|
---|
1318 | if (sharedState_yy.post_parse || this.post_parse) {
|
---|
1319 | // create an error hash info instance: we re-use this API in a **non-error situation**
|
---|
1320 | // as this one delivers all parser internals ready for access by userland code.
|
---|
1321 | hash = this.constructParseErrorInfo(null /* no error! */, null /* no exception! */, null, false);
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | if (sharedState_yy.post_parse) {
|
---|
1325 | rv = sharedState_yy.post_parse.call(this, sharedState_yy, resultValue, hash);
|
---|
1326 | if (typeof rv !== 'undefined') resultValue = rv;
|
---|
1327 | }
|
---|
1328 | if (this.post_parse) {
|
---|
1329 | rv = this.post_parse.call(this, sharedState_yy, resultValue, hash);
|
---|
1330 | if (typeof rv !== 'undefined') resultValue = rv;
|
---|
1331 | }
|
---|
1332 |
|
---|
1333 | // cleanup:
|
---|
1334 | if (hash && hash.destroy) {
|
---|
1335 | hash.destroy();
|
---|
1336 | }
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | if (this.__reentrant_call_depth > 1) return resultValue; // do not (yet) kill the sharedState when this is a reentrant run.
|
---|
1340 |
|
---|
1341 | // clean up the lingering lexer structures as well:
|
---|
1342 | if (lexer.cleanupAfterLex) {
|
---|
1343 | lexer.cleanupAfterLex(do_not_nuke_errorinfos);
|
---|
1344 | }
|
---|
1345 |
|
---|
1346 | // prevent lingering circular references from causing memory leaks:
|
---|
1347 | if (sharedState_yy) {
|
---|
1348 | sharedState_yy.lexer = undefined;
|
---|
1349 | sharedState_yy.parser = undefined;
|
---|
1350 | if (lexer.yy === sharedState_yy) {
|
---|
1351 | lexer.yy = undefined;
|
---|
1352 | }
|
---|
1353 | }
|
---|
1354 | sharedState_yy = undefined;
|
---|
1355 | this.parseError = this.originalParseError;
|
---|
1356 | this.quoteName = this.originalQuoteName;
|
---|
1357 |
|
---|
1358 | // nuke the vstack[] array at least as that one will still reference obsoleted user values.
|
---|
1359 | // To be safe, we nuke the other internal stack columns as well...
|
---|
1360 | stack.length = 0; // fastest way to nuke an array without overly bothering the GC
|
---|
1361 | sstack.length = 0;
|
---|
1362 |
|
---|
1363 | vstack.length = 0;
|
---|
1364 | sp = 0;
|
---|
1365 |
|
---|
1366 | // nuke the error hash info instances created during this run.
|
---|
1367 | // Userland code must COPY any data/references
|
---|
1368 | // in the error hash instance(s) it is more permanently interested in.
|
---|
1369 | if (!do_not_nuke_errorinfos) {
|
---|
1370 | for (var i = this.__error_infos.length - 1; i >= 0; i--) {
|
---|
1371 | var el = this.__error_infos[i];
|
---|
1372 | if (el && typeof el.destroy === 'function') {
|
---|
1373 | el.destroy();
|
---|
1374 | }
|
---|
1375 | }
|
---|
1376 | this.__error_infos.length = 0;
|
---|
1377 |
|
---|
1378 |
|
---|
1379 | }
|
---|
1380 |
|
---|
1381 | return resultValue;
|
---|
1382 | };
|
---|
1383 |
|
---|
1384 |
|
---|
1385 |
|
---|
1386 |
|
---|
1387 |
|
---|
1388 |
|
---|
1389 |
|
---|
1390 |
|
---|
1391 |
|
---|
1392 |
|
---|
1393 |
|
---|
1394 |
|
---|
1395 |
|
---|
1396 |
|
---|
1397 |
|
---|
1398 |
|
---|
1399 |
|
---|
1400 |
|
---|
1401 |
|
---|
1402 |
|
---|
1403 |
|
---|
1404 |
|
---|
1405 |
|
---|
1406 |
|
---|
1407 |
|
---|
1408 |
|
---|
1409 |
|
---|
1410 |
|
---|
1411 |
|
---|
1412 |
|
---|
1413 |
|
---|
1414 |
|
---|
1415 |
|
---|
1416 |
|
---|
1417 |
|
---|
1418 |
|
---|
1419 |
|
---|
1420 |
|
---|
1421 |
|
---|
1422 |
|
---|
1423 |
|
---|
1424 |
|
---|
1425 |
|
---|
1426 |
|
---|
1427 |
|
---|
1428 |
|
---|
1429 |
|
---|
1430 |
|
---|
1431 |
|
---|
1432 |
|
---|
1433 |
|
---|
1434 |
|
---|
1435 |
|
---|
1436 |
|
---|
1437 |
|
---|
1438 |
|
---|
1439 |
|
---|
1440 |
|
---|
1441 |
|
---|
1442 |
|
---|
1443 |
|
---|
1444 |
|
---|
1445 |
|
---|
1446 |
|
---|
1447 |
|
---|
1448 |
|
---|
1449 |
|
---|
1450 |
|
---|
1451 |
|
---|
1452 |
|
---|
1453 |
|
---|
1454 |
|
---|
1455 |
|
---|
1456 |
|
---|
1457 |
|
---|
1458 |
|
---|
1459 |
|
---|
1460 |
|
---|
1461 |
|
---|
1462 |
|
---|
1463 |
|
---|
1464 |
|
---|
1465 |
|
---|
1466 |
|
---|
1467 |
|
---|
1468 |
|
---|
1469 |
|
---|
1470 |
|
---|
1471 |
|
---|
1472 |
|
---|
1473 |
|
---|
1474 |
|
---|
1475 |
|
---|
1476 |
|
---|
1477 |
|
---|
1478 |
|
---|
1479 |
|
---|
1480 |
|
---|
1481 |
|
---|
1482 |
|
---|
1483 |
|
---|
1484 |
|
---|
1485 |
|
---|
1486 |
|
---|
1487 |
|
---|
1488 |
|
---|
1489 |
|
---|
1490 |
|
---|
1491 |
|
---|
1492 |
|
---|
1493 |
|
---|
1494 |
|
---|
1495 |
|
---|
1496 |
|
---|
1497 |
|
---|
1498 |
|
---|
1499 |
|
---|
1500 |
|
---|
1501 |
|
---|
1502 |
|
---|
1503 |
|
---|
1504 |
|
---|
1505 |
|
---|
1506 |
|
---|
1507 |
|
---|
1508 |
|
---|
1509 |
|
---|
1510 |
|
---|
1511 |
|
---|
1512 |
|
---|
1513 |
|
---|
1514 |
|
---|
1515 |
|
---|
1516 |
|
---|
1517 | // NOTE: as this API uses parse() as a closure, it MUST be set again on every parse() invocation,
|
---|
1518 | // or else your `lexer`, `sharedState`, etc. references will be *wrong*!
|
---|
1519 | this.constructParseErrorInfo = function parser_constructParseErrorInfo(msg, ex, expected, recoverable) {
|
---|
1520 | var pei = {
|
---|
1521 | errStr: msg,
|
---|
1522 | exception: ex,
|
---|
1523 | text: lexer.match,
|
---|
1524 | value: lexer.yytext,
|
---|
1525 | token: this.describeSymbol(symbol) || symbol,
|
---|
1526 | token_id: symbol,
|
---|
1527 | line: lexer.yylineno,
|
---|
1528 |
|
---|
1529 | expected: expected,
|
---|
1530 | recoverable: recoverable,
|
---|
1531 | state: state,
|
---|
1532 | action: action,
|
---|
1533 | new_state: newState,
|
---|
1534 | symbol_stack: stack,
|
---|
1535 | state_stack: sstack,
|
---|
1536 | value_stack: vstack,
|
---|
1537 |
|
---|
1538 | stack_pointer: sp,
|
---|
1539 | yy: sharedState_yy,
|
---|
1540 | lexer: lexer,
|
---|
1541 | parser: this,
|
---|
1542 |
|
---|
1543 | // and make sure the error info doesn't stay due to potential
|
---|
1544 | // ref cycle via userland code manipulations.
|
---|
1545 | // These would otherwise all be memory leak opportunities!
|
---|
1546 | //
|
---|
1547 | // Note that only array and object references are nuked as those
|
---|
1548 | // constitute the set of elements which can produce a cyclic ref.
|
---|
1549 | // The rest of the members is kept intact as they are harmless.
|
---|
1550 | destroy: function destructParseErrorInfo() {
|
---|
1551 | // remove cyclic references added to error info:
|
---|
1552 | // info.yy = null;
|
---|
1553 | // info.lexer = null;
|
---|
1554 | // info.value = null;
|
---|
1555 | // info.value_stack = null;
|
---|
1556 | // ...
|
---|
1557 | var rec = !!this.recoverable;
|
---|
1558 | for (var key in this) {
|
---|
1559 | if (this.hasOwnProperty(key) && typeof key === 'object') {
|
---|
1560 | this[key] = undefined;
|
---|
1561 | }
|
---|
1562 | }
|
---|
1563 | this.recoverable = rec;
|
---|
1564 | }
|
---|
1565 | };
|
---|
1566 | // track this instance so we can `destroy()` it once we deem it superfluous and ready for garbage collection!
|
---|
1567 | this.__error_infos.push(pei);
|
---|
1568 | return pei;
|
---|
1569 | };
|
---|
1570 |
|
---|
1571 |
|
---|
1572 |
|
---|
1573 |
|
---|
1574 |
|
---|
1575 |
|
---|
1576 |
|
---|
1577 |
|
---|
1578 |
|
---|
1579 |
|
---|
1580 |
|
---|
1581 |
|
---|
1582 |
|
---|
1583 | function getNonTerminalFromCode(symbol) {
|
---|
1584 | var tokenName = self.getSymbolName(symbol);
|
---|
1585 | if (!tokenName) {
|
---|
1586 | tokenName = symbol;
|
---|
1587 | }
|
---|
1588 | return tokenName;
|
---|
1589 | }
|
---|
1590 |
|
---|
1591 |
|
---|
1592 | function stdLex() {
|
---|
1593 | var token = lexer.lex();
|
---|
1594 | // if token isn't its numeric value, convert
|
---|
1595 | if (typeof token !== 'number') {
|
---|
1596 | token = self.symbols_[token] || token;
|
---|
1597 | }
|
---|
1598 |
|
---|
1599 | return token || EOF;
|
---|
1600 | }
|
---|
1601 |
|
---|
1602 | function fastLex() {
|
---|
1603 | var token = lexer.fastLex();
|
---|
1604 | // if token isn't its numeric value, convert
|
---|
1605 | if (typeof token !== 'number') {
|
---|
1606 | token = self.symbols_[token] || token;
|
---|
1607 | }
|
---|
1608 |
|
---|
1609 | return token || EOF;
|
---|
1610 | }
|
---|
1611 |
|
---|
1612 | var lex = stdLex;
|
---|
1613 |
|
---|
1614 |
|
---|
1615 | var state, action, r, t;
|
---|
1616 | var yyval = {
|
---|
1617 | $: true,
|
---|
1618 | _$: undefined,
|
---|
1619 | yy: sharedState_yy
|
---|
1620 | };
|
---|
1621 | var p;
|
---|
1622 | var yyrulelen;
|
---|
1623 | var this_production;
|
---|
1624 | var newState;
|
---|
1625 | var retval = false;
|
---|
1626 |
|
---|
1627 |
|
---|
1628 | try {
|
---|
1629 | this.__reentrant_call_depth++;
|
---|
1630 |
|
---|
1631 | lexer.setInput(input, sharedState_yy);
|
---|
1632 |
|
---|
1633 | // NOTE: we *assume* no lexer pre/post handlers are set up *after*
|
---|
1634 | // this initial `setInput()` call: hence we can now check and decide
|
---|
1635 | // whether we'll go with the standard, slower, lex() API or the
|
---|
1636 | // `fast_lex()` one:
|
---|
1637 | if (typeof lexer.canIUse === 'function') {
|
---|
1638 | var lexerInfo = lexer.canIUse();
|
---|
1639 | if (lexerInfo.fastLex && typeof fastLex === 'function') {
|
---|
1640 | lex = fastLex;
|
---|
1641 | }
|
---|
1642 | }
|
---|
1643 |
|
---|
1644 |
|
---|
1645 |
|
---|
1646 | vstack[sp] = null;
|
---|
1647 | sstack[sp] = 0;
|
---|
1648 | stack[sp] = 0;
|
---|
1649 | ++sp;
|
---|
1650 |
|
---|
1651 |
|
---|
1652 |
|
---|
1653 |
|
---|
1654 |
|
---|
1655 | if (this.pre_parse) {
|
---|
1656 | this.pre_parse.call(this, sharedState_yy);
|
---|
1657 | }
|
---|
1658 | if (sharedState_yy.pre_parse) {
|
---|
1659 | sharedState_yy.pre_parse.call(this, sharedState_yy);
|
---|
1660 | }
|
---|
1661 |
|
---|
1662 | newState = sstack[sp - 1];
|
---|
1663 | for (;;) {
|
---|
1664 | // retrieve state number from top of stack
|
---|
1665 | state = newState; // sstack[sp - 1];
|
---|
1666 |
|
---|
1667 | // use default actions if available
|
---|
1668 | if (this.defaultActions[state]) {
|
---|
1669 | action = 2;
|
---|
1670 | newState = this.defaultActions[state];
|
---|
1671 | } else {
|
---|
1672 | // The single `==` condition below covers both these `===` comparisons in a single
|
---|
1673 | // operation:
|
---|
1674 | //
|
---|
1675 | // if (symbol === null || typeof symbol === 'undefined') ...
|
---|
1676 | if (!symbol) {
|
---|
1677 | symbol = lex();
|
---|
1678 | }
|
---|
1679 | // read action for current state and first input
|
---|
1680 | t = (table[state] && table[state][symbol]) || NO_ACTION;
|
---|
1681 | newState = t[1];
|
---|
1682 | action = t[0];
|
---|
1683 |
|
---|
1684 |
|
---|
1685 |
|
---|
1686 |
|
---|
1687 |
|
---|
1688 |
|
---|
1689 |
|
---|
1690 |
|
---|
1691 |
|
---|
1692 |
|
---|
1693 |
|
---|
1694 | // handle parse error
|
---|
1695 | if (!action) {
|
---|
1696 | var errStr;
|
---|
1697 | var errSymbolDescr = (this.describeSymbol(symbol) || symbol);
|
---|
1698 | var expected = this.collect_expected_token_set(state);
|
---|
1699 |
|
---|
1700 | // Report error
|
---|
1701 | if (typeof lexer.yylineno === 'number') {
|
---|
1702 | errStr = 'Parse error on line ' + (lexer.yylineno + 1) + ': ';
|
---|
1703 | } else {
|
---|
1704 | errStr = 'Parse error: ';
|
---|
1705 | }
|
---|
1706 | if (typeof lexer.showPosition === 'function') {
|
---|
1707 | errStr += '\n' + lexer.showPosition(79 - 10, 10) + '\n';
|
---|
1708 | }
|
---|
1709 | if (expected.length) {
|
---|
1710 | errStr += 'Expecting ' + expected.join(', ') + ', got unexpected ' + errSymbolDescr;
|
---|
1711 | } else {
|
---|
1712 | errStr += 'Unexpected ' + errSymbolDescr;
|
---|
1713 | }
|
---|
1714 | // we cannot recover from the error!
|
---|
1715 | p = this.constructParseErrorInfo(errStr, null, expected, false);
|
---|
1716 | r = this.parseError(p.errStr, p, this.JisonParserError);
|
---|
1717 | if (typeof r !== 'undefined') {
|
---|
1718 | retval = r;
|
---|
1719 | }
|
---|
1720 | break;
|
---|
1721 | }
|
---|
1722 |
|
---|
1723 |
|
---|
1724 | }
|
---|
1725 |
|
---|
1726 |
|
---|
1727 |
|
---|
1728 |
|
---|
1729 |
|
---|
1730 |
|
---|
1731 |
|
---|
1732 |
|
---|
1733 |
|
---|
1734 |
|
---|
1735 | switch (action) {
|
---|
1736 | // catch misc. parse failures:
|
---|
1737 | default:
|
---|
1738 | // this shouldn't happen, unless resolve defaults are off
|
---|
1739 | if (action instanceof Array) {
|
---|
1740 | p = this.constructParseErrorInfo('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol, null, null, false);
|
---|
1741 | r = this.parseError(p.errStr, p, this.JisonParserError);
|
---|
1742 | if (typeof r !== 'undefined') {
|
---|
1743 | retval = r;
|
---|
1744 | }
|
---|
1745 | break;
|
---|
1746 | }
|
---|
1747 | // Another case of better safe than sorry: in case state transitions come out of another error recovery process
|
---|
1748 | // or a buggy LUT (LookUp Table):
|
---|
1749 | p = this.constructParseErrorInfo('Parsing halted. No viable error recovery approach available due to internal system failure.', null, null, false);
|
---|
1750 | r = this.parseError(p.errStr, p, this.JisonParserError);
|
---|
1751 | if (typeof r !== 'undefined') {
|
---|
1752 | retval = r;
|
---|
1753 | }
|
---|
1754 | break;
|
---|
1755 |
|
---|
1756 | // shift:
|
---|
1757 | case 1:
|
---|
1758 | stack[sp] = symbol;
|
---|
1759 | vstack[sp] = lexer.yytext;
|
---|
1760 |
|
---|
1761 | sstack[sp] = newState; // push state
|
---|
1762 |
|
---|
1763 | ++sp;
|
---|
1764 | symbol = 0;
|
---|
1765 |
|
---|
1766 |
|
---|
1767 |
|
---|
1768 |
|
---|
1769 | // Pick up the lexer details for the current symbol as that one is not 'look-ahead' any more:
|
---|
1770 |
|
---|
1771 |
|
---|
1772 |
|
---|
1773 |
|
---|
1774 | continue;
|
---|
1775 |
|
---|
1776 | // reduce:
|
---|
1777 | case 2:
|
---|
1778 |
|
---|
1779 |
|
---|
1780 |
|
---|
1781 | this_production = this.productions_[newState - 1]; // `this.productions_[]` is zero-based indexed while states start from 1 upwards...
|
---|
1782 | yyrulelen = this_production[1];
|
---|
1783 |
|
---|
1784 |
|
---|
1785 |
|
---|
1786 |
|
---|
1787 |
|
---|
1788 |
|
---|
1789 |
|
---|
1790 |
|
---|
1791 |
|
---|
1792 |
|
---|
1793 | r = this.performAction.call(yyval, newState, sp - 1, vstack);
|
---|
1794 |
|
---|
1795 | if (typeof r !== 'undefined') {
|
---|
1796 | retval = r;
|
---|
1797 | break;
|
---|
1798 | }
|
---|
1799 |
|
---|
1800 | // pop off stack
|
---|
1801 | sp -= yyrulelen;
|
---|
1802 |
|
---|
1803 | // don't overwrite the `symbol` variable: use a local var to speed things up:
|
---|
1804 | var ntsymbol = this_production[0]; // push nonterminal (reduce)
|
---|
1805 | stack[sp] = ntsymbol;
|
---|
1806 | vstack[sp] = yyval.$;
|
---|
1807 |
|
---|
1808 | // goto new state = table[STATE][NONTERMINAL]
|
---|
1809 | newState = table[sstack[sp - 1]][ntsymbol];
|
---|
1810 | sstack[sp] = newState;
|
---|
1811 | ++sp;
|
---|
1812 |
|
---|
1813 |
|
---|
1814 |
|
---|
1815 |
|
---|
1816 |
|
---|
1817 |
|
---|
1818 |
|
---|
1819 |
|
---|
1820 |
|
---|
1821 | continue;
|
---|
1822 |
|
---|
1823 | // accept:
|
---|
1824 | case 3:
|
---|
1825 | if (sp !== -2) {
|
---|
1826 | retval = true;
|
---|
1827 | // Return the `$accept` rule's `$$` result, if available.
|
---|
1828 | //
|
---|
1829 | // Also note that JISON always adds this top-most `$accept` rule (with implicit,
|
---|
1830 | // default, action):
|
---|
1831 | //
|
---|
1832 | // $accept: <startSymbol> $end
|
---|
1833 | // %{ $$ = $1; @$ = @1; %}
|
---|
1834 | //
|
---|
1835 | // which, combined with the parse kernel's `$accept` state behaviour coded below,
|
---|
1836 | // will produce the `$$` value output of the <startSymbol> rule as the parse result,
|
---|
1837 | // IFF that result is *not* `undefined`. (See also the parser kernel code.)
|
---|
1838 | //
|
---|
1839 | // In code:
|
---|
1840 | //
|
---|
1841 | // %{
|
---|
1842 | // @$ = @1; // if location tracking support is included
|
---|
1843 | // if (typeof $1 !== 'undefined')
|
---|
1844 | // return $1;
|
---|
1845 | // else
|
---|
1846 | // return true; // the default parse result if the rule actions don't produce anything
|
---|
1847 | // %}
|
---|
1848 | sp--;
|
---|
1849 | if (typeof vstack[sp] !== 'undefined') {
|
---|
1850 | retval = vstack[sp];
|
---|
1851 | }
|
---|
1852 | }
|
---|
1853 | break;
|
---|
1854 | }
|
---|
1855 |
|
---|
1856 | // break out of loop: we accept or fail with error
|
---|
1857 | break;
|
---|
1858 | }
|
---|
1859 | } catch (ex) {
|
---|
1860 | // report exceptions through the parseError callback too, but keep the exception intact
|
---|
1861 | // if it is a known parser or lexer error which has been thrown by parseError() already:
|
---|
1862 | if (ex instanceof this.JisonParserError) {
|
---|
1863 | throw ex;
|
---|
1864 | }
|
---|
1865 | else if (lexer && typeof lexer.JisonLexerError === 'function' && ex instanceof lexer.JisonLexerError) {
|
---|
1866 | throw ex;
|
---|
1867 | }
|
---|
1868 |
|
---|
1869 | p = this.constructParseErrorInfo('Parsing aborted due to exception.', ex, null, false);
|
---|
1870 | retval = false;
|
---|
1871 | r = this.parseError(p.errStr, p, this.JisonParserError);
|
---|
1872 | if (typeof r !== 'undefined') {
|
---|
1873 | retval = r;
|
---|
1874 | }
|
---|
1875 | } finally {
|
---|
1876 | retval = this.cleanupAfterParse(retval, true, true);
|
---|
1877 | this.__reentrant_call_depth--;
|
---|
1878 | } // /finally
|
---|
1879 |
|
---|
1880 | return retval;
|
---|
1881 | }
|
---|
1882 | };
|
---|
1883 | parser.originalParseError = parser.parseError;
|
---|
1884 | parser.originalQuoteName = parser.quoteName;
|
---|
1885 | /* lexer generated by jison-lex 0.6.1-215 */
|
---|
1886 |
|
---|
1887 | /*
|
---|
1888 | * Returns a Lexer object of the following structure:
|
---|
1889 | *
|
---|
1890 | * Lexer: {
|
---|
1891 | * yy: {} The so-called "shared state" or rather the *source* of it;
|
---|
1892 | * the real "shared state" `yy` passed around to
|
---|
1893 | * the rule actions, etc. is a direct reference!
|
---|
1894 | *
|
---|
1895 | * This "shared context" object was passed to the lexer by way of
|
---|
1896 | * the `lexer.setInput(str, yy)` API before you may use it.
|
---|
1897 | *
|
---|
1898 | * This "shared context" object is passed to the lexer action code in `performAction()`
|
---|
1899 | * so userland code in the lexer actions may communicate with the outside world
|
---|
1900 | * and/or other lexer rules' actions in more or less complex ways.
|
---|
1901 | *
|
---|
1902 | * }
|
---|
1903 | *
|
---|
1904 | * Lexer.prototype: {
|
---|
1905 | * EOF: 1,
|
---|
1906 | * ERROR: 2,
|
---|
1907 | *
|
---|
1908 | * yy: The overall "shared context" object reference.
|
---|
1909 | *
|
---|
1910 | * JisonLexerError: function(msg, hash),
|
---|
1911 | *
|
---|
1912 | * performAction: function lexer__performAction(yy, yyrulenumber, YY_START),
|
---|
1913 | *
|
---|
1914 | * The function parameters and `this` have the following value/meaning:
|
---|
1915 | * - `this` : reference to the `lexer` instance.
|
---|
1916 | * `yy_` is an alias for `this` lexer instance reference used internally.
|
---|
1917 | *
|
---|
1918 | * - `yy` : a reference to the `yy` "shared state" object which was passed to the lexer
|
---|
1919 | * by way of the `lexer.setInput(str, yy)` API before.
|
---|
1920 | *
|
---|
1921 | * Note:
|
---|
1922 | * The extra arguments you specified in the `%parse-param` statement in your
|
---|
1923 | * **parser** grammar definition file are passed to the lexer via this object
|
---|
1924 | * reference as member variables.
|
---|
1925 | *
|
---|
1926 | * - `yyrulenumber` : index of the matched lexer rule (regex), used internally.
|
---|
1927 | *
|
---|
1928 | * - `YY_START`: the current lexer "start condition" state.
|
---|
1929 | *
|
---|
1930 | * parseError: function(str, hash, ExceptionClass),
|
---|
1931 | *
|
---|
1932 | * constructLexErrorInfo: function(error_message, is_recoverable),
|
---|
1933 | * Helper function.
|
---|
1934 | * Produces a new errorInfo 'hash object' which can be passed into `parseError()`.
|
---|
1935 | * See it's use in this lexer kernel in many places; example usage:
|
---|
1936 | *
|
---|
1937 | * var infoObj = lexer.constructParseErrorInfo('fail!', true);
|
---|
1938 | * var retVal = lexer.parseError(infoObj.errStr, infoObj, lexer.JisonLexerError);
|
---|
1939 | *
|
---|
1940 | * options: { ... lexer %options ... },
|
---|
1941 | *
|
---|
1942 | * lex: function(),
|
---|
1943 | * Produce one token of lexed input, which was passed in earlier via the `lexer.setInput()` API.
|
---|
1944 | * You MAY use the additional `args...` parameters as per `%parse-param` spec of the **lexer** grammar:
|
---|
1945 | * these extra `args...` are added verbatim to the `yy` object reference as member variables.
|
---|
1946 | *
|
---|
1947 | * WARNING:
|
---|
1948 | * Lexer's additional `args...` parameters (via lexer's `%parse-param`) MAY conflict with
|
---|
1949 | * any attributes already added to `yy` by the **parser** or the jison run-time;
|
---|
1950 | * when such a collision is detected an exception is thrown to prevent the generated run-time
|
---|
1951 | * from silently accepting this confusing and potentially hazardous situation!
|
---|
1952 | *
|
---|
1953 | * cleanupAfterLex: function(do_not_nuke_errorinfos),
|
---|
1954 | * Helper function.
|
---|
1955 | *
|
---|
1956 | * This helper API is invoked when the **parse process** has completed: it is the responsibility
|
---|
1957 | * of the **parser** (or the calling userland code) to invoke this method once cleanup is desired.
|
---|
1958 | *
|
---|
1959 | * This helper may be invoked by user code to ensure the internal lexer gets properly garbage collected.
|
---|
1960 | *
|
---|
1961 | * setInput: function(input, [yy]),
|
---|
1962 | *
|
---|
1963 | *
|
---|
1964 | * input: function(),
|
---|
1965 | *
|
---|
1966 | *
|
---|
1967 | * unput: function(str),
|
---|
1968 | *
|
---|
1969 | *
|
---|
1970 | * more: function(),
|
---|
1971 | *
|
---|
1972 | *
|
---|
1973 | * reject: function(),
|
---|
1974 | *
|
---|
1975 | *
|
---|
1976 | * less: function(n),
|
---|
1977 | *
|
---|
1978 | *
|
---|
1979 | * pastInput: function(n),
|
---|
1980 | *
|
---|
1981 | *
|
---|
1982 | * upcomingInput: function(n),
|
---|
1983 | *
|
---|
1984 | *
|
---|
1985 | * showPosition: function(),
|
---|
1986 | *
|
---|
1987 | *
|
---|
1988 | * test_match: function(regex_match_array, rule_index),
|
---|
1989 | *
|
---|
1990 | *
|
---|
1991 | * next: function(),
|
---|
1992 | *
|
---|
1993 | *
|
---|
1994 | * begin: function(condition),
|
---|
1995 | *
|
---|
1996 | *
|
---|
1997 | * pushState: function(condition),
|
---|
1998 | *
|
---|
1999 | *
|
---|
2000 | * popState: function(),
|
---|
2001 | *
|
---|
2002 | *
|
---|
2003 | * topState: function(),
|
---|
2004 | *
|
---|
2005 | *
|
---|
2006 | * _currentRules: function(),
|
---|
2007 | *
|
---|
2008 | *
|
---|
2009 | * stateStackSize: function(),
|
---|
2010 | *
|
---|
2011 | *
|
---|
2012 | * performAction: function(yy, yy_, yyrulenumber, YY_START),
|
---|
2013 | *
|
---|
2014 | *
|
---|
2015 | * rules: [...],
|
---|
2016 | *
|
---|
2017 | *
|
---|
2018 | * conditions: {associative list: name ==> set},
|
---|
2019 | * }
|
---|
2020 | *
|
---|
2021 | *
|
---|
2022 | * token location info (`yylloc`): {
|
---|
2023 | * first_line: n,
|
---|
2024 | * last_line: n,
|
---|
2025 | * first_column: n,
|
---|
2026 | * last_column: n,
|
---|
2027 | * range: [start_number, end_number]
|
---|
2028 | * (where the numbers are indexes into the input string, zero-based)
|
---|
2029 | * }
|
---|
2030 | *
|
---|
2031 | * ---
|
---|
2032 | *
|
---|
2033 | * The `parseError` function receives a 'hash' object with these members for lexer errors:
|
---|
2034 | *
|
---|
2035 | * {
|
---|
2036 | * text: (matched text)
|
---|
2037 | * token: (the produced terminal token, if any)
|
---|
2038 | * token_id: (the produced terminal token numeric ID, if any)
|
---|
2039 | * line: (yylineno)
|
---|
2040 | * loc: (yylloc)
|
---|
2041 | * recoverable: (boolean: TRUE when the parser MAY have an error recovery rule
|
---|
2042 | * available for this particular error)
|
---|
2043 | * yy: (object: the current parser internal "shared state" `yy`
|
---|
2044 | * as is also available in the rule actions; this can be used,
|
---|
2045 | * for instance, for advanced error analysis and reporting)
|
---|
2046 | * lexer: (reference to the current lexer instance used by the parser)
|
---|
2047 | * }
|
---|
2048 | *
|
---|
2049 | * while `this` will reference the current lexer instance.
|
---|
2050 | *
|
---|
2051 | * When `parseError` is invoked by the lexer, the default implementation will
|
---|
2052 | * attempt to invoke `yy.parser.parseError()`; when this callback is not provided
|
---|
2053 | * it will try to invoke `yy.parseError()` instead. When that callback is also not
|
---|
2054 | * provided, a `JisonLexerError` exception will be thrown containing the error
|
---|
2055 | * message and `hash`, as constructed by the `constructLexErrorInfo()` API.
|
---|
2056 | *
|
---|
2057 | * Note that the lexer's `JisonLexerError` error class is passed via the
|
---|
2058 | * `ExceptionClass` argument, which is invoked to construct the exception
|
---|
2059 | * instance to be thrown, so technically `parseError` will throw the object
|
---|
2060 | * produced by the `new ExceptionClass(str, hash)` JavaScript expression.
|
---|
2061 | *
|
---|
2062 | * ---
|
---|
2063 | *
|
---|
2064 | * You can specify lexer options by setting / modifying the `.options` object of your Lexer instance.
|
---|
2065 | * These options are available:
|
---|
2066 | *
|
---|
2067 | * (Options are permanent.)
|
---|
2068 | *
|
---|
2069 | * yy: {
|
---|
2070 | * parseError: function(str, hash, ExceptionClass)
|
---|
2071 | * optional: overrides the default `parseError` function.
|
---|
2072 | * }
|
---|
2073 | *
|
---|
2074 | * lexer.options: {
|
---|
2075 | * pre_lex: function()
|
---|
2076 | * optional: is invoked before the lexer is invoked to produce another token.
|
---|
2077 | * `this` refers to the Lexer object.
|
---|
2078 | * post_lex: function(token) { return token; }
|
---|
2079 | * optional: is invoked when the lexer has produced a token `token`;
|
---|
2080 | * this function can override the returned token value by returning another.
|
---|
2081 | * When it does not return any (truthy) value, the lexer will return
|
---|
2082 | * the original `token`.
|
---|
2083 | * `this` refers to the Lexer object.
|
---|
2084 | *
|
---|
2085 | * WARNING: the next set of options are not meant to be changed. They echo the abilities of
|
---|
2086 | * the lexer as per when it was compiled!
|
---|
2087 | *
|
---|
2088 | * ranges: boolean
|
---|
2089 | * optional: `true` ==> token location info will include a .range[] member.
|
---|
2090 | * flex: boolean
|
---|
2091 | * optional: `true` ==> flex-like lexing behaviour where the rules are tested
|
---|
2092 | * exhaustively to find the longest match.
|
---|
2093 | * backtrack_lexer: boolean
|
---|
2094 | * optional: `true` ==> lexer regexes are tested in order and for invoked;
|
---|
2095 | * the lexer terminates the scan when a token is returned by the action code.
|
---|
2096 | * xregexp: boolean
|
---|
2097 | * optional: `true` ==> lexer rule regexes are "extended regex format" requiring the
|
---|
2098 | * `XRegExp` library. When this %option has not been specified at compile time, all lexer
|
---|
2099 | * rule regexes have been written as standard JavaScript RegExp expressions.
|
---|
2100 | * }
|
---|
2101 | */
|
---|
2102 |
|
---|
2103 |
|
---|
2104 | var lexer = function() {
|
---|
2105 | /**
|
---|
2106 | * See also:
|
---|
2107 | * http://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript/#35881508
|
---|
2108 | * but we keep the prototype.constructor and prototype.name assignment lines too for compatibility
|
---|
2109 | * with userland code which might access the derived class in a 'classic' way.
|
---|
2110 | *
|
---|
2111 | * @public
|
---|
2112 | * @constructor
|
---|
2113 | * @nocollapse
|
---|
2114 | */
|
---|
2115 | function JisonLexerError(msg, hash) {
|
---|
2116 | Object.defineProperty(this, 'name', {
|
---|
2117 | enumerable: false,
|
---|
2118 | writable: false,
|
---|
2119 | value: 'JisonLexerError'
|
---|
2120 | });
|
---|
2121 |
|
---|
2122 | if (msg == null)
|
---|
2123 | msg = '???';
|
---|
2124 |
|
---|
2125 | Object.defineProperty(this, 'message', {
|
---|
2126 | enumerable: false,
|
---|
2127 | writable: true,
|
---|
2128 | value: msg
|
---|
2129 | });
|
---|
2130 |
|
---|
2131 | this.hash = hash;
|
---|
2132 | var stacktrace;
|
---|
2133 |
|
---|
2134 | if (hash && hash.exception instanceof Error) {
|
---|
2135 | var ex2 = hash.exception;
|
---|
2136 | this.message = ex2.message || msg;
|
---|
2137 | stacktrace = ex2.stack;
|
---|
2138 | }
|
---|
2139 |
|
---|
2140 | if (!stacktrace) {
|
---|
2141 | if (Error.hasOwnProperty('captureStackTrace')) {
|
---|
2142 | // V8
|
---|
2143 | Error.captureStackTrace(this, this.constructor);
|
---|
2144 | } else {
|
---|
2145 | stacktrace = new Error(msg).stack;
|
---|
2146 | }
|
---|
2147 | }
|
---|
2148 |
|
---|
2149 | if (stacktrace) {
|
---|
2150 | Object.defineProperty(this, 'stack', {
|
---|
2151 | enumerable: false,
|
---|
2152 | writable: false,
|
---|
2153 | value: stacktrace
|
---|
2154 | });
|
---|
2155 | }
|
---|
2156 | }
|
---|
2157 |
|
---|
2158 | if (typeof Object.setPrototypeOf === 'function') {
|
---|
2159 | Object.setPrototypeOf(JisonLexerError.prototype, Error.prototype);
|
---|
2160 | } else {
|
---|
2161 | JisonLexerError.prototype = Object.create(Error.prototype);
|
---|
2162 | }
|
---|
2163 |
|
---|
2164 | JisonLexerError.prototype.constructor = JisonLexerError;
|
---|
2165 | JisonLexerError.prototype.name = 'JisonLexerError';
|
---|
2166 |
|
---|
2167 | var lexer = {
|
---|
2168 |
|
---|
2169 | // Code Generator Information Report
|
---|
2170 | // ---------------------------------
|
---|
2171 | //
|
---|
2172 | // Options:
|
---|
2173 | //
|
---|
2174 | // backtracking: .................... false
|
---|
2175 | // location.ranges: ................. false
|
---|
2176 | // location line+column tracking: ... true
|
---|
2177 | //
|
---|
2178 | //
|
---|
2179 | // Forwarded Parser Analysis flags:
|
---|
2180 | //
|
---|
2181 | // uses yyleng: ..................... false
|
---|
2182 | // uses yylineno: ................... false
|
---|
2183 | // uses yytext: ..................... false
|
---|
2184 | // uses yylloc: ..................... false
|
---|
2185 | // uses lexer values: ............... true / true
|
---|
2186 | // location tracking: ............... false
|
---|
2187 | // location assignment: ............. false
|
---|
2188 | //
|
---|
2189 | //
|
---|
2190 | // Lexer Analysis flags:
|
---|
2191 | //
|
---|
2192 | // uses yyleng: ..................... ???
|
---|
2193 | // uses yylineno: ................... ???
|
---|
2194 | // uses yytext: ..................... ???
|
---|
2195 | // uses yylloc: ..................... ???
|
---|
2196 | // uses ParseError API: ............. ???
|
---|
2197 | // uses yyerror: .................... ???
|
---|
2198 | // uses location tracking & editing: ???
|
---|
2199 | // uses more() API: ................. ???
|
---|
2200 | // uses unput() API: ................ ???
|
---|
2201 | // uses reject() API: ............... ???
|
---|
2202 | // uses less() API: ................. ???
|
---|
2203 | // uses display APIs pastInput(), upcomingInput(), showPosition():
|
---|
2204 | // ............................. ???
|
---|
2205 | // uses describeYYLLOC() API: ....... ???
|
---|
2206 | //
|
---|
2207 | // --------- END OF REPORT -----------
|
---|
2208 |
|
---|
2209 | EOF: 1,
|
---|
2210 | ERROR: 2,
|
---|
2211 |
|
---|
2212 | // JisonLexerError: JisonLexerError, /// <-- injected by the code generator
|
---|
2213 |
|
---|
2214 | // options: {}, /// <-- injected by the code generator
|
---|
2215 |
|
---|
2216 | // yy: ..., /// <-- injected by setInput()
|
---|
2217 |
|
---|
2218 | __currentRuleSet__: null, /// INTERNAL USE ONLY: internal rule set cache for the current lexer state
|
---|
2219 |
|
---|
2220 | __error_infos: [], /// INTERNAL USE ONLY: the set of lexErrorInfo objects created since the last cleanup
|
---|
2221 | __decompressed: false, /// INTERNAL USE ONLY: mark whether the lexer instance has been 'unfolded' completely and is now ready for use
|
---|
2222 | done: false, /// INTERNAL USE ONLY
|
---|
2223 | _backtrack: false, /// INTERNAL USE ONLY
|
---|
2224 | _input: '', /// INTERNAL USE ONLY
|
---|
2225 | _more: false, /// INTERNAL USE ONLY
|
---|
2226 | _signaled_error_token: false, /// INTERNAL USE ONLY
|
---|
2227 | conditionStack: [], /// INTERNAL USE ONLY; managed via `pushState()`, `popState()`, `topState()` and `stateStackSize()`
|
---|
2228 | match: '', /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: tracks input which has been matched so far for the lexer token under construction. `match` is identical to `yytext` except that this one still contains the matched input string after `lexer.performAction()` has been invoked, where userland code MAY have changed/replaced the `yytext` value entirely!
|
---|
2229 | matched: '', /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: tracks entire input which has been matched so far
|
---|
2230 | matches: false, /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: tracks RE match result for last (successful) match attempt
|
---|
2231 | yytext: '', /// ADVANCED USE ONLY: tracks input which has been matched so far for the lexer token under construction; this value is transferred to the parser as the 'token value' when the parser consumes the lexer token produced through a call to the `lex()` API.
|
---|
2232 | offset: 0, /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: tracks the 'cursor position' in the input string, i.e. the number of characters matched so far
|
---|
2233 | yyleng: 0, /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: length of matched input for the token under construction (`yytext`)
|
---|
2234 | yylineno: 0, /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: 'line number' at which the token under construction is located
|
---|
2235 | yylloc: null, /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: tracks location info (lines + columns) for the token under construction
|
---|
2236 |
|
---|
2237 | /**
|
---|
2238 | * INTERNAL USE: construct a suitable error info hash object instance for `parseError`.
|
---|
2239 | *
|
---|
2240 | * @public
|
---|
2241 | * @this {RegExpLexer}
|
---|
2242 | */
|
---|
2243 | constructLexErrorInfo: function lexer_constructLexErrorInfo(msg, recoverable, show_input_position) {
|
---|
2244 | msg = '' + msg;
|
---|
2245 |
|
---|
2246 | // heuristic to determine if the error message already contains a (partial) source code dump
|
---|
2247 | // as produced by either `showPosition()` or `prettyPrintRange()`:
|
---|
2248 | if (show_input_position == undefined) {
|
---|
2249 | show_input_position = !(msg.indexOf('\n') > 0 && msg.indexOf('^') > 0);
|
---|
2250 | }
|
---|
2251 |
|
---|
2252 | if (this.yylloc && show_input_position) {
|
---|
2253 | if (typeof this.prettyPrintRange === 'function') {
|
---|
2254 | var pretty_src = this.prettyPrintRange(this.yylloc);
|
---|
2255 |
|
---|
2256 | if (!/\n\s*$/.test(msg)) {
|
---|
2257 | msg += '\n';
|
---|
2258 | }
|
---|
2259 |
|
---|
2260 | msg += '\n Erroneous area:\n' + this.prettyPrintRange(this.yylloc);
|
---|
2261 | } else if (typeof this.showPosition === 'function') {
|
---|
2262 | var pos_str = this.showPosition();
|
---|
2263 |
|
---|
2264 | if (pos_str) {
|
---|
2265 | if (msg.length && msg[msg.length - 1] !== '\n' && pos_str[0] !== '\n') {
|
---|
2266 | msg += '\n' + pos_str;
|
---|
2267 | } else {
|
---|
2268 | msg += pos_str;
|
---|
2269 | }
|
---|
2270 | }
|
---|
2271 | }
|
---|
2272 | }
|
---|
2273 |
|
---|
2274 | /** @constructor */
|
---|
2275 | var pei = {
|
---|
2276 | errStr: msg,
|
---|
2277 | recoverable: !!recoverable,
|
---|
2278 | text: this.match, // This one MAY be empty; userland code should use the `upcomingInput` API to obtain more text which follows the 'lexer cursor position'...
|
---|
2279 | token: null,
|
---|
2280 | line: this.yylineno,
|
---|
2281 | loc: this.yylloc,
|
---|
2282 | yy: this.yy,
|
---|
2283 | lexer: this,
|
---|
2284 |
|
---|
2285 | /**
|
---|
2286 | * and make sure the error info doesn't stay due to potential
|
---|
2287 | * ref cycle via userland code manipulations.
|
---|
2288 | * These would otherwise all be memory leak opportunities!
|
---|
2289 | *
|
---|
2290 | * Note that only array and object references are nuked as those
|
---|
2291 | * constitute the set of elements which can produce a cyclic ref.
|
---|
2292 | * The rest of the members is kept intact as they are harmless.
|
---|
2293 | *
|
---|
2294 | * @public
|
---|
2295 | * @this {LexErrorInfo}
|
---|
2296 | */
|
---|
2297 | destroy: function destructLexErrorInfo() {
|
---|
2298 | // remove cyclic references added to error info:
|
---|
2299 | // info.yy = null;
|
---|
2300 | // info.lexer = null;
|
---|
2301 | // ...
|
---|
2302 | var rec = !!this.recoverable;
|
---|
2303 |
|
---|
2304 | for (var key in this) {
|
---|
2305 | if (this.hasOwnProperty(key) && typeof key === 'object') {
|
---|
2306 | this[key] = undefined;
|
---|
2307 | }
|
---|
2308 | }
|
---|
2309 |
|
---|
2310 | this.recoverable = rec;
|
---|
2311 | }
|
---|
2312 | };
|
---|
2313 |
|
---|
2314 | // track this instance so we can `destroy()` it once we deem it superfluous and ready for garbage collection!
|
---|
2315 | this.__error_infos.push(pei);
|
---|
2316 |
|
---|
2317 | return pei;
|
---|
2318 | },
|
---|
2319 |
|
---|
2320 | /**
|
---|
2321 | * handler which is invoked when a lexer error occurs.
|
---|
2322 | *
|
---|
2323 | * @public
|
---|
2324 | * @this {RegExpLexer}
|
---|
2325 | */
|
---|
2326 | parseError: function lexer_parseError(str, hash, ExceptionClass) {
|
---|
2327 | if (!ExceptionClass) {
|
---|
2328 | ExceptionClass = this.JisonLexerError;
|
---|
2329 | }
|
---|
2330 |
|
---|
2331 | if (this.yy) {
|
---|
2332 | if (this.yy.parser && typeof this.yy.parser.parseError === 'function') {
|
---|
2333 | return this.yy.parser.parseError.call(this, str, hash, ExceptionClass) || this.ERROR;
|
---|
2334 | } else if (typeof this.yy.parseError === 'function') {
|
---|
2335 | return this.yy.parseError.call(this, str, hash, ExceptionClass) || this.ERROR;
|
---|
2336 | }
|
---|
2337 | }
|
---|
2338 |
|
---|
2339 | throw new ExceptionClass(str, hash);
|
---|
2340 | },
|
---|
2341 |
|
---|
2342 | /**
|
---|
2343 | * method which implements `yyerror(str, ...args)` functionality for use inside lexer actions.
|
---|
2344 | *
|
---|
2345 | * @public
|
---|
2346 | * @this {RegExpLexer}
|
---|
2347 | */
|
---|
2348 | yyerror: function yyError(str /*, ...args */) {
|
---|
2349 | var lineno_msg = '';
|
---|
2350 |
|
---|
2351 | if (this.yylloc) {
|
---|
2352 | lineno_msg = ' on line ' + (this.yylineno + 1);
|
---|
2353 | }
|
---|
2354 |
|
---|
2355 | var p = this.constructLexErrorInfo(
|
---|
2356 | 'Lexical error' + lineno_msg + ': ' + str,
|
---|
2357 | this.options.lexerErrorsAreRecoverable
|
---|
2358 | );
|
---|
2359 |
|
---|
2360 | // Add any extra args to the hash under the name `extra_error_attributes`:
|
---|
2361 | var args = Array.prototype.slice.call(arguments, 1);
|
---|
2362 |
|
---|
2363 | if (args.length) {
|
---|
2364 | p.extra_error_attributes = args;
|
---|
2365 | }
|
---|
2366 |
|
---|
2367 | return this.parseError(p.errStr, p, this.JisonLexerError) || this.ERROR;
|
---|
2368 | },
|
---|
2369 |
|
---|
2370 | /**
|
---|
2371 | * final cleanup function for when we have completed lexing the input;
|
---|
2372 | * make it an API so that external code can use this one once userland
|
---|
2373 | * code has decided it's time to destroy any lingering lexer error
|
---|
2374 | * hash object instances and the like: this function helps to clean
|
---|
2375 | * up these constructs, which *may* carry cyclic references which would
|
---|
2376 | * otherwise prevent the instances from being properly and timely
|
---|
2377 | * garbage-collected, i.e. this function helps prevent memory leaks!
|
---|
2378 | *
|
---|
2379 | * @public
|
---|
2380 | * @this {RegExpLexer}
|
---|
2381 | */
|
---|
2382 | cleanupAfterLex: function lexer_cleanupAfterLex(do_not_nuke_errorinfos) {
|
---|
2383 | // prevent lingering circular references from causing memory leaks:
|
---|
2384 | this.setInput('', {});
|
---|
2385 |
|
---|
2386 | // nuke the error hash info instances created during this run.
|
---|
2387 | // Userland code must COPY any data/references
|
---|
2388 | // in the error hash instance(s) it is more permanently interested in.
|
---|
2389 | if (!do_not_nuke_errorinfos) {
|
---|
2390 | for (var i = this.__error_infos.length - 1; i >= 0; i--) {
|
---|
2391 | var el = this.__error_infos[i];
|
---|
2392 |
|
---|
2393 | if (el && typeof el.destroy === 'function') {
|
---|
2394 | el.destroy();
|
---|
2395 | }
|
---|
2396 | }
|
---|
2397 |
|
---|
2398 | this.__error_infos.length = 0;
|
---|
2399 | }
|
---|
2400 |
|
---|
2401 | return this;
|
---|
2402 | },
|
---|
2403 |
|
---|
2404 | /**
|
---|
2405 | * clear the lexer token context; intended for internal use only
|
---|
2406 | *
|
---|
2407 | * @public
|
---|
2408 | * @this {RegExpLexer}
|
---|
2409 | */
|
---|
2410 | clear: function lexer_clear() {
|
---|
2411 | this.yytext = '';
|
---|
2412 | this.yyleng = 0;
|
---|
2413 | this.match = '';
|
---|
2414 |
|
---|
2415 | // - DO NOT reset `this.matched`
|
---|
2416 | this.matches = false;
|
---|
2417 |
|
---|
2418 | this._more = false;
|
---|
2419 | this._backtrack = false;
|
---|
2420 | var col = (this.yylloc ? this.yylloc.last_column : 0);
|
---|
2421 |
|
---|
2422 | this.yylloc = {
|
---|
2423 | first_line: this.yylineno + 1,
|
---|
2424 | first_column: col,
|
---|
2425 | last_line: this.yylineno + 1,
|
---|
2426 | last_column: col,
|
---|
2427 | range: [this.offset, this.offset]
|
---|
2428 | };
|
---|
2429 | },
|
---|
2430 |
|
---|
2431 | /**
|
---|
2432 | * resets the lexer, sets new input
|
---|
2433 | *
|
---|
2434 | * @public
|
---|
2435 | * @this {RegExpLexer}
|
---|
2436 | */
|
---|
2437 | setInput: function lexer_setInput(input, yy) {
|
---|
2438 | this.yy = yy || this.yy || {};
|
---|
2439 |
|
---|
2440 | // also check if we've fully initialized the lexer instance,
|
---|
2441 | // including expansion work to be done to go from a loaded
|
---|
2442 | // lexer to a usable lexer:
|
---|
2443 | if (!this.__decompressed) {
|
---|
2444 | // step 1: decompress the regex list:
|
---|
2445 | var rules = this.rules;
|
---|
2446 |
|
---|
2447 | for (var i = 0, len = rules.length; i < len; i++) {
|
---|
2448 | var rule_re = rules[i];
|
---|
2449 |
|
---|
2450 | // compression: is the RE an xref to another RE slot in the rules[] table?
|
---|
2451 | if (typeof rule_re === 'number') {
|
---|
2452 | rules[i] = rules[rule_re];
|
---|
2453 | }
|
---|
2454 | }
|
---|
2455 |
|
---|
2456 | // step 2: unfold the conditions[] set to make these ready for use:
|
---|
2457 | var conditions = this.conditions;
|
---|
2458 |
|
---|
2459 | for (var k in conditions) {
|
---|
2460 | var spec = conditions[k];
|
---|
2461 | var rule_ids = spec.rules;
|
---|
2462 | var len = rule_ids.length;
|
---|
2463 | var rule_regexes = new Array(len + 1); // slot 0 is unused; we use a 1-based index approach here to keep the hottest code in `lexer_next()` fast and simple!
|
---|
2464 | var rule_new_ids = new Array(len + 1);
|
---|
2465 |
|
---|
2466 | for (var i = 0; i < len; i++) {
|
---|
2467 | var idx = rule_ids[i];
|
---|
2468 | var rule_re = rules[idx];
|
---|
2469 | rule_regexes[i + 1] = rule_re;
|
---|
2470 | rule_new_ids[i + 1] = idx;
|
---|
2471 | }
|
---|
2472 |
|
---|
2473 | spec.rules = rule_new_ids;
|
---|
2474 | spec.__rule_regexes = rule_regexes;
|
---|
2475 | spec.__rule_count = len;
|
---|
2476 | }
|
---|
2477 |
|
---|
2478 | this.__decompressed = true;
|
---|
2479 | }
|
---|
2480 |
|
---|
2481 | this._input = input || '';
|
---|
2482 | this.clear();
|
---|
2483 | this._signaled_error_token = false;
|
---|
2484 | this.done = false;
|
---|
2485 | this.yylineno = 0;
|
---|
2486 | this.matched = '';
|
---|
2487 | this.conditionStack = ['INITIAL'];
|
---|
2488 | this.__currentRuleSet__ = null;
|
---|
2489 |
|
---|
2490 | this.yylloc = {
|
---|
2491 | first_line: 1,
|
---|
2492 | first_column: 0,
|
---|
2493 | last_line: 1,
|
---|
2494 | last_column: 0,
|
---|
2495 | range: [0, 0]
|
---|
2496 | };
|
---|
2497 |
|
---|
2498 | this.offset = 0;
|
---|
2499 | return this;
|
---|
2500 | },
|
---|
2501 |
|
---|
2502 | /**
|
---|
2503 | * edit the remaining input via user-specified callback.
|
---|
2504 | * This can be used to forward-adjust the input-to-parse,
|
---|
2505 | * e.g. inserting macro expansions and alike in the
|
---|
2506 | * input which has yet to be lexed.
|
---|
2507 | * The behaviour of this API contrasts the `unput()` et al
|
---|
2508 | * APIs as those act on the *consumed* input, while this
|
---|
2509 | * one allows one to manipulate the future, without impacting
|
---|
2510 | * the current `yyloc` cursor location or any history.
|
---|
2511 | *
|
---|
2512 | * Use this API to help implement C-preprocessor-like
|
---|
2513 | * `#include` statements, etc.
|
---|
2514 | *
|
---|
2515 | * The provided callback must be synchronous and is
|
---|
2516 | * expected to return the edited input (string).
|
---|
2517 | *
|
---|
2518 | * The `cpsArg` argument value is passed to the callback
|
---|
2519 | * as-is.
|
---|
2520 | *
|
---|
2521 | * `callback` interface:
|
---|
2522 | * `function callback(input, cpsArg)`
|
---|
2523 | *
|
---|
2524 | * - `input` will carry the remaining-input-to-lex string
|
---|
2525 | * from the lexer.
|
---|
2526 | * - `cpsArg` is `cpsArg` passed into this API.
|
---|
2527 | *
|
---|
2528 | * The `this` reference for the callback will be set to
|
---|
2529 | * reference this lexer instance so that userland code
|
---|
2530 | * in the callback can easily and quickly access any lexer
|
---|
2531 | * API.
|
---|
2532 | *
|
---|
2533 | * When the callback returns a non-string-type falsey value,
|
---|
2534 | * we assume the callback did not edit the input and we
|
---|
2535 | * will using the input as-is.
|
---|
2536 | *
|
---|
2537 | * When the callback returns a non-string-type value, it
|
---|
2538 | * is converted to a string for lexing via the `"" + retval`
|
---|
2539 | * operation. (See also why: http://2ality.com/2012/03/converting-to-string.html
|
---|
2540 | * -- that way any returned object's `toValue()` and `toString()`
|
---|
2541 | * methods will be invoked in a proper/desirable order.)
|
---|
2542 | *
|
---|
2543 | * @public
|
---|
2544 | * @this {RegExpLexer}
|
---|
2545 | */
|
---|
2546 | editRemainingInput: function lexer_editRemainingInput(callback, cpsArg) {
|
---|
2547 | var rv = callback.call(this, this._input, cpsArg);
|
---|
2548 |
|
---|
2549 | if (typeof rv !== 'string') {
|
---|
2550 | if (rv) {
|
---|
2551 | this._input = '' + rv;
|
---|
2552 | }
|
---|
2553 | // else: keep `this._input` as is.
|
---|
2554 | } else {
|
---|
2555 | this._input = rv;
|
---|
2556 | }
|
---|
2557 |
|
---|
2558 | return this;
|
---|
2559 | },
|
---|
2560 |
|
---|
2561 | /**
|
---|
2562 | * consumes and returns one char from the input
|
---|
2563 | *
|
---|
2564 | * @public
|
---|
2565 | * @this {RegExpLexer}
|
---|
2566 | */
|
---|
2567 | input: function lexer_input() {
|
---|
2568 | if (!this._input) {
|
---|
2569 | //this.done = true; -- don't set `done` as we want the lex()/next() API to be able to produce one custom EOF token match after this anyhow. (lexer can match special <<EOF>> tokens and perform user action code for a <<EOF>> match, but only does so *once*)
|
---|
2570 | return null;
|
---|
2571 | }
|
---|
2572 |
|
---|
2573 | var ch = this._input[0];
|
---|
2574 | this.yytext += ch;
|
---|
2575 | this.yyleng++;
|
---|
2576 | this.offset++;
|
---|
2577 | this.match += ch;
|
---|
2578 | this.matched += ch;
|
---|
2579 |
|
---|
2580 | // Count the linenumber up when we hit the LF (or a stand-alone CR).
|
---|
2581 | // On CRLF, the linenumber is incremented when you fetch the CR or the CRLF combo
|
---|
2582 | // and we advance immediately past the LF as well, returning both together as if
|
---|
2583 | // it was all a single 'character' only.
|
---|
2584 | var slice_len = 1;
|
---|
2585 |
|
---|
2586 | var lines = false;
|
---|
2587 |
|
---|
2588 | if (ch === '\n') {
|
---|
2589 | lines = true;
|
---|
2590 | } else if (ch === '\r') {
|
---|
2591 | lines = true;
|
---|
2592 | var ch2 = this._input[1];
|
---|
2593 |
|
---|
2594 | if (ch2 === '\n') {
|
---|
2595 | slice_len++;
|
---|
2596 | ch += ch2;
|
---|
2597 | this.yytext += ch2;
|
---|
2598 | this.yyleng++;
|
---|
2599 | this.offset++;
|
---|
2600 | this.match += ch2;
|
---|
2601 | this.matched += ch2;
|
---|
2602 | this.yylloc.range[1]++;
|
---|
2603 | }
|
---|
2604 | }
|
---|
2605 |
|
---|
2606 | if (lines) {
|
---|
2607 | this.yylineno++;
|
---|
2608 | this.yylloc.last_line++;
|
---|
2609 | this.yylloc.last_column = 0;
|
---|
2610 | } else {
|
---|
2611 | this.yylloc.last_column++;
|
---|
2612 | }
|
---|
2613 |
|
---|
2614 | this.yylloc.range[1]++;
|
---|
2615 | this._input = this._input.slice(slice_len);
|
---|
2616 | return ch;
|
---|
2617 | },
|
---|
2618 |
|
---|
2619 | /**
|
---|
2620 | * unshifts one char (or an entire string) into the input
|
---|
2621 | *
|
---|
2622 | * @public
|
---|
2623 | * @this {RegExpLexer}
|
---|
2624 | */
|
---|
2625 | unput: function lexer_unput(ch) {
|
---|
2626 | var len = ch.length;
|
---|
2627 | var lines = ch.split(/(?:\r\n?|\n)/g);
|
---|
2628 | this._input = ch + this._input;
|
---|
2629 | this.yytext = this.yytext.substr(0, this.yytext.length - len);
|
---|
2630 | this.yyleng = this.yytext.length;
|
---|
2631 | this.offset -= len;
|
---|
2632 | this.match = this.match.substr(0, this.match.length - len);
|
---|
2633 | this.matched = this.matched.substr(0, this.matched.length - len);
|
---|
2634 |
|
---|
2635 | if (lines.length > 1) {
|
---|
2636 | this.yylineno -= lines.length - 1;
|
---|
2637 | this.yylloc.last_line = this.yylineno + 1;
|
---|
2638 |
|
---|
2639 | // Get last entirely matched line into the `pre_lines[]` array's
|
---|
2640 | // last index slot; we don't mind when other previously
|
---|
2641 | // matched lines end up in the array too.
|
---|
2642 | var pre = this.match;
|
---|
2643 |
|
---|
2644 | var pre_lines = pre.split(/(?:\r\n?|\n)/g);
|
---|
2645 |
|
---|
2646 | if (pre_lines.length === 1) {
|
---|
2647 | pre = this.matched;
|
---|
2648 | pre_lines = pre.split(/(?:\r\n?|\n)/g);
|
---|
2649 | }
|
---|
2650 |
|
---|
2651 | this.yylloc.last_column = pre_lines[pre_lines.length - 1].length;
|
---|
2652 | } else {
|
---|
2653 | this.yylloc.last_column -= len;
|
---|
2654 | }
|
---|
2655 |
|
---|
2656 | this.yylloc.range[1] = this.yylloc.range[0] + this.yyleng;
|
---|
2657 | this.done = false;
|
---|
2658 | return this;
|
---|
2659 | },
|
---|
2660 |
|
---|
2661 | /**
|
---|
2662 | * cache matched text and append it on next action
|
---|
2663 | *
|
---|
2664 | * @public
|
---|
2665 | * @this {RegExpLexer}
|
---|
2666 | */
|
---|
2667 | more: function lexer_more() {
|
---|
2668 | this._more = true;
|
---|
2669 | return this;
|
---|
2670 | },
|
---|
2671 |
|
---|
2672 | /**
|
---|
2673 | * signal the lexer that this rule fails to match the input, so the
|
---|
2674 | * next matching rule (regex) should be tested instead.
|
---|
2675 | *
|
---|
2676 | * @public
|
---|
2677 | * @this {RegExpLexer}
|
---|
2678 | */
|
---|
2679 | reject: function lexer_reject() {
|
---|
2680 | if (this.options.backtrack_lexer) {
|
---|
2681 | this._backtrack = true;
|
---|
2682 | } else {
|
---|
2683 | // when the `parseError()` call returns, we MUST ensure that the error is registered.
|
---|
2684 | // We accomplish this by signaling an 'error' token to be produced for the current
|
---|
2685 | // `.lex()` run.
|
---|
2686 | var lineno_msg = '';
|
---|
2687 |
|
---|
2688 | if (this.yylloc) {
|
---|
2689 | lineno_msg = ' on line ' + (this.yylineno + 1);
|
---|
2690 | }
|
---|
2691 |
|
---|
2692 | var p = this.constructLexErrorInfo(
|
---|
2693 | 'Lexical error' + lineno_msg + ': You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).',
|
---|
2694 | false
|
---|
2695 | );
|
---|
2696 |
|
---|
2697 | this._signaled_error_token = this.parseError(p.errStr, p, this.JisonLexerError) || this.ERROR;
|
---|
2698 | }
|
---|
2699 |
|
---|
2700 | return this;
|
---|
2701 | },
|
---|
2702 |
|
---|
2703 | /**
|
---|
2704 | * retain first n characters of the match
|
---|
2705 | *
|
---|
2706 | * @public
|
---|
2707 | * @this {RegExpLexer}
|
---|
2708 | */
|
---|
2709 | less: function lexer_less(n) {
|
---|
2710 | return this.unput(this.match.slice(n));
|
---|
2711 | },
|
---|
2712 |
|
---|
2713 | /**
|
---|
2714 | * return (part of the) already matched input, i.e. for error
|
---|
2715 | * messages.
|
---|
2716 | *
|
---|
2717 | * Limit the returned string length to `maxSize` (default: 20).
|
---|
2718 | *
|
---|
2719 | * Limit the returned string to the `maxLines` number of lines of
|
---|
2720 | * input (default: 1).
|
---|
2721 | *
|
---|
2722 | * Negative limit values equal *unlimited*.
|
---|
2723 | *
|
---|
2724 | * @public
|
---|
2725 | * @this {RegExpLexer}
|
---|
2726 | */
|
---|
2727 | pastInput: function lexer_pastInput(maxSize, maxLines) {
|
---|
2728 | var past = this.matched.substring(0, this.matched.length - this.match.length);
|
---|
2729 |
|
---|
2730 | if (maxSize < 0)
|
---|
2731 | maxSize = past.length;
|
---|
2732 | else if (!maxSize)
|
---|
2733 | maxSize = 20;
|
---|
2734 |
|
---|
2735 | if (maxLines < 0)
|
---|
2736 | maxLines = past.length; // can't ever have more input lines than this!
|
---|
2737 | else if (!maxLines)
|
---|
2738 | maxLines = 1;
|
---|
2739 |
|
---|
2740 | // `substr` anticipation: treat \r\n as a single character and take a little
|
---|
2741 | // more than necessary so that we can still properly check against maxSize
|
---|
2742 | // after we've transformed and limited the newLines in here:
|
---|
2743 | past = past.substr(-maxSize * 2 - 2);
|
---|
2744 |
|
---|
2745 | // now that we have a significantly reduced string to process, transform the newlines
|
---|
2746 | // and chop them, then limit them:
|
---|
2747 | var a = past.replace(/\r\n|\r/g, '\n').split('\n');
|
---|
2748 |
|
---|
2749 | a = a.slice(-maxLines);
|
---|
2750 | past = a.join('\n');
|
---|
2751 |
|
---|
2752 | // When, after limiting to maxLines, we still have too much to return,
|
---|
2753 | // do add an ellipsis prefix...
|
---|
2754 | if (past.length > maxSize) {
|
---|
2755 | past = '...' + past.substr(-maxSize);
|
---|
2756 | }
|
---|
2757 |
|
---|
2758 | return past;
|
---|
2759 | },
|
---|
2760 |
|
---|
2761 | /**
|
---|
2762 | * return (part of the) upcoming input, i.e. for error messages.
|
---|
2763 | *
|
---|
2764 | * Limit the returned string length to `maxSize` (default: 20).
|
---|
2765 | *
|
---|
2766 | * Limit the returned string to the `maxLines` number of lines of input (default: 1).
|
---|
2767 | *
|
---|
2768 | * Negative limit values equal *unlimited*.
|
---|
2769 | *
|
---|
2770 | * > ### NOTE ###
|
---|
2771 | * >
|
---|
2772 | * > *"upcoming input"* is defined as the whole of the both
|
---|
2773 | * > the *currently lexed* input, together with any remaining input
|
---|
2774 | * > following that. *"currently lexed"* input is the input
|
---|
2775 | * > already recognized by the lexer but not yet returned with
|
---|
2776 | * > the lexer token. This happens when you are invoking this API
|
---|
2777 | * > from inside any lexer rule action code block.
|
---|
2778 | * >
|
---|
2779 | *
|
---|
2780 | * @public
|
---|
2781 | * @this {RegExpLexer}
|
---|
2782 | */
|
---|
2783 | upcomingInput: function lexer_upcomingInput(maxSize, maxLines) {
|
---|
2784 | var next = this.match;
|
---|
2785 |
|
---|
2786 | if (maxSize < 0)
|
---|
2787 | maxSize = next.length + this._input.length;
|
---|
2788 | else if (!maxSize)
|
---|
2789 | maxSize = 20;
|
---|
2790 |
|
---|
2791 | if (maxLines < 0)
|
---|
2792 | maxLines = maxSize; // can't ever have more input lines than this!
|
---|
2793 | else if (!maxLines)
|
---|
2794 | maxLines = 1;
|
---|
2795 |
|
---|
2796 | // `substring` anticipation: treat \r\n as a single character and take a little
|
---|
2797 | // more than necessary so that we can still properly check against maxSize
|
---|
2798 | // after we've transformed and limited the newLines in here:
|
---|
2799 | if (next.length < maxSize * 2 + 2) {
|
---|
2800 | next += this._input.substring(0, maxSize * 2 + 2); // substring is faster on Chrome/V8
|
---|
2801 | }
|
---|
2802 |
|
---|
2803 | // now that we have a significantly reduced string to process, transform the newlines
|
---|
2804 | // and chop them, then limit them:
|
---|
2805 | var a = next.replace(/\r\n|\r/g, '\n').split('\n');
|
---|
2806 |
|
---|
2807 | a = a.slice(0, maxLines);
|
---|
2808 | next = a.join('\n');
|
---|
2809 |
|
---|
2810 | // When, after limiting to maxLines, we still have too much to return,
|
---|
2811 | // do add an ellipsis postfix...
|
---|
2812 | if (next.length > maxSize) {
|
---|
2813 | next = next.substring(0, maxSize) + '...';
|
---|
2814 | }
|
---|
2815 |
|
---|
2816 | return next;
|
---|
2817 | },
|
---|
2818 |
|
---|
2819 | /**
|
---|
2820 | * return a string which displays the character position where the
|
---|
2821 | * lexing error occurred, i.e. for error messages
|
---|
2822 | *
|
---|
2823 | * @public
|
---|
2824 | * @this {RegExpLexer}
|
---|
2825 | */
|
---|
2826 | showPosition: function lexer_showPosition(maxPrefix, maxPostfix) {
|
---|
2827 | var pre = this.pastInput(maxPrefix).replace(/\s/g, ' ');
|
---|
2828 | var c = new Array(pre.length + 1).join('-');
|
---|
2829 | return pre + this.upcomingInput(maxPostfix).replace(/\s/g, ' ') + '\n' + c + '^';
|
---|
2830 | },
|
---|
2831 |
|
---|
2832 | /**
|
---|
2833 | * return an YYLLOC info object derived off the given context (actual, preceding, following, current).
|
---|
2834 | * Use this method when the given `actual` location is not guaranteed to exist (i.e. when
|
---|
2835 | * it MAY be NULL) and you MUST have a valid location info object anyway:
|
---|
2836 | * then we take the given context of the `preceding` and `following` locations, IFF those are available,
|
---|
2837 | * and reconstruct the `actual` location info from those.
|
---|
2838 | * If this fails, the heuristic is to take the `current` location, IFF available.
|
---|
2839 | * If this fails as well, we assume the sought location is at/around the current lexer position
|
---|
2840 | * and then produce that one as a response. DO NOTE that these heuristic/derived location info
|
---|
2841 | * values MAY be inaccurate!
|
---|
2842 | *
|
---|
2843 | * NOTE: `deriveLocationInfo()` ALWAYS produces a location info object *copy* of `actual`, not just
|
---|
2844 | * a *reference* hence all input location objects can be assumed to be 'constant' (function has no side-effects).
|
---|
2845 | *
|
---|
2846 | * @public
|
---|
2847 | * @this {RegExpLexer}
|
---|
2848 | */
|
---|
2849 | deriveLocationInfo: function lexer_deriveYYLLOC(actual, preceding, following, current) {
|
---|
2850 | var loc = {
|
---|
2851 | first_line: 1,
|
---|
2852 | first_column: 0,
|
---|
2853 | last_line: 1,
|
---|
2854 | last_column: 0,
|
---|
2855 | range: [0, 0]
|
---|
2856 | };
|
---|
2857 |
|
---|
2858 | if (actual) {
|
---|
2859 | loc.first_line = actual.first_line | 0;
|
---|
2860 | loc.last_line = actual.last_line | 0;
|
---|
2861 | loc.first_column = actual.first_column | 0;
|
---|
2862 | loc.last_column = actual.last_column | 0;
|
---|
2863 |
|
---|
2864 | if (actual.range) {
|
---|
2865 | loc.range[0] = actual.range[0] | 0;
|
---|
2866 | loc.range[1] = actual.range[1] | 0;
|
---|
2867 | }
|
---|
2868 | }
|
---|
2869 |
|
---|
2870 | if (loc.first_line <= 0 || loc.last_line < loc.first_line) {
|
---|
2871 | // plan B: heuristic using preceding and following:
|
---|
2872 | if (loc.first_line <= 0 && preceding) {
|
---|
2873 | loc.first_line = preceding.last_line | 0;
|
---|
2874 | loc.first_column = preceding.last_column | 0;
|
---|
2875 |
|
---|
2876 | if (preceding.range) {
|
---|
2877 | loc.range[0] = actual.range[1] | 0;
|
---|
2878 | }
|
---|
2879 | }
|
---|
2880 |
|
---|
2881 | if ((loc.last_line <= 0 || loc.last_line < loc.first_line) && following) {
|
---|
2882 | loc.last_line = following.first_line | 0;
|
---|
2883 | loc.last_column = following.first_column | 0;
|
---|
2884 |
|
---|
2885 | if (following.range) {
|
---|
2886 | loc.range[1] = actual.range[0] | 0;
|
---|
2887 | }
|
---|
2888 | }
|
---|
2889 |
|
---|
2890 | // plan C?: see if the 'current' location is useful/sane too:
|
---|
2891 | if (loc.first_line <= 0 && current && (loc.last_line <= 0 || current.last_line <= loc.last_line)) {
|
---|
2892 | loc.first_line = current.first_line | 0;
|
---|
2893 | loc.first_column = current.first_column | 0;
|
---|
2894 |
|
---|
2895 | if (current.range) {
|
---|
2896 | loc.range[0] = current.range[0] | 0;
|
---|
2897 | }
|
---|
2898 | }
|
---|
2899 |
|
---|
2900 | if (loc.last_line <= 0 && current && (loc.first_line <= 0 || current.first_line >= loc.first_line)) {
|
---|
2901 | loc.last_line = current.last_line | 0;
|
---|
2902 | loc.last_column = current.last_column | 0;
|
---|
2903 |
|
---|
2904 | if (current.range) {
|
---|
2905 | loc.range[1] = current.range[1] | 0;
|
---|
2906 | }
|
---|
2907 | }
|
---|
2908 | }
|
---|
2909 |
|
---|
2910 | // sanitize: fix last_line BEFORE we fix first_line as we use the 'raw' value of the latter
|
---|
2911 | // or plan D heuristics to produce a 'sensible' last_line value:
|
---|
2912 | if (loc.last_line <= 0) {
|
---|
2913 | if (loc.first_line <= 0) {
|
---|
2914 | loc.first_line = this.yylloc.first_line;
|
---|
2915 | loc.last_line = this.yylloc.last_line;
|
---|
2916 | loc.first_column = this.yylloc.first_column;
|
---|
2917 | loc.last_column = this.yylloc.last_column;
|
---|
2918 | loc.range[0] = this.yylloc.range[0];
|
---|
2919 | loc.range[1] = this.yylloc.range[1];
|
---|
2920 | } else {
|
---|
2921 | loc.last_line = this.yylloc.last_line;
|
---|
2922 | loc.last_column = this.yylloc.last_column;
|
---|
2923 | loc.range[1] = this.yylloc.range[1];
|
---|
2924 | }
|
---|
2925 | }
|
---|
2926 |
|
---|
2927 | if (loc.first_line <= 0) {
|
---|
2928 | loc.first_line = loc.last_line;
|
---|
2929 | loc.first_column = 0; // loc.last_column;
|
---|
2930 | loc.range[1] = loc.range[0];
|
---|
2931 | }
|
---|
2932 |
|
---|
2933 | if (loc.first_column < 0) {
|
---|
2934 | loc.first_column = 0;
|
---|
2935 | }
|
---|
2936 |
|
---|
2937 | if (loc.last_column < 0) {
|
---|
2938 | loc.last_column = (loc.first_column > 0 ? loc.first_column : 80);
|
---|
2939 | }
|
---|
2940 |
|
---|
2941 | return loc;
|
---|
2942 | },
|
---|
2943 |
|
---|
2944 | /**
|
---|
2945 | * return a string which displays the lines & columns of input which are referenced
|
---|
2946 | * by the given location info range, plus a few lines of context.
|
---|
2947 | *
|
---|
2948 | * This function pretty-prints the indicated section of the input, with line numbers
|
---|
2949 | * and everything!
|
---|
2950 | *
|
---|
2951 | * This function is very useful to provide highly readable error reports, while
|
---|
2952 | * the location range may be specified in various flexible ways:
|
---|
2953 | *
|
---|
2954 | * - `loc` is the location info object which references the area which should be
|
---|
2955 | * displayed and 'marked up': these lines & columns of text are marked up by `^`
|
---|
2956 | * characters below each character in the entire input range.
|
---|
2957 | *
|
---|
2958 | * - `context_loc` is the *optional* location info object which instructs this
|
---|
2959 | * pretty-printer how much *leading* context should be displayed alongside
|
---|
2960 | * the area referenced by `loc`. This can help provide context for the displayed
|
---|
2961 | * error, etc.
|
---|
2962 | *
|
---|
2963 | * When this location info is not provided, a default context of 3 lines is
|
---|
2964 | * used.
|
---|
2965 | *
|
---|
2966 | * - `context_loc2` is another *optional* location info object, which serves
|
---|
2967 | * a similar purpose to `context_loc`: it specifies the amount of *trailing*
|
---|
2968 | * context lines to display in the pretty-print output.
|
---|
2969 | *
|
---|
2970 | * When this location info is not provided, a default context of 1 line only is
|
---|
2971 | * used.
|
---|
2972 | *
|
---|
2973 | * Special Notes:
|
---|
2974 | *
|
---|
2975 | * - when the `loc`-indicated range is very large (about 5 lines or more), then
|
---|
2976 | * only the first and last few lines of this block are printed while a
|
---|
2977 | * `...continued...` message will be printed between them.
|
---|
2978 | *
|
---|
2979 | * This serves the purpose of not printing a huge amount of text when the `loc`
|
---|
2980 | * range happens to be huge: this way a manageable & readable output results
|
---|
2981 | * for arbitrary large ranges.
|
---|
2982 | *
|
---|
2983 | * - this function can display lines of input which whave not yet been lexed.
|
---|
2984 | * `prettyPrintRange()` can access the entire input!
|
---|
2985 | *
|
---|
2986 | * @public
|
---|
2987 | * @this {RegExpLexer}
|
---|
2988 | */
|
---|
2989 | prettyPrintRange: function lexer_prettyPrintRange(loc, context_loc, context_loc2) {
|
---|
2990 | loc = this.deriveLocationInfo(loc, context_loc, context_loc2);
|
---|
2991 | const CONTEXT = 3;
|
---|
2992 | const CONTEXT_TAIL = 1;
|
---|
2993 | const MINIMUM_VISIBLE_NONEMPTY_LINE_COUNT = 2;
|
---|
2994 | var input = this.matched + this._input;
|
---|
2995 | var lines = input.split('\n');
|
---|
2996 | var l0 = Math.max(1, (context_loc ? context_loc.first_line : loc.first_line - CONTEXT));
|
---|
2997 | var l1 = Math.max(1, (context_loc2 ? context_loc2.last_line : loc.last_line + CONTEXT_TAIL));
|
---|
2998 | var lineno_display_width = 1 + Math.log10(l1 | 1) | 0;
|
---|
2999 | var ws_prefix = new Array(lineno_display_width).join(' ');
|
---|
3000 | var nonempty_line_indexes = [];
|
---|
3001 |
|
---|
3002 | var rv = lines.slice(l0 - 1, l1 + 1).map(function injectLineNumber(line, index) {
|
---|
3003 | var lno = index + l0;
|
---|
3004 | var lno_pfx = (ws_prefix + lno).substr(-lineno_display_width);
|
---|
3005 | var rv = lno_pfx + ': ' + line;
|
---|
3006 | var errpfx = new Array(lineno_display_width + 1).join('^');
|
---|
3007 | var offset = 2 + 1;
|
---|
3008 | var len = 0;
|
---|
3009 |
|
---|
3010 | if (lno === loc.first_line) {
|
---|
3011 | offset += loc.first_column;
|
---|
3012 |
|
---|
3013 | len = Math.max(
|
---|
3014 | 2,
|
---|
3015 | ((lno === loc.last_line ? loc.last_column : line.length)) - loc.first_column + 1
|
---|
3016 | );
|
---|
3017 | } else if (lno === loc.last_line) {
|
---|
3018 | len = Math.max(2, loc.last_column + 1);
|
---|
3019 | } else if (lno > loc.first_line && lno < loc.last_line) {
|
---|
3020 | len = Math.max(2, line.length + 1);
|
---|
3021 | }
|
---|
3022 |
|
---|
3023 | if (len) {
|
---|
3024 | var lead = new Array(offset).join('.');
|
---|
3025 | var mark = new Array(len).join('^');
|
---|
3026 | rv += '\n' + errpfx + lead + mark;
|
---|
3027 |
|
---|
3028 | if (line.trim().length > 0) {
|
---|
3029 | nonempty_line_indexes.push(index);
|
---|
3030 | }
|
---|
3031 | }
|
---|
3032 |
|
---|
3033 | rv = rv.replace(/\t/g, ' ');
|
---|
3034 | return rv;
|
---|
3035 | });
|
---|
3036 |
|
---|
3037 | // now make sure we don't print an overly large amount of error area: limit it
|
---|
3038 | // to the top and bottom line count:
|
---|
3039 | if (nonempty_line_indexes.length > 2 * MINIMUM_VISIBLE_NONEMPTY_LINE_COUNT) {
|
---|
3040 | var clip_start = nonempty_line_indexes[MINIMUM_VISIBLE_NONEMPTY_LINE_COUNT - 1] + 1;
|
---|
3041 | var clip_end = nonempty_line_indexes[nonempty_line_indexes.length - MINIMUM_VISIBLE_NONEMPTY_LINE_COUNT] - 1;
|
---|
3042 | var intermediate_line = new Array(lineno_display_width + 1).join(' ') + ' (...continued...)';
|
---|
3043 | intermediate_line += '\n' + new Array(lineno_display_width + 1).join('-') + ' (---------------)';
|
---|
3044 | rv.splice(clip_start, clip_end - clip_start + 1, intermediate_line);
|
---|
3045 | }
|
---|
3046 |
|
---|
3047 | return rv.join('\n');
|
---|
3048 | },
|
---|
3049 |
|
---|
3050 | /**
|
---|
3051 | * helper function, used to produce a human readable description as a string, given
|
---|
3052 | * the input `yylloc` location object.
|
---|
3053 | *
|
---|
3054 | * Set `display_range_too` to TRUE to include the string character index position(s)
|
---|
3055 | * in the description if the `yylloc.range` is available.
|
---|
3056 | *
|
---|
3057 | * @public
|
---|
3058 | * @this {RegExpLexer}
|
---|
3059 | */
|
---|
3060 | describeYYLLOC: function lexer_describe_yylloc(yylloc, display_range_too) {
|
---|
3061 | var l1 = yylloc.first_line;
|
---|
3062 | var l2 = yylloc.last_line;
|
---|
3063 | var c1 = yylloc.first_column;
|
---|
3064 | var c2 = yylloc.last_column;
|
---|
3065 | var dl = l2 - l1;
|
---|
3066 | var dc = c2 - c1;
|
---|
3067 | var rv;
|
---|
3068 |
|
---|
3069 | if (dl === 0) {
|
---|
3070 | rv = 'line ' + l1 + ', ';
|
---|
3071 |
|
---|
3072 | if (dc <= 1) {
|
---|
3073 | rv += 'column ' + c1;
|
---|
3074 | } else {
|
---|
3075 | rv += 'columns ' + c1 + ' .. ' + c2;
|
---|
3076 | }
|
---|
3077 | } else {
|
---|
3078 | rv = 'lines ' + l1 + '(column ' + c1 + ') .. ' + l2 + '(column ' + c2 + ')';
|
---|
3079 | }
|
---|
3080 |
|
---|
3081 | if (yylloc.range && display_range_too) {
|
---|
3082 | var r1 = yylloc.range[0];
|
---|
3083 | var r2 = yylloc.range[1] - 1;
|
---|
3084 |
|
---|
3085 | if (r2 <= r1) {
|
---|
3086 | rv += ' {String Offset: ' + r1 + '}';
|
---|
3087 | } else {
|
---|
3088 | rv += ' {String Offset range: ' + r1 + ' .. ' + r2 + '}';
|
---|
3089 | }
|
---|
3090 | }
|
---|
3091 |
|
---|
3092 | return rv;
|
---|
3093 | },
|
---|
3094 |
|
---|
3095 | /**
|
---|
3096 | * test the lexed token: return FALSE when not a match, otherwise return token.
|
---|
3097 | *
|
---|
3098 | * `match` is supposed to be an array coming out of a regex match, i.e. `match[0]`
|
---|
3099 | * contains the actually matched text string.
|
---|
3100 | *
|
---|
3101 | * Also move the input cursor forward and update the match collectors:
|
---|
3102 | *
|
---|
3103 | * - `yytext`
|
---|
3104 | * - `yyleng`
|
---|
3105 | * - `match`
|
---|
3106 | * - `matches`
|
---|
3107 | * - `yylloc`
|
---|
3108 | * - `offset`
|
---|
3109 | *
|
---|
3110 | * @public
|
---|
3111 | * @this {RegExpLexer}
|
---|
3112 | */
|
---|
3113 | test_match: function lexer_test_match(match, indexed_rule) {
|
---|
3114 | var token, lines, backup, match_str, match_str_len;
|
---|
3115 |
|
---|
3116 | if (this.options.backtrack_lexer) {
|
---|
3117 | // save context
|
---|
3118 | backup = {
|
---|
3119 | yylineno: this.yylineno,
|
---|
3120 |
|
---|
3121 | yylloc: {
|
---|
3122 | first_line: this.yylloc.first_line,
|
---|
3123 | last_line: this.yylloc.last_line,
|
---|
3124 | first_column: this.yylloc.first_column,
|
---|
3125 | last_column: this.yylloc.last_column,
|
---|
3126 | range: this.yylloc.range.slice(0)
|
---|
3127 | },
|
---|
3128 |
|
---|
3129 | yytext: this.yytext,
|
---|
3130 | match: this.match,
|
---|
3131 | matches: this.matches,
|
---|
3132 | matched: this.matched,
|
---|
3133 | yyleng: this.yyleng,
|
---|
3134 | offset: this.offset,
|
---|
3135 | _more: this._more,
|
---|
3136 | _input: this._input,
|
---|
3137 |
|
---|
3138 | //_signaled_error_token: this._signaled_error_token,
|
---|
3139 | yy: this.yy,
|
---|
3140 |
|
---|
3141 | conditionStack: this.conditionStack.slice(0),
|
---|
3142 | done: this.done
|
---|
3143 | };
|
---|
3144 | }
|
---|
3145 |
|
---|
3146 | match_str = match[0];
|
---|
3147 | match_str_len = match_str.length;
|
---|
3148 |
|
---|
3149 | // if (match_str.indexOf('\n') !== -1 || match_str.indexOf('\r') !== -1) {
|
---|
3150 | lines = match_str.split(/(?:\r\n?|\n)/g);
|
---|
3151 |
|
---|
3152 | if (lines.length > 1) {
|
---|
3153 | this.yylineno += lines.length - 1;
|
---|
3154 | this.yylloc.last_line = this.yylineno + 1;
|
---|
3155 | this.yylloc.last_column = lines[lines.length - 1].length;
|
---|
3156 | } else {
|
---|
3157 | this.yylloc.last_column += match_str_len;
|
---|
3158 | }
|
---|
3159 |
|
---|
3160 | // }
|
---|
3161 | this.yytext += match_str;
|
---|
3162 |
|
---|
3163 | this.match += match_str;
|
---|
3164 | this.matched += match_str;
|
---|
3165 | this.matches = match;
|
---|
3166 | this.yyleng = this.yytext.length;
|
---|
3167 | this.yylloc.range[1] += match_str_len;
|
---|
3168 |
|
---|
3169 | // previous lex rules MAY have invoked the `more()` API rather than producing a token:
|
---|
3170 | // those rules will already have moved this `offset` forward matching their match lengths,
|
---|
3171 | // hence we must only add our own match length now:
|
---|
3172 | this.offset += match_str_len;
|
---|
3173 |
|
---|
3174 | this._more = false;
|
---|
3175 | this._backtrack = false;
|
---|
3176 | this._input = this._input.slice(match_str_len);
|
---|
3177 |
|
---|
3178 | // calling this method:
|
---|
3179 | //
|
---|
3180 | // function lexer__performAction(yy, yyrulenumber, YY_START) {...}
|
---|
3181 | token = this.performAction.call(
|
---|
3182 | this,
|
---|
3183 | this.yy,
|
---|
3184 | indexed_rule,
|
---|
3185 | this.conditionStack[this.conditionStack.length - 1] /* = YY_START */
|
---|
3186 | );
|
---|
3187 |
|
---|
3188 | // otherwise, when the action codes are all simple return token statements:
|
---|
3189 | //token = this.simpleCaseActionClusters[indexed_rule];
|
---|
3190 |
|
---|
3191 | if (this.done && this._input) {
|
---|
3192 | this.done = false;
|
---|
3193 | }
|
---|
3194 |
|
---|
3195 | if (token) {
|
---|
3196 | return token;
|
---|
3197 | } else if (this._backtrack) {
|
---|
3198 | // recover context
|
---|
3199 | for (var k in backup) {
|
---|
3200 | this[k] = backup[k];
|
---|
3201 | }
|
---|
3202 |
|
---|
3203 | this.__currentRuleSet__ = null;
|
---|
3204 | return false; // rule action called reject() implying the next rule should be tested instead.
|
---|
3205 | } else if (this._signaled_error_token) {
|
---|
3206 | // produce one 'error' token as `.parseError()` in `reject()`
|
---|
3207 | // did not guarantee a failure signal by throwing an exception!
|
---|
3208 | token = this._signaled_error_token;
|
---|
3209 |
|
---|
3210 | this._signaled_error_token = false;
|
---|
3211 | return token;
|
---|
3212 | }
|
---|
3213 |
|
---|
3214 | return false;
|
---|
3215 | },
|
---|
3216 |
|
---|
3217 | /**
|
---|
3218 | * return next match in input
|
---|
3219 | *
|
---|
3220 | * @public
|
---|
3221 | * @this {RegExpLexer}
|
---|
3222 | */
|
---|
3223 | next: function lexer_next() {
|
---|
3224 | if (this.done) {
|
---|
3225 | this.clear();
|
---|
3226 | return this.EOF;
|
---|
3227 | }
|
---|
3228 |
|
---|
3229 | if (!this._input) {
|
---|
3230 | this.done = true;
|
---|
3231 | }
|
---|
3232 |
|
---|
3233 | var token, match, tempMatch, index;
|
---|
3234 |
|
---|
3235 | if (!this._more) {
|
---|
3236 | this.clear();
|
---|
3237 | }
|
---|
3238 |
|
---|
3239 | var spec = this.__currentRuleSet__;
|
---|
3240 |
|
---|
3241 | if (!spec) {
|
---|
3242 | // Update the ruleset cache as we apparently encountered a state change or just started lexing.
|
---|
3243 | // The cache is set up for fast lookup -- we assume a lexer will switch states much less often than it will
|
---|
3244 | // invoke the `lex()` token-producing API and related APIs, hence caching the set for direct access helps
|
---|
3245 | // speed up those activities a tiny bit.
|
---|
3246 | spec = this.__currentRuleSet__ = this._currentRules();
|
---|
3247 |
|
---|
3248 | // Check whether a *sane* condition has been pushed before: this makes the lexer robust against
|
---|
3249 | // user-programmer bugs such as https://github.com/zaach/jison-lex/issues/19
|
---|
3250 | if (!spec || !spec.rules) {
|
---|
3251 | var lineno_msg = '';
|
---|
3252 |
|
---|
3253 | if (this.options.trackPosition) {
|
---|
3254 | lineno_msg = ' on line ' + (this.yylineno + 1);
|
---|
3255 | }
|
---|
3256 |
|
---|
3257 | var p = this.constructLexErrorInfo(
|
---|
3258 | 'Internal lexer engine error' + lineno_msg + ': The lex grammar programmer pushed a non-existing condition name "' + this.topState() + '"; this is a fatal error and should be reported to the application programmer team!',
|
---|
3259 | false
|
---|
3260 | );
|
---|
3261 |
|
---|
3262 | // produce one 'error' token until this situation has been resolved, most probably by parse termination!
|
---|
3263 | return this.parseError(p.errStr, p, this.JisonLexerError) || this.ERROR;
|
---|
3264 | }
|
---|
3265 | }
|
---|
3266 |
|
---|
3267 | var rule_ids = spec.rules;
|
---|
3268 | var regexes = spec.__rule_regexes;
|
---|
3269 | var len = spec.__rule_count;
|
---|
3270 |
|
---|
3271 | // Note: the arrays are 1-based, while `len` itself is a valid index,
|
---|
3272 | // hence the non-standard less-or-equal check in the next loop condition!
|
---|
3273 | for (var i = 1; i <= len; i++) {
|
---|
3274 | tempMatch = this._input.match(regexes[i]);
|
---|
3275 |
|
---|
3276 | if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
|
---|
3277 | match = tempMatch;
|
---|
3278 | index = i;
|
---|
3279 |
|
---|
3280 | if (this.options.backtrack_lexer) {
|
---|
3281 | token = this.test_match(tempMatch, rule_ids[i]);
|
---|
3282 |
|
---|
3283 | if (token !== false) {
|
---|
3284 | return token;
|
---|
3285 | } else if (this._backtrack) {
|
---|
3286 | match = undefined;
|
---|
3287 | continue; // rule action called reject() implying a rule MISmatch.
|
---|
3288 | } else {
|
---|
3289 | // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
|
---|
3290 | return false;
|
---|
3291 | }
|
---|
3292 | } else if (!this.options.flex) {
|
---|
3293 | break;
|
---|
3294 | }
|
---|
3295 | }
|
---|
3296 | }
|
---|
3297 |
|
---|
3298 | if (match) {
|
---|
3299 | token = this.test_match(match, rule_ids[index]);
|
---|
3300 |
|
---|
3301 | if (token !== false) {
|
---|
3302 | return token;
|
---|
3303 | }
|
---|
3304 |
|
---|
3305 | // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
|
---|
3306 | return false;
|
---|
3307 | }
|
---|
3308 |
|
---|
3309 | if (!this._input) {
|
---|
3310 | this.done = true;
|
---|
3311 | this.clear();
|
---|
3312 | return this.EOF;
|
---|
3313 | } else {
|
---|
3314 | var lineno_msg = '';
|
---|
3315 |
|
---|
3316 | if (this.options.trackPosition) {
|
---|
3317 | lineno_msg = ' on line ' + (this.yylineno + 1);
|
---|
3318 | }
|
---|
3319 |
|
---|
3320 | var p = this.constructLexErrorInfo(
|
---|
3321 | 'Lexical error' + lineno_msg + ': Unrecognized text.',
|
---|
3322 | this.options.lexerErrorsAreRecoverable
|
---|
3323 | );
|
---|
3324 |
|
---|
3325 | var pendingInput = this._input;
|
---|
3326 | var activeCondition = this.topState();
|
---|
3327 | var conditionStackDepth = this.conditionStack.length;
|
---|
3328 | token = this.parseError(p.errStr, p, this.JisonLexerError) || this.ERROR;
|
---|
3329 |
|
---|
3330 | if (token === this.ERROR) {
|
---|
3331 | // we can try to recover from a lexer error that `parseError()` did not 'recover' for us
|
---|
3332 | // by moving forward at least one character at a time IFF the (user-specified?) `parseError()`
|
---|
3333 | // has not consumed/modified any pending input or changed state in the error handler:
|
---|
3334 | if (!this.matches && // and make sure the input has been modified/consumed ...
|
---|
3335 | pendingInput === this._input && // ...or the lexer state has been modified significantly enough
|
---|
3336 | // to merit a non-consuming error handling action right now.
|
---|
3337 | activeCondition === this.topState() && conditionStackDepth === this.conditionStack.length) {
|
---|
3338 | this.input();
|
---|
3339 | }
|
---|
3340 | }
|
---|
3341 |
|
---|
3342 | return token;
|
---|
3343 | }
|
---|
3344 | },
|
---|
3345 |
|
---|
3346 | /**
|
---|
3347 | * return next match that has a token
|
---|
3348 | *
|
---|
3349 | * @public
|
---|
3350 | * @this {RegExpLexer}
|
---|
3351 | */
|
---|
3352 | lex: function lexer_lex() {
|
---|
3353 | var r;
|
---|
3354 |
|
---|
3355 | // allow the PRE/POST handlers set/modify the return token for maximum flexibility of the generated lexer:
|
---|
3356 | if (typeof this.pre_lex === 'function') {
|
---|
3357 | r = this.pre_lex.call(this, 0);
|
---|
3358 | }
|
---|
3359 |
|
---|
3360 | if (typeof this.options.pre_lex === 'function') {
|
---|
3361 | // (also account for a userdef function which does not return any value: keep the token as is)
|
---|
3362 | r = this.options.pre_lex.call(this, r) || r;
|
---|
3363 | }
|
---|
3364 |
|
---|
3365 | if (this.yy && typeof this.yy.pre_lex === 'function') {
|
---|
3366 | // (also account for a userdef function which does not return any value: keep the token as is)
|
---|
3367 | r = this.yy.pre_lex.call(this, r) || r;
|
---|
3368 | }
|
---|
3369 |
|
---|
3370 | while (!r) {
|
---|
3371 | r = this.next();
|
---|
3372 | }
|
---|
3373 |
|
---|
3374 | if (this.yy && typeof this.yy.post_lex === 'function') {
|
---|
3375 | // (also account for a userdef function which does not return any value: keep the token as is)
|
---|
3376 | r = this.yy.post_lex.call(this, r) || r;
|
---|
3377 | }
|
---|
3378 |
|
---|
3379 | if (typeof this.options.post_lex === 'function') {
|
---|
3380 | // (also account for a userdef function which does not return any value: keep the token as is)
|
---|
3381 | r = this.options.post_lex.call(this, r) || r;
|
---|
3382 | }
|
---|
3383 |
|
---|
3384 | if (typeof this.post_lex === 'function') {
|
---|
3385 | // (also account for a userdef function which does not return any value: keep the token as is)
|
---|
3386 | r = this.post_lex.call(this, r) || r;
|
---|
3387 | }
|
---|
3388 |
|
---|
3389 | return r;
|
---|
3390 | },
|
---|
3391 |
|
---|
3392 | /**
|
---|
3393 | * return next match that has a token. Identical to the `lex()` API but does not invoke any of the
|
---|
3394 | * `pre_lex()` nor any of the `post_lex()` callbacks.
|
---|
3395 | *
|
---|
3396 | * @public
|
---|
3397 | * @this {RegExpLexer}
|
---|
3398 | */
|
---|
3399 | fastLex: function lexer_fastLex() {
|
---|
3400 | var r;
|
---|
3401 |
|
---|
3402 | while (!r) {
|
---|
3403 | r = this.next();
|
---|
3404 | }
|
---|
3405 |
|
---|
3406 | return r;
|
---|
3407 | },
|
---|
3408 |
|
---|
3409 | /**
|
---|
3410 | * return info about the lexer state that can help a parser or other lexer API user to use the
|
---|
3411 | * most efficient means available. This API is provided to aid run-time performance for larger
|
---|
3412 | * systems which employ this lexer.
|
---|
3413 | *
|
---|
3414 | * @public
|
---|
3415 | * @this {RegExpLexer}
|
---|
3416 | */
|
---|
3417 | canIUse: function lexer_canIUse() {
|
---|
3418 | var rv = {
|
---|
3419 | fastLex: !(typeof this.pre_lex === 'function' || typeof this.options.pre_lex === 'function' || this.yy && typeof this.yy.pre_lex === 'function' || this.yy && typeof this.yy.post_lex === 'function' || typeof this.options.post_lex === 'function' || typeof this.post_lex === 'function') && typeof this.fastLex === 'function'
|
---|
3420 | };
|
---|
3421 |
|
---|
3422 | return rv;
|
---|
3423 | },
|
---|
3424 |
|
---|
3425 | /**
|
---|
3426 | * backwards compatible alias for `pushState()`;
|
---|
3427 | * the latter is symmetrical with `popState()` and we advise to use
|
---|
3428 | * those APIs in any modern lexer code, rather than `begin()`.
|
---|
3429 | *
|
---|
3430 | * @public
|
---|
3431 | * @this {RegExpLexer}
|
---|
3432 | */
|
---|
3433 | begin: function lexer_begin(condition) {
|
---|
3434 | return this.pushState(condition);
|
---|
3435 | },
|
---|
3436 |
|
---|
3437 | /**
|
---|
3438 | * activates a new lexer condition state (pushes the new lexer
|
---|
3439 | * condition state onto the condition stack)
|
---|
3440 | *
|
---|
3441 | * @public
|
---|
3442 | * @this {RegExpLexer}
|
---|
3443 | */
|
---|
3444 | pushState: function lexer_pushState(condition) {
|
---|
3445 | this.conditionStack.push(condition);
|
---|
3446 | this.__currentRuleSet__ = null;
|
---|
3447 | return this;
|
---|
3448 | },
|
---|
3449 |
|
---|
3450 | /**
|
---|
3451 | * pop the previously active lexer condition state off the condition
|
---|
3452 | * stack
|
---|
3453 | *
|
---|
3454 | * @public
|
---|
3455 | * @this {RegExpLexer}
|
---|
3456 | */
|
---|
3457 | popState: function lexer_popState() {
|
---|
3458 | var n = this.conditionStack.length - 1;
|
---|
3459 |
|
---|
3460 | if (n > 0) {
|
---|
3461 | this.__currentRuleSet__ = null;
|
---|
3462 | return this.conditionStack.pop();
|
---|
3463 | } else {
|
---|
3464 | return this.conditionStack[0];
|
---|
3465 | }
|
---|
3466 | },
|
---|
3467 |
|
---|
3468 | /**
|
---|
3469 | * return the currently active lexer condition state; when an index
|
---|
3470 | * argument is provided it produces the N-th previous condition state,
|
---|
3471 | * if available
|
---|
3472 | *
|
---|
3473 | * @public
|
---|
3474 | * @this {RegExpLexer}
|
---|
3475 | */
|
---|
3476 | topState: function lexer_topState(n) {
|
---|
3477 | n = this.conditionStack.length - 1 - Math.abs(n || 0);
|
---|
3478 |
|
---|
3479 | if (n >= 0) {
|
---|
3480 | return this.conditionStack[n];
|
---|
3481 | } else {
|
---|
3482 | return 'INITIAL';
|
---|
3483 | }
|
---|
3484 | },
|
---|
3485 |
|
---|
3486 | /**
|
---|
3487 | * (internal) determine the lexer rule set which is active for the
|
---|
3488 | * currently active lexer condition state
|
---|
3489 | *
|
---|
3490 | * @public
|
---|
3491 | * @this {RegExpLexer}
|
---|
3492 | */
|
---|
3493 | _currentRules: function lexer__currentRules() {
|
---|
3494 | if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
|
---|
3495 | return this.conditions[this.conditionStack[this.conditionStack.length - 1]];
|
---|
3496 | } else {
|
---|
3497 | return this.conditions['INITIAL'];
|
---|
3498 | }
|
---|
3499 | },
|
---|
3500 |
|
---|
3501 | /**
|
---|
3502 | * return the number of states currently on the stack
|
---|
3503 | *
|
---|
3504 | * @public
|
---|
3505 | * @this {RegExpLexer}
|
---|
3506 | */
|
---|
3507 | stateStackSize: function lexer_stateStackSize() {
|
---|
3508 | return this.conditionStack.length;
|
---|
3509 | },
|
---|
3510 |
|
---|
3511 | options: {
|
---|
3512 | trackPosition: true,
|
---|
3513 | caseInsensitive: true
|
---|
3514 | },
|
---|
3515 |
|
---|
3516 | JisonLexerError: JisonLexerError,
|
---|
3517 |
|
---|
3518 | performAction: function lexer__performAction(yy, yyrulenumber, YY_START) {
|
---|
3519 | var yy_ = this;
|
---|
3520 | var YYSTATE = YY_START;
|
---|
3521 |
|
---|
3522 | switch (yyrulenumber) {
|
---|
3523 | case 0:
|
---|
3524 | /*! Conditions:: INITIAL */
|
---|
3525 | /*! Rule:: \s+ */
|
---|
3526 | /* skip whitespace */
|
---|
3527 | break;
|
---|
3528 |
|
---|
3529 | default:
|
---|
3530 | return this.simpleCaseActionClusters[yyrulenumber];
|
---|
3531 | }
|
---|
3532 | },
|
---|
3533 |
|
---|
3534 | simpleCaseActionClusters: {
|
---|
3535 | /*! Conditions:: INITIAL */
|
---|
3536 | /*! Rule:: (-(webkit|moz)-)?calc\b */
|
---|
3537 | 1: 3,
|
---|
3538 |
|
---|
3539 | /*! Conditions:: INITIAL */
|
---|
3540 | /*! Rule:: [a-z][a-z0-9-]*\s*\((?:(?:"(?:\\.|[^\"\\])*"|'(?:\\.|[^\'\\])*')|\([^)]*\)|[^\(\)]*)*\) */
|
---|
3541 | 2: 10,
|
---|
3542 |
|
---|
3543 | /*! Conditions:: INITIAL */
|
---|
3544 | /*! Rule:: \* */
|
---|
3545 | 3: 8,
|
---|
3546 |
|
---|
3547 | /*! Conditions:: INITIAL */
|
---|
3548 | /*! Rule:: \/ */
|
---|
3549 | 4: 9,
|
---|
3550 |
|
---|
3551 | /*! Conditions:: INITIAL */
|
---|
3552 | /*! Rule:: \+ */
|
---|
3553 | 5: 6,
|
---|
3554 |
|
---|
3555 | /*! Conditions:: INITIAL */
|
---|
3556 | /*! Rule:: - */
|
---|
3557 | 6: 7,
|
---|
3558 |
|
---|
3559 | /*! Conditions:: INITIAL */
|
---|
3560 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)em\b */
|
---|
3561 | 7: 17,
|
---|
3562 |
|
---|
3563 | /*! Conditions:: INITIAL */
|
---|
3564 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)ex\b */
|
---|
3565 | 8: 18,
|
---|
3566 |
|
---|
3567 | /*! Conditions:: INITIAL */
|
---|
3568 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)ch\b */
|
---|
3569 | 9: 19,
|
---|
3570 |
|
---|
3571 | /*! Conditions:: INITIAL */
|
---|
3572 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)rem\b */
|
---|
3573 | 10: 20,
|
---|
3574 |
|
---|
3575 | /*! Conditions:: INITIAL */
|
---|
3576 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)vw\b */
|
---|
3577 | 11: 22,
|
---|
3578 |
|
---|
3579 | /*! Conditions:: INITIAL */
|
---|
3580 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)vh\b */
|
---|
3581 | 12: 21,
|
---|
3582 |
|
---|
3583 | /*! Conditions:: INITIAL */
|
---|
3584 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)vmin\b */
|
---|
3585 | 13: 23,
|
---|
3586 |
|
---|
3587 | /*! Conditions:: INITIAL */
|
---|
3588 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)vmax\b */
|
---|
3589 | 14: 24,
|
---|
3590 |
|
---|
3591 | /*! Conditions:: INITIAL */
|
---|
3592 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)cm\b */
|
---|
3593 | 15: 11,
|
---|
3594 |
|
---|
3595 | /*! Conditions:: INITIAL */
|
---|
3596 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)mm\b */
|
---|
3597 | 16: 11,
|
---|
3598 |
|
---|
3599 | /*! Conditions:: INITIAL */
|
---|
3600 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)Q\b */
|
---|
3601 | 17: 11,
|
---|
3602 |
|
---|
3603 | /*! Conditions:: INITIAL */
|
---|
3604 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)in\b */
|
---|
3605 | 18: 11,
|
---|
3606 |
|
---|
3607 | /*! Conditions:: INITIAL */
|
---|
3608 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)pt\b */
|
---|
3609 | 19: 11,
|
---|
3610 |
|
---|
3611 | /*! Conditions:: INITIAL */
|
---|
3612 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)pc\b */
|
---|
3613 | 20: 11,
|
---|
3614 |
|
---|
3615 | /*! Conditions:: INITIAL */
|
---|
3616 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)px\b */
|
---|
3617 | 21: 11,
|
---|
3618 |
|
---|
3619 | /*! Conditions:: INITIAL */
|
---|
3620 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)deg\b */
|
---|
3621 | 22: 12,
|
---|
3622 |
|
---|
3623 | /*! Conditions:: INITIAL */
|
---|
3624 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)grad\b */
|
---|
3625 | 23: 12,
|
---|
3626 |
|
---|
3627 | /*! Conditions:: INITIAL */
|
---|
3628 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)rad\b */
|
---|
3629 | 24: 12,
|
---|
3630 |
|
---|
3631 | /*! Conditions:: INITIAL */
|
---|
3632 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)turn\b */
|
---|
3633 | 25: 12,
|
---|
3634 |
|
---|
3635 | /*! Conditions:: INITIAL */
|
---|
3636 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)s\b */
|
---|
3637 | 26: 13,
|
---|
3638 |
|
---|
3639 | /*! Conditions:: INITIAL */
|
---|
3640 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)ms\b */
|
---|
3641 | 27: 13,
|
---|
3642 |
|
---|
3643 | /*! Conditions:: INITIAL */
|
---|
3644 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)Hz\b */
|
---|
3645 | 28: 14,
|
---|
3646 |
|
---|
3647 | /*! Conditions:: INITIAL */
|
---|
3648 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)kHz\b */
|
---|
3649 | 29: 14,
|
---|
3650 |
|
---|
3651 | /*! Conditions:: INITIAL */
|
---|
3652 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)dpi\b */
|
---|
3653 | 30: 15,
|
---|
3654 |
|
---|
3655 | /*! Conditions:: INITIAL */
|
---|
3656 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)dpcm\b */
|
---|
3657 | 31: 15,
|
---|
3658 |
|
---|
3659 | /*! Conditions:: INITIAL */
|
---|
3660 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)dppx\b */
|
---|
3661 | 32: 15,
|
---|
3662 |
|
---|
3663 | /*! Conditions:: INITIAL */
|
---|
3664 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)% */
|
---|
3665 | 33: 25,
|
---|
3666 |
|
---|
3667 | /*! Conditions:: INITIAL */
|
---|
3668 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)\b */
|
---|
3669 | 34: 26,
|
---|
3670 |
|
---|
3671 | /*! Conditions:: INITIAL */
|
---|
3672 | /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)-?([a-zA-Z_]|[\240-\377]|(\\[0-9a-fA-F]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-fA-F]))([a-zA-Z0-9_-]|[\240-\377]|(\\[0-9a-fA-F]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-fA-F]))*\b */
|
---|
3673 | 35: 16,
|
---|
3674 |
|
---|
3675 | /*! Conditions:: INITIAL */
|
---|
3676 | /*! Rule:: \( */
|
---|
3677 | 36: 4,
|
---|
3678 |
|
---|
3679 | /*! Conditions:: INITIAL */
|
---|
3680 | /*! Rule:: \) */
|
---|
3681 | 37: 5,
|
---|
3682 |
|
---|
3683 | /*! Conditions:: INITIAL */
|
---|
3684 | /*! Rule:: $ */
|
---|
3685 | 38: 1
|
---|
3686 | },
|
---|
3687 |
|
---|
3688 | rules: [
|
---|
3689 | /* 0: */ /^(?:\s+)/i,
|
---|
3690 | /* 1: */ /^(?:(-(webkit|moz)-)?calc\b)/i,
|
---|
3691 | /* 2: */ /^(?:[a-z][\d\-a-z]*\s*\((?:(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')|\([^)]*\)|[^()]*)*\))/i,
|
---|
3692 | /* 3: */ /^(?:\*)/i,
|
---|
3693 | /* 4: */ /^(?:\/)/i,
|
---|
3694 | /* 5: */ /^(?:\+)/i,
|
---|
3695 | /* 6: */ /^(?:-)/i,
|
---|
3696 | /* 7: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)em\b)/i,
|
---|
3697 | /* 8: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)ex\b)/i,
|
---|
3698 | /* 9: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)ch\b)/i,
|
---|
3699 | /* 10: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)rem\b)/i,
|
---|
3700 | /* 11: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)vw\b)/i,
|
---|
3701 | /* 12: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)vh\b)/i,
|
---|
3702 | /* 13: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)vmin\b)/i,
|
---|
3703 | /* 14: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)vmax\b)/i,
|
---|
3704 | /* 15: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)cm\b)/i,
|
---|
3705 | /* 16: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)mm\b)/i,
|
---|
3706 | /* 17: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)Q\b)/i,
|
---|
3707 | /* 18: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)in\b)/i,
|
---|
3708 | /* 19: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)pt\b)/i,
|
---|
3709 | /* 20: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)pc\b)/i,
|
---|
3710 | /* 21: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)px\b)/i,
|
---|
3711 | /* 22: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)deg\b)/i,
|
---|
3712 | /* 23: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)grad\b)/i,
|
---|
3713 | /* 24: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)rad\b)/i,
|
---|
3714 | /* 25: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)turn\b)/i,
|
---|
3715 | /* 26: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)s\b)/i,
|
---|
3716 | /* 27: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)ms\b)/i,
|
---|
3717 | /* 28: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)Hz\b)/i,
|
---|
3718 | /* 29: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)kHz\b)/i,
|
---|
3719 | /* 30: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)dpi\b)/i,
|
---|
3720 | /* 31: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)dpcm\b)/i,
|
---|
3721 | /* 32: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)dppx\b)/i,
|
---|
3722 | /* 33: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)%)/i,
|
---|
3723 | /* 34: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)\b)/i,
|
---|
3724 | /* 35: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)-?([^\W\d]|[ -ÿ]|(\\[\dA-Fa-f]{1,6}(\r\n|[\t\n\f\r ])?|\\[^\d\n\f\rA-Fa-f]))([\w\-]|[ -ÿ]|(\\[\dA-Fa-f]{1,6}(\r\n|[\t\n\f\r ])?|\\[^\d\n\f\rA-Fa-f]))*\b)/i,
|
---|
3725 | /* 36: */ /^(?:\()/i,
|
---|
3726 | /* 37: */ /^(?:\))/i,
|
---|
3727 | /* 38: */ /^(?:$)/i
|
---|
3728 | ],
|
---|
3729 |
|
---|
3730 | conditions: {
|
---|
3731 | 'INITIAL': {
|
---|
3732 | rules: [
|
---|
3733 | 0,
|
---|
3734 | 1,
|
---|
3735 | 2,
|
---|
3736 | 3,
|
---|
3737 | 4,
|
---|
3738 | 5,
|
---|
3739 | 6,
|
---|
3740 | 7,
|
---|
3741 | 8,
|
---|
3742 | 9,
|
---|
3743 | 10,
|
---|
3744 | 11,
|
---|
3745 | 12,
|
---|
3746 | 13,
|
---|
3747 | 14,
|
---|
3748 | 15,
|
---|
3749 | 16,
|
---|
3750 | 17,
|
---|
3751 | 18,
|
---|
3752 | 19,
|
---|
3753 | 20,
|
---|
3754 | 21,
|
---|
3755 | 22,
|
---|
3756 | 23,
|
---|
3757 | 24,
|
---|
3758 | 25,
|
---|
3759 | 26,
|
---|
3760 | 27,
|
---|
3761 | 28,
|
---|
3762 | 29,
|
---|
3763 | 30,
|
---|
3764 | 31,
|
---|
3765 | 32,
|
---|
3766 | 33,
|
---|
3767 | 34,
|
---|
3768 | 35,
|
---|
3769 | 36,
|
---|
3770 | 37,
|
---|
3771 | 38
|
---|
3772 | ],
|
---|
3773 |
|
---|
3774 | inclusive: true
|
---|
3775 | }
|
---|
3776 | }
|
---|
3777 | };
|
---|
3778 |
|
---|
3779 | return lexer;
|
---|
3780 | }();
|
---|
3781 | parser.lexer = lexer;
|
---|
3782 |
|
---|
3783 |
|
---|
3784 |
|
---|
3785 | function Parser() {
|
---|
3786 | this.yy = {};
|
---|
3787 | }
|
---|
3788 | Parser.prototype = parser;
|
---|
3789 | parser.Parser = Parser;
|
---|
3790 |
|
---|
3791 | return new Parser();
|
---|
3792 | })();
|
---|
3793 |
|
---|
3794 |
|
---|
3795 |
|
---|
3796 |
|
---|
3797 | if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
|
---|
3798 | exports.parser = parser;
|
---|
3799 | exports.Parser = parser.Parser;
|
---|
3800 | exports.parse = function () {
|
---|
3801 | return parser.parse.apply(parser, arguments);
|
---|
3802 | };
|
---|
3803 |
|
---|
3804 | }
|
---|