parser.js 26 KB

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