Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

parser.js 73KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673
  1. var result = (function(){
  2. /*
  3. * Generated by PEG.js 0.7.0.
  4. *
  5. * http://pegjs.majda.cz/
  6. */
  7. function quote(s) {
  8. /*
  9. * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
  10. * string literal except for the closing quote character, backslash,
  11. * carriage return, line separator, paragraph separator, and line feed.
  12. * Any character may appear in the form of an escape sequence.
  13. *
  14. * For portability, we also escape escape all control and non-ASCII
  15. * characters. Note that "\0" and "\v" escape sequences are not used
  16. * because JSHint does not like the first and IE the second.
  17. */
  18. return '"' + s
  19. .replace(/\\/g, '\\\\') // backslash
  20. .replace(/"/g, '\\"') // closing quote character
  21. .replace(/\x08/g, '\\b') // backspace
  22. .replace(/\t/g, '\\t') // horizontal tab
  23. .replace(/\n/g, '\\n') // line feed
  24. .replace(/\f/g, '\\f') // form feed
  25. .replace(/\r/g, '\\r') // carriage return
  26. .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape)
  27. + '"';
  28. }
  29. var result = {
  30. /*
  31. * Parses the input with a generated parser. If the parsing is successfull,
  32. * returns a value explicitly or implicitly specified by the grammar from
  33. * which the parser was generated (see |PEG.buildParser|). If the parsing is
  34. * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
  35. */
  36. parse: function(input, startRule) {
  37. var parseFunctions = {
  38. "start": parse_start,
  39. "_": parse__,
  40. "identifierName": parse_identifierName,
  41. "binaryOp": parse_binaryOp,
  42. "selectors": parse_selectors,
  43. "selector": parse_selector,
  44. "sequence": parse_sequence,
  45. "atom": parse_atom,
  46. "wildcard": parse_wildcard,
  47. "identifier": parse_identifier,
  48. "attr": parse_attr,
  49. "attrOps": parse_attrOps,
  50. "attrEqOps": parse_attrEqOps,
  51. "attrName": parse_attrName,
  52. "attrValue": parse_attrValue,
  53. "string": parse_string,
  54. "number": parse_number,
  55. "path": parse_path,
  56. "type": parse_type,
  57. "regex": parse_regex,
  58. "field": parse_field,
  59. "negation": parse_negation,
  60. "matches": parse_matches,
  61. "has": parse_has,
  62. "firstChild": parse_firstChild,
  63. "lastChild": parse_lastChild,
  64. "nthChild": parse_nthChild,
  65. "nthLastChild": parse_nthLastChild,
  66. "class": parse_class
  67. };
  68. if (startRule !== undefined) {
  69. if (parseFunctions[startRule] === undefined) {
  70. throw new Error("Invalid rule name: " + quote(startRule) + ".");
  71. }
  72. } else {
  73. startRule = "start";
  74. }
  75. var pos = 0;
  76. var reportFailures = 0;
  77. var rightmostFailuresPos = 0;
  78. var rightmostFailuresExpected = [];
  79. var cache = {};
  80. function padLeft(input, padding, length) {
  81. var result = input;
  82. var padLength = length - input.length;
  83. for (var i = 0; i < padLength; i++) {
  84. result = padding + result;
  85. }
  86. return result;
  87. }
  88. function escape(ch) {
  89. var charCode = ch.charCodeAt(0);
  90. var escapeChar;
  91. var length;
  92. if (charCode <= 0xFF) {
  93. escapeChar = 'x';
  94. length = 2;
  95. } else {
  96. escapeChar = 'u';
  97. length = 4;
  98. }
  99. return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
  100. }
  101. function matchFailed(failure) {
  102. if (pos < rightmostFailuresPos) {
  103. return;
  104. }
  105. if (pos > rightmostFailuresPos) {
  106. rightmostFailuresPos = pos;
  107. rightmostFailuresExpected = [];
  108. }
  109. rightmostFailuresExpected.push(failure);
  110. }
  111. function parse_start() {
  112. var cacheKey = "start@" + pos;
  113. var cachedResult = cache[cacheKey];
  114. if (cachedResult) {
  115. pos = cachedResult.nextPos;
  116. return cachedResult.result;
  117. }
  118. var result0, result1, result2;
  119. var pos0, pos1;
  120. pos0 = pos;
  121. pos1 = pos;
  122. result0 = parse__();
  123. if (result0 !== null) {
  124. result1 = parse_selectors();
  125. if (result1 !== null) {
  126. result2 = parse__();
  127. if (result2 !== null) {
  128. result0 = [result0, result1, result2];
  129. } else {
  130. result0 = null;
  131. pos = pos1;
  132. }
  133. } else {
  134. result0 = null;
  135. pos = pos1;
  136. }
  137. } else {
  138. result0 = null;
  139. pos = pos1;
  140. }
  141. if (result0 !== null) {
  142. result0 = (function(offset, ss) { return ss.length === 1 ? ss[0] : { type: 'matches', selectors: ss }; })(pos0, result0[1]);
  143. }
  144. if (result0 === null) {
  145. pos = pos0;
  146. }
  147. if (result0 === null) {
  148. pos0 = pos;
  149. result0 = parse__();
  150. if (result0 !== null) {
  151. result0 = (function(offset) { return void 0; })(pos0);
  152. }
  153. if (result0 === null) {
  154. pos = pos0;
  155. }
  156. }
  157. cache[cacheKey] = {
  158. nextPos: pos,
  159. result: result0
  160. };
  161. return result0;
  162. }
  163. function parse__() {
  164. var cacheKey = "_@" + pos;
  165. var cachedResult = cache[cacheKey];
  166. if (cachedResult) {
  167. pos = cachedResult.nextPos;
  168. return cachedResult.result;
  169. }
  170. var result0, result1;
  171. result0 = [];
  172. if (input.charCodeAt(pos) === 32) {
  173. result1 = " ";
  174. pos++;
  175. } else {
  176. result1 = null;
  177. if (reportFailures === 0) {
  178. matchFailed("\" \"");
  179. }
  180. }
  181. while (result1 !== null) {
  182. result0.push(result1);
  183. if (input.charCodeAt(pos) === 32) {
  184. result1 = " ";
  185. pos++;
  186. } else {
  187. result1 = null;
  188. if (reportFailures === 0) {
  189. matchFailed("\" \"");
  190. }
  191. }
  192. }
  193. cache[cacheKey] = {
  194. nextPos: pos,
  195. result: result0
  196. };
  197. return result0;
  198. }
  199. function parse_identifierName() {
  200. var cacheKey = "identifierName@" + pos;
  201. var cachedResult = cache[cacheKey];
  202. if (cachedResult) {
  203. pos = cachedResult.nextPos;
  204. return cachedResult.result;
  205. }
  206. var result0, result1;
  207. var pos0;
  208. pos0 = pos;
  209. if (/^[^ [\],():#!=><~+.]/.test(input.charAt(pos))) {
  210. result1 = input.charAt(pos);
  211. pos++;
  212. } else {
  213. result1 = null;
  214. if (reportFailures === 0) {
  215. matchFailed("[^ [\\],():#!=><~+.]");
  216. }
  217. }
  218. if (result1 !== null) {
  219. result0 = [];
  220. while (result1 !== null) {
  221. result0.push(result1);
  222. if (/^[^ [\],():#!=><~+.]/.test(input.charAt(pos))) {
  223. result1 = input.charAt(pos);
  224. pos++;
  225. } else {
  226. result1 = null;
  227. if (reportFailures === 0) {
  228. matchFailed("[^ [\\],():#!=><~+.]");
  229. }
  230. }
  231. }
  232. } else {
  233. result0 = null;
  234. }
  235. if (result0 !== null) {
  236. result0 = (function(offset, i) { return i.join(''); })(pos0, result0);
  237. }
  238. if (result0 === null) {
  239. pos = pos0;
  240. }
  241. cache[cacheKey] = {
  242. nextPos: pos,
  243. result: result0
  244. };
  245. return result0;
  246. }
  247. function parse_binaryOp() {
  248. var cacheKey = "binaryOp@" + pos;
  249. var cachedResult = cache[cacheKey];
  250. if (cachedResult) {
  251. pos = cachedResult.nextPos;
  252. return cachedResult.result;
  253. }
  254. var result0, result1, result2;
  255. var pos0, pos1;
  256. pos0 = pos;
  257. pos1 = pos;
  258. result0 = parse__();
  259. if (result0 !== null) {
  260. if (input.charCodeAt(pos) === 62) {
  261. result1 = ">";
  262. pos++;
  263. } else {
  264. result1 = null;
  265. if (reportFailures === 0) {
  266. matchFailed("\">\"");
  267. }
  268. }
  269. if (result1 !== null) {
  270. result2 = parse__();
  271. if (result2 !== null) {
  272. result0 = [result0, result1, result2];
  273. } else {
  274. result0 = null;
  275. pos = pos1;
  276. }
  277. } else {
  278. result0 = null;
  279. pos = pos1;
  280. }
  281. } else {
  282. result0 = null;
  283. pos = pos1;
  284. }
  285. if (result0 !== null) {
  286. result0 = (function(offset) { return 'child'; })(pos0);
  287. }
  288. if (result0 === null) {
  289. pos = pos0;
  290. }
  291. if (result0 === null) {
  292. pos0 = pos;
  293. pos1 = pos;
  294. result0 = parse__();
  295. if (result0 !== null) {
  296. if (input.charCodeAt(pos) === 126) {
  297. result1 = "~";
  298. pos++;
  299. } else {
  300. result1 = null;
  301. if (reportFailures === 0) {
  302. matchFailed("\"~\"");
  303. }
  304. }
  305. if (result1 !== null) {
  306. result2 = parse__();
  307. if (result2 !== null) {
  308. result0 = [result0, result1, result2];
  309. } else {
  310. result0 = null;
  311. pos = pos1;
  312. }
  313. } else {
  314. result0 = null;
  315. pos = pos1;
  316. }
  317. } else {
  318. result0 = null;
  319. pos = pos1;
  320. }
  321. if (result0 !== null) {
  322. result0 = (function(offset) { return 'sibling'; })(pos0);
  323. }
  324. if (result0 === null) {
  325. pos = pos0;
  326. }
  327. if (result0 === null) {
  328. pos0 = pos;
  329. pos1 = pos;
  330. result0 = parse__();
  331. if (result0 !== null) {
  332. if (input.charCodeAt(pos) === 43) {
  333. result1 = "+";
  334. pos++;
  335. } else {
  336. result1 = null;
  337. if (reportFailures === 0) {
  338. matchFailed("\"+\"");
  339. }
  340. }
  341. if (result1 !== null) {
  342. result2 = parse__();
  343. if (result2 !== null) {
  344. result0 = [result0, result1, result2];
  345. } else {
  346. result0 = null;
  347. pos = pos1;
  348. }
  349. } else {
  350. result0 = null;
  351. pos = pos1;
  352. }
  353. } else {
  354. result0 = null;
  355. pos = pos1;
  356. }
  357. if (result0 !== null) {
  358. result0 = (function(offset) { return 'adjacent'; })(pos0);
  359. }
  360. if (result0 === null) {
  361. pos = pos0;
  362. }
  363. if (result0 === null) {
  364. pos0 = pos;
  365. pos1 = pos;
  366. if (input.charCodeAt(pos) === 32) {
  367. result0 = " ";
  368. pos++;
  369. } else {
  370. result0 = null;
  371. if (reportFailures === 0) {
  372. matchFailed("\" \"");
  373. }
  374. }
  375. if (result0 !== null) {
  376. result1 = parse__();
  377. if (result1 !== null) {
  378. result0 = [result0, result1];
  379. } else {
  380. result0 = null;
  381. pos = pos1;
  382. }
  383. } else {
  384. result0 = null;
  385. pos = pos1;
  386. }
  387. if (result0 !== null) {
  388. result0 = (function(offset) { return 'descendant'; })(pos0);
  389. }
  390. if (result0 === null) {
  391. pos = pos0;
  392. }
  393. }
  394. }
  395. }
  396. cache[cacheKey] = {
  397. nextPos: pos,
  398. result: result0
  399. };
  400. return result0;
  401. }
  402. function parse_selectors() {
  403. var cacheKey = "selectors@" + pos;
  404. var cachedResult = cache[cacheKey];
  405. if (cachedResult) {
  406. pos = cachedResult.nextPos;
  407. return cachedResult.result;
  408. }
  409. var result0, result1, result2, result3, result4, result5;
  410. var pos0, pos1, pos2;
  411. pos0 = pos;
  412. pos1 = pos;
  413. result0 = parse_selector();
  414. if (result0 !== null) {
  415. result1 = [];
  416. pos2 = pos;
  417. result2 = parse__();
  418. if (result2 !== null) {
  419. if (input.charCodeAt(pos) === 44) {
  420. result3 = ",";
  421. pos++;
  422. } else {
  423. result3 = null;
  424. if (reportFailures === 0) {
  425. matchFailed("\",\"");
  426. }
  427. }
  428. if (result3 !== null) {
  429. result4 = parse__();
  430. if (result4 !== null) {
  431. result5 = parse_selector();
  432. if (result5 !== null) {
  433. result2 = [result2, result3, result4, result5];
  434. } else {
  435. result2 = null;
  436. pos = pos2;
  437. }
  438. } else {
  439. result2 = null;
  440. pos = pos2;
  441. }
  442. } else {
  443. result2 = null;
  444. pos = pos2;
  445. }
  446. } else {
  447. result2 = null;
  448. pos = pos2;
  449. }
  450. while (result2 !== null) {
  451. result1.push(result2);
  452. pos2 = pos;
  453. result2 = parse__();
  454. if (result2 !== null) {
  455. if (input.charCodeAt(pos) === 44) {
  456. result3 = ",";
  457. pos++;
  458. } else {
  459. result3 = null;
  460. if (reportFailures === 0) {
  461. matchFailed("\",\"");
  462. }
  463. }
  464. if (result3 !== null) {
  465. result4 = parse__();
  466. if (result4 !== null) {
  467. result5 = parse_selector();
  468. if (result5 !== null) {
  469. result2 = [result2, result3, result4, result5];
  470. } else {
  471. result2 = null;
  472. pos = pos2;
  473. }
  474. } else {
  475. result2 = null;
  476. pos = pos2;
  477. }
  478. } else {
  479. result2 = null;
  480. pos = pos2;
  481. }
  482. } else {
  483. result2 = null;
  484. pos = pos2;
  485. }
  486. }
  487. if (result1 !== null) {
  488. result0 = [result0, result1];
  489. } else {
  490. result0 = null;
  491. pos = pos1;
  492. }
  493. } else {
  494. result0 = null;
  495. pos = pos1;
  496. }
  497. if (result0 !== null) {
  498. result0 = (function(offset, s, ss) {
  499. return [s].concat(ss.map(function (s) { return s[3]; }));
  500. })(pos0, result0[0], result0[1]);
  501. }
  502. if (result0 === null) {
  503. pos = pos0;
  504. }
  505. cache[cacheKey] = {
  506. nextPos: pos,
  507. result: result0
  508. };
  509. return result0;
  510. }
  511. function parse_selector() {
  512. var cacheKey = "selector@" + pos;
  513. var cachedResult = cache[cacheKey];
  514. if (cachedResult) {
  515. pos = cachedResult.nextPos;
  516. return cachedResult.result;
  517. }
  518. var result0, result1, result2, result3;
  519. var pos0, pos1, pos2;
  520. pos0 = pos;
  521. pos1 = pos;
  522. result0 = parse_sequence();
  523. if (result0 !== null) {
  524. result1 = [];
  525. pos2 = pos;
  526. result2 = parse_binaryOp();
  527. if (result2 !== null) {
  528. result3 = parse_sequence();
  529. if (result3 !== null) {
  530. result2 = [result2, result3];
  531. } else {
  532. result2 = null;
  533. pos = pos2;
  534. }
  535. } else {
  536. result2 = null;
  537. pos = pos2;
  538. }
  539. while (result2 !== null) {
  540. result1.push(result2);
  541. pos2 = pos;
  542. result2 = parse_binaryOp();
  543. if (result2 !== null) {
  544. result3 = parse_sequence();
  545. if (result3 !== null) {
  546. result2 = [result2, result3];
  547. } else {
  548. result2 = null;
  549. pos = pos2;
  550. }
  551. } else {
  552. result2 = null;
  553. pos = pos2;
  554. }
  555. }
  556. if (result1 !== null) {
  557. result0 = [result0, result1];
  558. } else {
  559. result0 = null;
  560. pos = pos1;
  561. }
  562. } else {
  563. result0 = null;
  564. pos = pos1;
  565. }
  566. if (result0 !== null) {
  567. result0 = (function(offset, a, ops) {
  568. return ops.reduce(function (memo, rhs) {
  569. return { type: rhs[0], left: memo, right: rhs[1] };
  570. }, a);
  571. })(pos0, result0[0], result0[1]);
  572. }
  573. if (result0 === null) {
  574. pos = pos0;
  575. }
  576. cache[cacheKey] = {
  577. nextPos: pos,
  578. result: result0
  579. };
  580. return result0;
  581. }
  582. function parse_sequence() {
  583. var cacheKey = "sequence@" + pos;
  584. var cachedResult = cache[cacheKey];
  585. if (cachedResult) {
  586. pos = cachedResult.nextPos;
  587. return cachedResult.result;
  588. }
  589. var result0, result1, result2;
  590. var pos0, pos1;
  591. pos0 = pos;
  592. pos1 = pos;
  593. if (input.charCodeAt(pos) === 33) {
  594. result0 = "!";
  595. pos++;
  596. } else {
  597. result0 = null;
  598. if (reportFailures === 0) {
  599. matchFailed("\"!\"");
  600. }
  601. }
  602. result0 = result0 !== null ? result0 : "";
  603. if (result0 !== null) {
  604. result2 = parse_atom();
  605. if (result2 !== null) {
  606. result1 = [];
  607. while (result2 !== null) {
  608. result1.push(result2);
  609. result2 = parse_atom();
  610. }
  611. } else {
  612. result1 = null;
  613. }
  614. if (result1 !== null) {
  615. result0 = [result0, result1];
  616. } else {
  617. result0 = null;
  618. pos = pos1;
  619. }
  620. } else {
  621. result0 = null;
  622. pos = pos1;
  623. }
  624. if (result0 !== null) {
  625. result0 = (function(offset, subject, as) {
  626. var b = as.length === 1 ? as[0] : { type: 'compound', selectors: as };
  627. if(subject) b.subject = true;
  628. return b;
  629. })(pos0, result0[0], result0[1]);
  630. }
  631. if (result0 === null) {
  632. pos = pos0;
  633. }
  634. cache[cacheKey] = {
  635. nextPos: pos,
  636. result: result0
  637. };
  638. return result0;
  639. }
  640. function parse_atom() {
  641. var cacheKey = "atom@" + pos;
  642. var cachedResult = cache[cacheKey];
  643. if (cachedResult) {
  644. pos = cachedResult.nextPos;
  645. return cachedResult.result;
  646. }
  647. var result0;
  648. result0 = parse_wildcard();
  649. if (result0 === null) {
  650. result0 = parse_identifier();
  651. if (result0 === null) {
  652. result0 = parse_attr();
  653. if (result0 === null) {
  654. result0 = parse_field();
  655. if (result0 === null) {
  656. result0 = parse_negation();
  657. if (result0 === null) {
  658. result0 = parse_matches();
  659. if (result0 === null) {
  660. result0 = parse_has();
  661. if (result0 === null) {
  662. result0 = parse_firstChild();
  663. if (result0 === null) {
  664. result0 = parse_lastChild();
  665. if (result0 === null) {
  666. result0 = parse_nthChild();
  667. if (result0 === null) {
  668. result0 = parse_nthLastChild();
  669. if (result0 === null) {
  670. result0 = parse_class();
  671. }
  672. }
  673. }
  674. }
  675. }
  676. }
  677. }
  678. }
  679. }
  680. }
  681. }
  682. cache[cacheKey] = {
  683. nextPos: pos,
  684. result: result0
  685. };
  686. return result0;
  687. }
  688. function parse_wildcard() {
  689. var cacheKey = "wildcard@" + pos;
  690. var cachedResult = cache[cacheKey];
  691. if (cachedResult) {
  692. pos = cachedResult.nextPos;
  693. return cachedResult.result;
  694. }
  695. var result0;
  696. var pos0;
  697. pos0 = pos;
  698. if (input.charCodeAt(pos) === 42) {
  699. result0 = "*";
  700. pos++;
  701. } else {
  702. result0 = null;
  703. if (reportFailures === 0) {
  704. matchFailed("\"*\"");
  705. }
  706. }
  707. if (result0 !== null) {
  708. result0 = (function(offset, a) { return { type: 'wildcard', value: a }; })(pos0, result0);
  709. }
  710. if (result0 === null) {
  711. pos = pos0;
  712. }
  713. cache[cacheKey] = {
  714. nextPos: pos,
  715. result: result0
  716. };
  717. return result0;
  718. }
  719. function parse_identifier() {
  720. var cacheKey = "identifier@" + pos;
  721. var cachedResult = cache[cacheKey];
  722. if (cachedResult) {
  723. pos = cachedResult.nextPos;
  724. return cachedResult.result;
  725. }
  726. var result0, result1;
  727. var pos0, pos1;
  728. pos0 = pos;
  729. pos1 = pos;
  730. if (input.charCodeAt(pos) === 35) {
  731. result0 = "#";
  732. pos++;
  733. } else {
  734. result0 = null;
  735. if (reportFailures === 0) {
  736. matchFailed("\"#\"");
  737. }
  738. }
  739. result0 = result0 !== null ? result0 : "";
  740. if (result0 !== null) {
  741. result1 = parse_identifierName();
  742. if (result1 !== null) {
  743. result0 = [result0, result1];
  744. } else {
  745. result0 = null;
  746. pos = pos1;
  747. }
  748. } else {
  749. result0 = null;
  750. pos = pos1;
  751. }
  752. if (result0 !== null) {
  753. result0 = (function(offset, i) { return { type: 'identifier', value: i }; })(pos0, result0[1]);
  754. }
  755. if (result0 === null) {
  756. pos = pos0;
  757. }
  758. cache[cacheKey] = {
  759. nextPos: pos,
  760. result: result0
  761. };
  762. return result0;
  763. }
  764. function parse_attr() {
  765. var cacheKey = "attr@" + pos;
  766. var cachedResult = cache[cacheKey];
  767. if (cachedResult) {
  768. pos = cachedResult.nextPos;
  769. return cachedResult.result;
  770. }
  771. var result0, result1, result2, result3, result4;
  772. var pos0, pos1;
  773. pos0 = pos;
  774. pos1 = pos;
  775. if (input.charCodeAt(pos) === 91) {
  776. result0 = "[";
  777. pos++;
  778. } else {
  779. result0 = null;
  780. if (reportFailures === 0) {
  781. matchFailed("\"[\"");
  782. }
  783. }
  784. if (result0 !== null) {
  785. result1 = parse__();
  786. if (result1 !== null) {
  787. result2 = parse_attrValue();
  788. if (result2 !== null) {
  789. result3 = parse__();
  790. if (result3 !== null) {
  791. if (input.charCodeAt(pos) === 93) {
  792. result4 = "]";
  793. pos++;
  794. } else {
  795. result4 = null;
  796. if (reportFailures === 0) {
  797. matchFailed("\"]\"");
  798. }
  799. }
  800. if (result4 !== null) {
  801. result0 = [result0, result1, result2, result3, result4];
  802. } else {
  803. result0 = null;
  804. pos = pos1;
  805. }
  806. } else {
  807. result0 = null;
  808. pos = pos1;
  809. }
  810. } else {
  811. result0 = null;
  812. pos = pos1;
  813. }
  814. } else {
  815. result0 = null;
  816. pos = pos1;
  817. }
  818. } else {
  819. result0 = null;
  820. pos = pos1;
  821. }
  822. if (result0 !== null) {
  823. result0 = (function(offset, v) { return v; })(pos0, result0[2]);
  824. }
  825. if (result0 === null) {
  826. pos = pos0;
  827. }
  828. cache[cacheKey] = {
  829. nextPos: pos,
  830. result: result0
  831. };
  832. return result0;
  833. }
  834. function parse_attrOps() {
  835. var cacheKey = "attrOps@" + pos;
  836. var cachedResult = cache[cacheKey];
  837. if (cachedResult) {
  838. pos = cachedResult.nextPos;
  839. return cachedResult.result;
  840. }
  841. var result0, result1;
  842. var pos0, pos1;
  843. pos0 = pos;
  844. pos1 = pos;
  845. if (/^[><!]/.test(input.charAt(pos))) {
  846. result0 = input.charAt(pos);
  847. pos++;
  848. } else {
  849. result0 = null;
  850. if (reportFailures === 0) {
  851. matchFailed("[><!]");
  852. }
  853. }
  854. result0 = result0 !== null ? result0 : "";
  855. if (result0 !== null) {
  856. if (input.charCodeAt(pos) === 61) {
  857. result1 = "=";
  858. pos++;
  859. } else {
  860. result1 = null;
  861. if (reportFailures === 0) {
  862. matchFailed("\"=\"");
  863. }
  864. }
  865. if (result1 !== null) {
  866. result0 = [result0, result1];
  867. } else {
  868. result0 = null;
  869. pos = pos1;
  870. }
  871. } else {
  872. result0 = null;
  873. pos = pos1;
  874. }
  875. if (result0 !== null) {
  876. result0 = (function(offset, a) { return a + '='; })(pos0, result0[0]);
  877. }
  878. if (result0 === null) {
  879. pos = pos0;
  880. }
  881. if (result0 === null) {
  882. if (/^[><]/.test(input.charAt(pos))) {
  883. result0 = input.charAt(pos);
  884. pos++;
  885. } else {
  886. result0 = null;
  887. if (reportFailures === 0) {
  888. matchFailed("[><]");
  889. }
  890. }
  891. }
  892. cache[cacheKey] = {
  893. nextPos: pos,
  894. result: result0
  895. };
  896. return result0;
  897. }
  898. function parse_attrEqOps() {
  899. var cacheKey = "attrEqOps@" + pos;
  900. var cachedResult = cache[cacheKey];
  901. if (cachedResult) {
  902. pos = cachedResult.nextPos;
  903. return cachedResult.result;
  904. }
  905. var result0, result1;
  906. var pos0, pos1;
  907. pos0 = pos;
  908. pos1 = pos;
  909. if (input.charCodeAt(pos) === 33) {
  910. result0 = "!";
  911. pos++;
  912. } else {
  913. result0 = null;
  914. if (reportFailures === 0) {
  915. matchFailed("\"!\"");
  916. }
  917. }
  918. result0 = result0 !== null ? result0 : "";
  919. if (result0 !== null) {
  920. if (input.charCodeAt(pos) === 61) {
  921. result1 = "=";
  922. pos++;
  923. } else {
  924. result1 = null;
  925. if (reportFailures === 0) {
  926. matchFailed("\"=\"");
  927. }
  928. }
  929. if (result1 !== null) {
  930. result0 = [result0, result1];
  931. } else {
  932. result0 = null;
  933. pos = pos1;
  934. }
  935. } else {
  936. result0 = null;
  937. pos = pos1;
  938. }
  939. if (result0 !== null) {
  940. result0 = (function(offset, a) { return a + '='; })(pos0, result0[0]);
  941. }
  942. if (result0 === null) {
  943. pos = pos0;
  944. }
  945. cache[cacheKey] = {
  946. nextPos: pos,
  947. result: result0
  948. };
  949. return result0;
  950. }
  951. function parse_attrName() {
  952. var cacheKey = "attrName@" + pos;
  953. var cachedResult = cache[cacheKey];
  954. if (cachedResult) {
  955. pos = cachedResult.nextPos;
  956. return cachedResult.result;
  957. }
  958. var result0, result1;
  959. var pos0;
  960. pos0 = pos;
  961. result1 = parse_identifierName();
  962. if (result1 === null) {
  963. if (input.charCodeAt(pos) === 46) {
  964. result1 = ".";
  965. pos++;
  966. } else {
  967. result1 = null;
  968. if (reportFailures === 0) {
  969. matchFailed("\".\"");
  970. }
  971. }
  972. }
  973. if (result1 !== null) {
  974. result0 = [];
  975. while (result1 !== null) {
  976. result0.push(result1);
  977. result1 = parse_identifierName();
  978. if (result1 === null) {
  979. if (input.charCodeAt(pos) === 46) {
  980. result1 = ".";
  981. pos++;
  982. } else {
  983. result1 = null;
  984. if (reportFailures === 0) {
  985. matchFailed("\".\"");
  986. }
  987. }
  988. }
  989. }
  990. } else {
  991. result0 = null;
  992. }
  993. if (result0 !== null) {
  994. result0 = (function(offset, i) { return i.join(''); })(pos0, result0);
  995. }
  996. if (result0 === null) {
  997. pos = pos0;
  998. }
  999. cache[cacheKey] = {
  1000. nextPos: pos,
  1001. result: result0
  1002. };
  1003. return result0;
  1004. }
  1005. function parse_attrValue() {
  1006. var cacheKey = "attrValue@" + pos;
  1007. var cachedResult = cache[cacheKey];
  1008. if (cachedResult) {
  1009. pos = cachedResult.nextPos;
  1010. return cachedResult.result;
  1011. }
  1012. var result0, result1, result2, result3, result4;
  1013. var pos0, pos1;
  1014. pos0 = pos;
  1015. pos1 = pos;
  1016. result0 = parse_attrName();
  1017. if (result0 !== null) {
  1018. result1 = parse__();
  1019. if (result1 !== null) {
  1020. result2 = parse_attrEqOps();
  1021. if (result2 !== null) {
  1022. result3 = parse__();
  1023. if (result3 !== null) {
  1024. result4 = parse_type();
  1025. if (result4 === null) {
  1026. result4 = parse_regex();
  1027. }
  1028. if (result4 !== null) {
  1029. result0 = [result0, result1, result2, result3, result4];
  1030. } else {
  1031. result0 = null;
  1032. pos = pos1;
  1033. }
  1034. } else {
  1035. result0 = null;
  1036. pos = pos1;
  1037. }
  1038. } else {
  1039. result0 = null;
  1040. pos = pos1;
  1041. }
  1042. } else {
  1043. result0 = null;
  1044. pos = pos1;
  1045. }
  1046. } else {
  1047. result0 = null;
  1048. pos = pos1;
  1049. }
  1050. if (result0 !== null) {
  1051. result0 = (function(offset, name, op, value) {
  1052. return { type: 'attribute', name: name, operator: op, value: value };
  1053. })(pos0, result0[0], result0[2], result0[4]);
  1054. }
  1055. if (result0 === null) {
  1056. pos = pos0;
  1057. }
  1058. if (result0 === null) {
  1059. pos0 = pos;
  1060. pos1 = pos;
  1061. result0 = parse_attrName();
  1062. if (result0 !== null) {
  1063. result1 = parse__();
  1064. if (result1 !== null) {
  1065. result2 = parse_attrOps();
  1066. if (result2 !== null) {
  1067. result3 = parse__();
  1068. if (result3 !== null) {
  1069. result4 = parse_string();
  1070. if (result4 === null) {
  1071. result4 = parse_number();
  1072. if (result4 === null) {
  1073. result4 = parse_path();
  1074. }
  1075. }
  1076. if (result4 !== null) {
  1077. result0 = [result0, result1, result2, result3, result4];
  1078. } else {
  1079. result0 = null;
  1080. pos = pos1;
  1081. }
  1082. } else {
  1083. result0 = null;
  1084. pos = pos1;
  1085. }
  1086. } else {
  1087. result0 = null;
  1088. pos = pos1;
  1089. }
  1090. } else {
  1091. result0 = null;
  1092. pos = pos1;
  1093. }
  1094. } else {
  1095. result0 = null;
  1096. pos = pos1;
  1097. }
  1098. if (result0 !== null) {
  1099. result0 = (function(offset, name, op, value) {
  1100. return { type: 'attribute', name: name, operator: op, value: value };
  1101. })(pos0, result0[0], result0[2], result0[4]);
  1102. }
  1103. if (result0 === null) {
  1104. pos = pos0;
  1105. }
  1106. if (result0 === null) {
  1107. pos0 = pos;
  1108. result0 = parse_attrName();
  1109. if (result0 !== null) {
  1110. result0 = (function(offset, name) { return { type: 'attribute', name: name }; })(pos0, result0);
  1111. }
  1112. if (result0 === null) {
  1113. pos = pos0;
  1114. }
  1115. }
  1116. }
  1117. cache[cacheKey] = {
  1118. nextPos: pos,
  1119. result: result0
  1120. };
  1121. return result0;
  1122. }
  1123. function parse_string() {
  1124. var cacheKey = "string@" + pos;
  1125. var cachedResult = cache[cacheKey];
  1126. if (cachedResult) {
  1127. pos = cachedResult.nextPos;
  1128. return cachedResult.result;
  1129. }
  1130. var result0, result1, result2, result3;
  1131. var pos0, pos1, pos2, pos3;
  1132. pos0 = pos;
  1133. pos1 = pos;
  1134. if (input.charCodeAt(pos) === 34) {
  1135. result0 = "\"";
  1136. pos++;
  1137. } else {
  1138. result0 = null;
  1139. if (reportFailures === 0) {
  1140. matchFailed("\"\\\"\"");
  1141. }
  1142. }
  1143. if (result0 !== null) {
  1144. result1 = [];
  1145. if (/^[^\\"]/.test(input.charAt(pos))) {
  1146. result2 = input.charAt(pos);
  1147. pos++;
  1148. } else {
  1149. result2 = null;
  1150. if (reportFailures === 0) {
  1151. matchFailed("[^\\\\\"]");
  1152. }
  1153. }
  1154. if (result2 === null) {
  1155. pos2 = pos;
  1156. pos3 = pos;
  1157. if (input.charCodeAt(pos) === 92) {
  1158. result2 = "\\";
  1159. pos++;
  1160. } else {
  1161. result2 = null;
  1162. if (reportFailures === 0) {
  1163. matchFailed("\"\\\\\"");
  1164. }
  1165. }
  1166. if (result2 !== null) {
  1167. if (input.length > pos) {
  1168. result3 = input.charAt(pos);
  1169. pos++;
  1170. } else {
  1171. result3 = null;
  1172. if (reportFailures === 0) {
  1173. matchFailed("any character");
  1174. }
  1175. }
  1176. if (result3 !== null) {
  1177. result2 = [result2, result3];
  1178. } else {
  1179. result2 = null;
  1180. pos = pos3;
  1181. }
  1182. } else {
  1183. result2 = null;
  1184. pos = pos3;
  1185. }
  1186. if (result2 !== null) {
  1187. result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]);
  1188. }
  1189. if (result2 === null) {
  1190. pos = pos2;
  1191. }
  1192. }
  1193. while (result2 !== null) {
  1194. result1.push(result2);
  1195. if (/^[^\\"]/.test(input.charAt(pos))) {
  1196. result2 = input.charAt(pos);
  1197. pos++;
  1198. } else {
  1199. result2 = null;
  1200. if (reportFailures === 0) {
  1201. matchFailed("[^\\\\\"]");
  1202. }
  1203. }
  1204. if (result2 === null) {
  1205. pos2 = pos;
  1206. pos3 = pos;
  1207. if (input.charCodeAt(pos) === 92) {
  1208. result2 = "\\";
  1209. pos++;
  1210. } else {
  1211. result2 = null;
  1212. if (reportFailures === 0) {
  1213. matchFailed("\"\\\\\"");
  1214. }
  1215. }
  1216. if (result2 !== null) {
  1217. if (input.length > pos) {
  1218. result3 = input.charAt(pos);
  1219. pos++;
  1220. } else {
  1221. result3 = null;
  1222. if (reportFailures === 0) {
  1223. matchFailed("any character");
  1224. }
  1225. }
  1226. if (result3 !== null) {
  1227. result2 = [result2, result3];
  1228. } else {
  1229. result2 = null;
  1230. pos = pos3;
  1231. }
  1232. } else {
  1233. result2 = null;
  1234. pos = pos3;
  1235. }
  1236. if (result2 !== null) {
  1237. result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]);
  1238. }
  1239. if (result2 === null) {
  1240. pos = pos2;
  1241. }
  1242. }
  1243. }
  1244. if (result1 !== null) {
  1245. if (input.charCodeAt(pos) === 34) {
  1246. result2 = "\"";
  1247. pos++;
  1248. } else {
  1249. result2 = null;
  1250. if (reportFailures === 0) {
  1251. matchFailed("\"\\\"\"");
  1252. }
  1253. }
  1254. if (result2 !== null) {
  1255. result0 = [result0, result1, result2];
  1256. } else {
  1257. result0 = null;
  1258. pos = pos1;
  1259. }
  1260. } else {
  1261. result0 = null;
  1262. pos = pos1;
  1263. }
  1264. } else {
  1265. result0 = null;
  1266. pos = pos1;
  1267. }
  1268. if (result0 !== null) {
  1269. result0 = (function(offset, d) {
  1270. return { type: 'literal', value: strUnescape(d.join('')) };
  1271. })(pos0, result0[1]);
  1272. }
  1273. if (result0 === null) {
  1274. pos = pos0;
  1275. }
  1276. if (result0 === null) {
  1277. pos0 = pos;
  1278. pos1 = pos;
  1279. if (input.charCodeAt(pos) === 39) {
  1280. result0 = "'";
  1281. pos++;
  1282. } else {
  1283. result0 = null;
  1284. if (reportFailures === 0) {
  1285. matchFailed("\"'\"");
  1286. }
  1287. }
  1288. if (result0 !== null) {
  1289. result1 = [];
  1290. if (/^[^\\']/.test(input.charAt(pos))) {
  1291. result2 = input.charAt(pos);
  1292. pos++;
  1293. } else {
  1294. result2 = null;
  1295. if (reportFailures === 0) {
  1296. matchFailed("[^\\\\']");
  1297. }
  1298. }
  1299. if (result2 === null) {
  1300. pos2 = pos;
  1301. pos3 = pos;
  1302. if (input.charCodeAt(pos) === 92) {
  1303. result2 = "\\";
  1304. pos++;
  1305. } else {
  1306. result2 = null;
  1307. if (reportFailures === 0) {
  1308. matchFailed("\"\\\\\"");
  1309. }
  1310. }
  1311. if (result2 !== null) {
  1312. if (input.length > pos) {
  1313. result3 = input.charAt(pos);
  1314. pos++;
  1315. } else {
  1316. result3 = null;
  1317. if (reportFailures === 0) {
  1318. matchFailed("any character");
  1319. }
  1320. }
  1321. if (result3 !== null) {
  1322. result2 = [result2, result3];
  1323. } else {
  1324. result2 = null;
  1325. pos = pos3;
  1326. }
  1327. } else {
  1328. result2 = null;
  1329. pos = pos3;
  1330. }
  1331. if (result2 !== null) {
  1332. result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]);
  1333. }
  1334. if (result2 === null) {
  1335. pos = pos2;
  1336. }
  1337. }
  1338. while (result2 !== null) {
  1339. result1.push(result2);
  1340. if (/^[^\\']/.test(input.charAt(pos))) {
  1341. result2 = input.charAt(pos);
  1342. pos++;
  1343. } else {
  1344. result2 = null;
  1345. if (reportFailures === 0) {
  1346. matchFailed("[^\\\\']");
  1347. }
  1348. }
  1349. if (result2 === null) {
  1350. pos2 = pos;
  1351. pos3 = pos;
  1352. if (input.charCodeAt(pos) === 92) {
  1353. result2 = "\\";
  1354. pos++;
  1355. } else {
  1356. result2 = null;
  1357. if (reportFailures === 0) {
  1358. matchFailed("\"\\\\\"");
  1359. }
  1360. }
  1361. if (result2 !== null) {
  1362. if (input.length > pos) {
  1363. result3 = input.charAt(pos);
  1364. pos++;
  1365. } else {
  1366. result3 = null;
  1367. if (reportFailures === 0) {
  1368. matchFailed("any character");
  1369. }
  1370. }
  1371. if (result3 !== null) {
  1372. result2 = [result2, result3];
  1373. } else {
  1374. result2 = null;
  1375. pos = pos3;
  1376. }
  1377. } else {
  1378. result2 = null;
  1379. pos = pos3;
  1380. }
  1381. if (result2 !== null) {
  1382. result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]);
  1383. }
  1384. if (result2 === null) {
  1385. pos = pos2;
  1386. }
  1387. }
  1388. }
  1389. if (result1 !== null) {
  1390. if (input.charCodeAt(pos) === 39) {
  1391. result2 = "'";
  1392. pos++;
  1393. } else {
  1394. result2 = null;
  1395. if (reportFailures === 0) {
  1396. matchFailed("\"'\"");
  1397. }
  1398. }
  1399. if (result2 !== null) {
  1400. result0 = [result0, result1, result2];
  1401. } else {
  1402. result0 = null;
  1403. pos = pos1;
  1404. }
  1405. } else {
  1406. result0 = null;
  1407. pos = pos1;
  1408. }
  1409. } else {
  1410. result0 = null;
  1411. pos = pos1;
  1412. }
  1413. if (result0 !== null) {
  1414. result0 = (function(offset, d) {
  1415. return { type: 'literal', value: strUnescape(d.join('')) };
  1416. })(pos0, result0[1]);
  1417. }
  1418. if (result0 === null) {
  1419. pos = pos0;
  1420. }
  1421. }
  1422. cache[cacheKey] = {
  1423. nextPos: pos,
  1424. result: result0
  1425. };
  1426. return result0;
  1427. }
  1428. function parse_number() {
  1429. var cacheKey = "number@" + pos;
  1430. var cachedResult = cache[cacheKey];
  1431. if (cachedResult) {
  1432. pos = cachedResult.nextPos;
  1433. return cachedResult.result;
  1434. }
  1435. var result0, result1, result2;
  1436. var pos0, pos1, pos2;
  1437. pos0 = pos;
  1438. pos1 = pos;
  1439. pos2 = pos;
  1440. result0 = [];
  1441. if (/^[0-9]/.test(input.charAt(pos))) {
  1442. result1 = input.charAt(pos);
  1443. pos++;
  1444. } else {
  1445. result1 = null;
  1446. if (reportFailures === 0) {
  1447. matchFailed("[0-9]");
  1448. }
  1449. }
  1450. while (result1 !== null) {
  1451. result0.push(result1);
  1452. if (/^[0-9]/.test(input.charAt(pos))) {
  1453. result1 = input.charAt(pos);
  1454. pos++;
  1455. } else {
  1456. result1 = null;
  1457. if (reportFailures === 0) {
  1458. matchFailed("[0-9]");
  1459. }
  1460. }
  1461. }
  1462. if (result0 !== null) {
  1463. if (input.charCodeAt(pos) === 46) {
  1464. result1 = ".";
  1465. pos++;
  1466. } else {
  1467. result1 = null;
  1468. if (reportFailures === 0) {
  1469. matchFailed("\".\"");
  1470. }
  1471. }
  1472. if (result1 !== null) {
  1473. result0 = [result0, result1];
  1474. } else {
  1475. result0 = null;
  1476. pos = pos2;
  1477. }
  1478. } else {
  1479. result0 = null;
  1480. pos = pos2;
  1481. }
  1482. result0 = result0 !== null ? result0 : "";
  1483. if (result0 !== null) {
  1484. if (/^[0-9]/.test(input.charAt(pos))) {
  1485. result2 = input.charAt(pos);
  1486. pos++;
  1487. } else {
  1488. result2 = null;
  1489. if (reportFailures === 0) {
  1490. matchFailed("[0-9]");
  1491. }
  1492. }
  1493. if (result2 !== null) {
  1494. result1 = [];
  1495. while (result2 !== null) {
  1496. result1.push(result2);
  1497. if (/^[0-9]/.test(input.charAt(pos))) {
  1498. result2 = input.charAt(pos);
  1499. pos++;
  1500. } else {
  1501. result2 = null;
  1502. if (reportFailures === 0) {
  1503. matchFailed("[0-9]");
  1504. }
  1505. }
  1506. }
  1507. } else {
  1508. result1 = null;
  1509. }
  1510. if (result1 !== null) {
  1511. result0 = [result0, result1];
  1512. } else {
  1513. result0 = null;
  1514. pos = pos1;
  1515. }
  1516. } else {
  1517. result0 = null;
  1518. pos = pos1;
  1519. }
  1520. if (result0 !== null) {
  1521. result0 = (function(offset, a, b) {
  1522. return { type: 'literal', value: parseFloat((a ? a.join('') : '') + b.join('')) };
  1523. })(pos0, result0[0], result0[1]);
  1524. }
  1525. if (result0 === null) {
  1526. pos = pos0;
  1527. }
  1528. cache[cacheKey] = {
  1529. nextPos: pos,
  1530. result: result0
  1531. };
  1532. return result0;
  1533. }
  1534. function parse_path() {
  1535. var cacheKey = "path@" + pos;
  1536. var cachedResult = cache[cacheKey];
  1537. if (cachedResult) {
  1538. pos = cachedResult.nextPos;
  1539. return cachedResult.result;
  1540. }
  1541. var result0;
  1542. var pos0;
  1543. pos0 = pos;
  1544. result0 = parse_identifierName();
  1545. if (result0 !== null) {
  1546. result0 = (function(offset, i) { return { type: 'literal', value: i }; })(pos0, result0);
  1547. }
  1548. if (result0 === null) {
  1549. pos = pos0;
  1550. }
  1551. cache[cacheKey] = {
  1552. nextPos: pos,
  1553. result: result0
  1554. };
  1555. return result0;
  1556. }
  1557. function parse_type() {
  1558. var cacheKey = "type@" + pos;
  1559. var cachedResult = cache[cacheKey];
  1560. if (cachedResult) {
  1561. pos = cachedResult.nextPos;
  1562. return cachedResult.result;
  1563. }
  1564. var result0, result1, result2, result3, result4;
  1565. var pos0, pos1;
  1566. pos0 = pos;
  1567. pos1 = pos;
  1568. if (input.substr(pos, 5) === "type(") {
  1569. result0 = "type(";
  1570. pos += 5;
  1571. } else {
  1572. result0 = null;
  1573. if (reportFailures === 0) {
  1574. matchFailed("\"type(\"");
  1575. }
  1576. }
  1577. if (result0 !== null) {
  1578. result1 = parse__();
  1579. if (result1 !== null) {
  1580. if (/^[^ )]/.test(input.charAt(pos))) {
  1581. result3 = input.charAt(pos);
  1582. pos++;
  1583. } else {
  1584. result3 = null;
  1585. if (reportFailures === 0) {
  1586. matchFailed("[^ )]");
  1587. }
  1588. }
  1589. if (result3 !== null) {
  1590. result2 = [];
  1591. while (result3 !== null) {
  1592. result2.push(result3);
  1593. if (/^[^ )]/.test(input.charAt(pos))) {
  1594. result3 = input.charAt(pos);
  1595. pos++;
  1596. } else {
  1597. result3 = null;
  1598. if (reportFailures === 0) {
  1599. matchFailed("[^ )]");
  1600. }
  1601. }
  1602. }
  1603. } else {
  1604. result2 = null;
  1605. }
  1606. if (result2 !== null) {
  1607. result3 = parse__();
  1608. if (result3 !== null) {
  1609. if (input.charCodeAt(pos) === 41) {
  1610. result4 = ")";
  1611. pos++;
  1612. } else {
  1613. result4 = null;
  1614. if (reportFailures === 0) {
  1615. matchFailed("\")\"");
  1616. }
  1617. }
  1618. if (result4 !== null) {
  1619. result0 = [result0, result1, result2, result3, result4];
  1620. } else {
  1621. result0 = null;
  1622. pos = pos1;
  1623. }
  1624. } else {
  1625. result0 = null;
  1626. pos = pos1;
  1627. }
  1628. } else {
  1629. result0 = null;
  1630. pos = pos1;
  1631. }
  1632. } else {
  1633. result0 = null;
  1634. pos = pos1;
  1635. }
  1636. } else {
  1637. result0 = null;
  1638. pos = pos1;
  1639. }
  1640. if (result0 !== null) {
  1641. result0 = (function(offset, t) { return { type: 'type', value: t.join('') }; })(pos0, result0[2]);
  1642. }
  1643. if (result0 === null) {
  1644. pos = pos0;
  1645. }
  1646. cache[cacheKey] = {
  1647. nextPos: pos,
  1648. result: result0
  1649. };
  1650. return result0;
  1651. }
  1652. function parse_regex() {
  1653. var cacheKey = "regex@" + pos;
  1654. var cachedResult = cache[cacheKey];
  1655. if (cachedResult) {
  1656. pos = cachedResult.nextPos;
  1657. return cachedResult.result;
  1658. }
  1659. var result0, result1, result2;
  1660. var pos0, pos1;
  1661. pos0 = pos;
  1662. pos1 = pos;
  1663. if (input.charCodeAt(pos) === 47) {
  1664. result0 = "/";
  1665. pos++;
  1666. } else {
  1667. result0 = null;
  1668. if (reportFailures === 0) {
  1669. matchFailed("\"/\"");
  1670. }
  1671. }
  1672. if (result0 !== null) {
  1673. if (/^[^\/]/.test(input.charAt(pos))) {
  1674. result2 = input.charAt(pos);
  1675. pos++;
  1676. } else {
  1677. result2 = null;
  1678. if (reportFailures === 0) {
  1679. matchFailed("[^\\/]");
  1680. }
  1681. }
  1682. if (result2 !== null) {
  1683. result1 = [];
  1684. while (result2 !== null) {
  1685. result1.push(result2);
  1686. if (/^[^\/]/.test(input.charAt(pos))) {
  1687. result2 = input.charAt(pos);
  1688. pos++;
  1689. } else {
  1690. result2 = null;
  1691. if (reportFailures === 0) {
  1692. matchFailed("[^\\/]");
  1693. }
  1694. }
  1695. }
  1696. } else {
  1697. result1 = null;
  1698. }
  1699. if (result1 !== null) {
  1700. if (input.charCodeAt(pos) === 47) {
  1701. result2 = "/";
  1702. pos++;
  1703. } else {
  1704. result2 = null;
  1705. if (reportFailures === 0) {
  1706. matchFailed("\"/\"");
  1707. }
  1708. }
  1709. if (result2 !== null) {
  1710. result0 = [result0, result1, result2];
  1711. } else {
  1712. result0 = null;
  1713. pos = pos1;
  1714. }
  1715. } else {
  1716. result0 = null;
  1717. pos = pos1;
  1718. }
  1719. } else {
  1720. result0 = null;
  1721. pos = pos1;
  1722. }
  1723. if (result0 !== null) {
  1724. result0 = (function(offset, d) { return { type: 'regexp', value: new RegExp(d.join('')) }; })(pos0, result0[1]);
  1725. }
  1726. if (result0 === null) {
  1727. pos = pos0;
  1728. }
  1729. cache[cacheKey] = {
  1730. nextPos: pos,
  1731. result: result0
  1732. };
  1733. return result0;
  1734. }
  1735. function parse_field() {
  1736. var cacheKey = "field@" + pos;
  1737. var cachedResult = cache[cacheKey];
  1738. if (cachedResult) {
  1739. pos = cachedResult.nextPos;
  1740. return cachedResult.result;
  1741. }
  1742. var result0, result1, result2, result3, result4;
  1743. var pos0, pos1, pos2;
  1744. pos0 = pos;
  1745. pos1 = pos;
  1746. if (input.charCodeAt(pos) === 46) {
  1747. result0 = ".";
  1748. pos++;
  1749. } else {
  1750. result0 = null;
  1751. if (reportFailures === 0) {
  1752. matchFailed("\".\"");
  1753. }
  1754. }
  1755. if (result0 !== null) {
  1756. result1 = parse_identifierName();
  1757. if (result1 !== null) {
  1758. result2 = [];
  1759. pos2 = pos;
  1760. if (input.charCodeAt(pos) === 46) {
  1761. result3 = ".";
  1762. pos++;
  1763. } else {
  1764. result3 = null;
  1765. if (reportFailures === 0) {
  1766. matchFailed("\".\"");
  1767. }
  1768. }
  1769. if (result3 !== null) {
  1770. result4 = parse_identifierName();
  1771. if (result4 !== null) {
  1772. result3 = [result3, result4];
  1773. } else {
  1774. result3 = null;
  1775. pos = pos2;
  1776. }
  1777. } else {
  1778. result3 = null;
  1779. pos = pos2;
  1780. }
  1781. while (result3 !== null) {
  1782. result2.push(result3);
  1783. pos2 = pos;
  1784. if (input.charCodeAt(pos) === 46) {
  1785. result3 = ".";
  1786. pos++;
  1787. } else {
  1788. result3 = null;
  1789. if (reportFailures === 0) {
  1790. matchFailed("\".\"");
  1791. }
  1792. }
  1793. if (result3 !== null) {
  1794. result4 = parse_identifierName();
  1795. if (result4 !== null) {
  1796. result3 = [result3, result4];
  1797. } else {
  1798. result3 = null;
  1799. pos = pos2;
  1800. }
  1801. } else {
  1802. result3 = null;
  1803. pos = pos2;
  1804. }
  1805. }
  1806. if (result2 !== null) {
  1807. result0 = [result0, result1, result2];
  1808. } else {
  1809. result0 = null;
  1810. pos = pos1;
  1811. }
  1812. } else {
  1813. result0 = null;
  1814. pos = pos1;
  1815. }
  1816. } else {
  1817. result0 = null;
  1818. pos = pos1;
  1819. }
  1820. if (result0 !== null) {
  1821. result0 = (function(offset, i, is) {
  1822. return { type: 'field', name: is.reduce(function(memo, p){ return memo + p[0] + p[1]; }, i)};
  1823. })(pos0, result0[1], result0[2]);
  1824. }
  1825. if (result0 === null) {
  1826. pos = pos0;
  1827. }
  1828. cache[cacheKey] = {
  1829. nextPos: pos,
  1830. result: result0
  1831. };
  1832. return result0;
  1833. }
  1834. function parse_negation() {
  1835. var cacheKey = "negation@" + pos;
  1836. var cachedResult = cache[cacheKey];
  1837. if (cachedResult) {
  1838. pos = cachedResult.nextPos;
  1839. return cachedResult.result;
  1840. }
  1841. var result0, result1, result2, result3, result4;
  1842. var pos0, pos1;
  1843. pos0 = pos;
  1844. pos1 = pos;
  1845. if (input.substr(pos, 5) === ":not(") {
  1846. result0 = ":not(";
  1847. pos += 5;
  1848. } else {
  1849. result0 = null;
  1850. if (reportFailures === 0) {
  1851. matchFailed("\":not(\"");
  1852. }
  1853. }
  1854. if (result0 !== null) {
  1855. result1 = parse__();
  1856. if (result1 !== null) {
  1857. result2 = parse_selectors();
  1858. if (result2 !== null) {
  1859. result3 = parse__();
  1860. if (result3 !== null) {
  1861. if (input.charCodeAt(pos) === 41) {
  1862. result4 = ")";
  1863. pos++;
  1864. } else {
  1865. result4 = null;
  1866. if (reportFailures === 0) {
  1867. matchFailed("\")\"");
  1868. }
  1869. }
  1870. if (result4 !== null) {
  1871. result0 = [result0, result1, result2, result3, result4];
  1872. } else {
  1873. result0 = null;
  1874. pos = pos1;
  1875. }
  1876. } else {
  1877. result0 = null;
  1878. pos = pos1;
  1879. }
  1880. } else {
  1881. result0 = null;
  1882. pos = pos1;
  1883. }
  1884. } else {
  1885. result0 = null;
  1886. pos = pos1;
  1887. }
  1888. } else {
  1889. result0 = null;
  1890. pos = pos1;
  1891. }
  1892. if (result0 !== null) {
  1893. result0 = (function(offset, ss) { return { type: 'not', selectors: ss }; })(pos0, result0[2]);
  1894. }
  1895. if (result0 === null) {
  1896. pos = pos0;
  1897. }
  1898. cache[cacheKey] = {
  1899. nextPos: pos,
  1900. result: result0
  1901. };
  1902. return result0;
  1903. }
  1904. function parse_matches() {
  1905. var cacheKey = "matches@" + pos;
  1906. var cachedResult = cache[cacheKey];
  1907. if (cachedResult) {
  1908. pos = cachedResult.nextPos;
  1909. return cachedResult.result;
  1910. }
  1911. var result0, result1, result2, result3, result4;
  1912. var pos0, pos1;
  1913. pos0 = pos;
  1914. pos1 = pos;
  1915. if (input.substr(pos, 9) === ":matches(") {
  1916. result0 = ":matches(";
  1917. pos += 9;
  1918. } else {
  1919. result0 = null;
  1920. if (reportFailures === 0) {
  1921. matchFailed("\":matches(\"");
  1922. }
  1923. }
  1924. if (result0 !== null) {
  1925. result1 = parse__();
  1926. if (result1 !== null) {
  1927. result2 = parse_selectors();
  1928. if (result2 !== null) {
  1929. result3 = parse__();
  1930. if (result3 !== null) {
  1931. if (input.charCodeAt(pos) === 41) {
  1932. result4 = ")";
  1933. pos++;
  1934. } else {
  1935. result4 = null;
  1936. if (reportFailures === 0) {
  1937. matchFailed("\")\"");
  1938. }
  1939. }
  1940. if (result4 !== null) {
  1941. result0 = [result0, result1, result2, result3, result4];
  1942. } else {
  1943. result0 = null;
  1944. pos = pos1;
  1945. }
  1946. } else {
  1947. result0 = null;
  1948. pos = pos1;
  1949. }
  1950. } else {
  1951. result0 = null;
  1952. pos = pos1;
  1953. }
  1954. } else {
  1955. result0 = null;
  1956. pos = pos1;
  1957. }
  1958. } else {
  1959. result0 = null;
  1960. pos = pos1;
  1961. }
  1962. if (result0 !== null) {
  1963. result0 = (function(offset, ss) { return { type: 'matches', selectors: ss }; })(pos0, result0[2]);
  1964. }
  1965. if (result0 === null) {
  1966. pos = pos0;
  1967. }
  1968. cache[cacheKey] = {
  1969. nextPos: pos,
  1970. result: result0
  1971. };
  1972. return result0;
  1973. }
  1974. function parse_has() {
  1975. var cacheKey = "has@" + pos;
  1976. var cachedResult = cache[cacheKey];
  1977. if (cachedResult) {
  1978. pos = cachedResult.nextPos;
  1979. return cachedResult.result;
  1980. }
  1981. var result0, result1, result2, result3, result4;
  1982. var pos0, pos1;
  1983. pos0 = pos;
  1984. pos1 = pos;
  1985. if (input.substr(pos, 5) === ":has(") {
  1986. result0 = ":has(";
  1987. pos += 5;
  1988. } else {
  1989. result0 = null;
  1990. if (reportFailures === 0) {
  1991. matchFailed("\":has(\"");
  1992. }
  1993. }
  1994. if (result0 !== null) {
  1995. result1 = parse__();
  1996. if (result1 !== null) {
  1997. result2 = parse_selectors();
  1998. if (result2 !== null) {
  1999. result3 = parse__();
  2000. if (result3 !== null) {
  2001. if (input.charCodeAt(pos) === 41) {
  2002. result4 = ")";
  2003. pos++;
  2004. } else {
  2005. result4 = null;
  2006. if (reportFailures === 0) {
  2007. matchFailed("\")\"");
  2008. }
  2009. }
  2010. if (result4 !== null) {
  2011. result0 = [result0, result1, result2, result3, result4];
  2012. } else {
  2013. result0 = null;
  2014. pos = pos1;
  2015. }
  2016. } else {
  2017. result0 = null;
  2018. pos = pos1;
  2019. }
  2020. } else {
  2021. result0 = null;
  2022. pos = pos1;
  2023. }
  2024. } else {
  2025. result0 = null;
  2026. pos = pos1;
  2027. }
  2028. } else {
  2029. result0 = null;
  2030. pos = pos1;
  2031. }
  2032. if (result0 !== null) {
  2033. result0 = (function(offset, ss) { return { type: 'has', selectors: ss }; })(pos0, result0[2]);
  2034. }
  2035. if (result0 === null) {
  2036. pos = pos0;
  2037. }
  2038. cache[cacheKey] = {
  2039. nextPos: pos,
  2040. result: result0
  2041. };
  2042. return result0;
  2043. }
  2044. function parse_firstChild() {
  2045. var cacheKey = "firstChild@" + pos;
  2046. var cachedResult = cache[cacheKey];
  2047. if (cachedResult) {
  2048. pos = cachedResult.nextPos;
  2049. return cachedResult.result;
  2050. }
  2051. var result0;
  2052. var pos0;
  2053. pos0 = pos;
  2054. if (input.substr(pos, 12) === ":first-child") {
  2055. result0 = ":first-child";
  2056. pos += 12;
  2057. } else {
  2058. result0 = null;
  2059. if (reportFailures === 0) {
  2060. matchFailed("\":first-child\"");
  2061. }
  2062. }
  2063. if (result0 !== null) {
  2064. result0 = (function(offset) { return nth(1); })(pos0);
  2065. }
  2066. if (result0 === null) {
  2067. pos = pos0;
  2068. }
  2069. cache[cacheKey] = {
  2070. nextPos: pos,
  2071. result: result0
  2072. };
  2073. return result0;
  2074. }
  2075. function parse_lastChild() {
  2076. var cacheKey = "lastChild@" + pos;
  2077. var cachedResult = cache[cacheKey];
  2078. if (cachedResult) {
  2079. pos = cachedResult.nextPos;
  2080. return cachedResult.result;
  2081. }
  2082. var result0;
  2083. var pos0;
  2084. pos0 = pos;
  2085. if (input.substr(pos, 11) === ":last-child") {
  2086. result0 = ":last-child";
  2087. pos += 11;
  2088. } else {
  2089. result0 = null;
  2090. if (reportFailures === 0) {
  2091. matchFailed("\":last-child\"");
  2092. }
  2093. }
  2094. if (result0 !== null) {
  2095. result0 = (function(offset) { return nthLast(1); })(pos0);
  2096. }
  2097. if (result0 === null) {
  2098. pos = pos0;
  2099. }
  2100. cache[cacheKey] = {
  2101. nextPos: pos,
  2102. result: result0
  2103. };
  2104. return result0;
  2105. }
  2106. function parse_nthChild() {
  2107. var cacheKey = "nthChild@" + pos;
  2108. var cachedResult = cache[cacheKey];
  2109. if (cachedResult) {
  2110. pos = cachedResult.nextPos;
  2111. return cachedResult.result;
  2112. }
  2113. var result0, result1, result2, result3, result4;
  2114. var pos0, pos1;
  2115. pos0 = pos;
  2116. pos1 = pos;
  2117. if (input.substr(pos, 11) === ":nth-child(") {
  2118. result0 = ":nth-child(";
  2119. pos += 11;
  2120. } else {
  2121. result0 = null;
  2122. if (reportFailures === 0) {
  2123. matchFailed("\":nth-child(\"");
  2124. }
  2125. }
  2126. if (result0 !== null) {
  2127. result1 = parse__();
  2128. if (result1 !== null) {
  2129. if (/^[0-9]/.test(input.charAt(pos))) {
  2130. result3 = input.charAt(pos);
  2131. pos++;
  2132. } else {
  2133. result3 = null;
  2134. if (reportFailures === 0) {
  2135. matchFailed("[0-9]");
  2136. }
  2137. }
  2138. if (result3 !== null) {
  2139. result2 = [];
  2140. while (result3 !== null) {
  2141. result2.push(result3);
  2142. if (/^[0-9]/.test(input.charAt(pos))) {
  2143. result3 = input.charAt(pos);
  2144. pos++;
  2145. } else {
  2146. result3 = null;
  2147. if (reportFailures === 0) {
  2148. matchFailed("[0-9]");
  2149. }
  2150. }
  2151. }
  2152. } else {
  2153. result2 = null;
  2154. }
  2155. if (result2 !== null) {
  2156. result3 = parse__();
  2157. if (result3 !== null) {
  2158. if (input.charCodeAt(pos) === 41) {
  2159. result4 = ")";
  2160. pos++;
  2161. } else {
  2162. result4 = null;
  2163. if (reportFailures === 0) {
  2164. matchFailed("\")\"");
  2165. }
  2166. }
  2167. if (result4 !== null) {
  2168. result0 = [result0, result1, result2, result3, result4];
  2169. } else {
  2170. result0 = null;
  2171. pos = pos1;
  2172. }
  2173. } else {
  2174. result0 = null;
  2175. pos = pos1;
  2176. }
  2177. } else {
  2178. result0 = null;
  2179. pos = pos1;
  2180. }
  2181. } else {
  2182. result0 = null;
  2183. pos = pos1;
  2184. }
  2185. } else {
  2186. result0 = null;
  2187. pos = pos1;
  2188. }
  2189. if (result0 !== null) {
  2190. result0 = (function(offset, n) { return nth(parseInt(n.join(''), 10)); })(pos0, result0[2]);
  2191. }
  2192. if (result0 === null) {
  2193. pos = pos0;
  2194. }
  2195. cache[cacheKey] = {
  2196. nextPos: pos,
  2197. result: result0
  2198. };
  2199. return result0;
  2200. }
  2201. function parse_nthLastChild() {
  2202. var cacheKey = "nthLastChild@" + pos;
  2203. var cachedResult = cache[cacheKey];
  2204. if (cachedResult) {
  2205. pos = cachedResult.nextPos;
  2206. return cachedResult.result;
  2207. }
  2208. var result0, result1, result2, result3, result4;
  2209. var pos0, pos1;
  2210. pos0 = pos;
  2211. pos1 = pos;
  2212. if (input.substr(pos, 16) === ":nth-last-child(") {
  2213. result0 = ":nth-last-child(";
  2214. pos += 16;
  2215. } else {
  2216. result0 = null;
  2217. if (reportFailures === 0) {
  2218. matchFailed("\":nth-last-child(\"");
  2219. }
  2220. }
  2221. if (result0 !== null) {
  2222. result1 = parse__();
  2223. if (result1 !== null) {
  2224. if (/^[0-9]/.test(input.charAt(pos))) {
  2225. result3 = input.charAt(pos);
  2226. pos++;
  2227. } else {
  2228. result3 = null;
  2229. if (reportFailures === 0) {
  2230. matchFailed("[0-9]");
  2231. }
  2232. }
  2233. if (result3 !== null) {
  2234. result2 = [];
  2235. while (result3 !== null) {
  2236. result2.push(result3);
  2237. if (/^[0-9]/.test(input.charAt(pos))) {
  2238. result3 = input.charAt(pos);
  2239. pos++;
  2240. } else {
  2241. result3 = null;
  2242. if (reportFailures === 0) {
  2243. matchFailed("[0-9]");
  2244. }
  2245. }
  2246. }
  2247. } else {
  2248. result2 = null;
  2249. }
  2250. if (result2 !== null) {
  2251. result3 = parse__();
  2252. if (result3 !== null) {
  2253. if (input.charCodeAt(pos) === 41) {
  2254. result4 = ")";
  2255. pos++;
  2256. } else {
  2257. result4 = null;
  2258. if (reportFailures === 0) {
  2259. matchFailed("\")\"");
  2260. }
  2261. }
  2262. if (result4 !== null) {
  2263. result0 = [result0, result1, result2, result3, result4];
  2264. } else {
  2265. result0 = null;
  2266. pos = pos1;
  2267. }
  2268. } else {
  2269. result0 = null;
  2270. pos = pos1;
  2271. }
  2272. } else {
  2273. result0 = null;
  2274. pos = pos1;
  2275. }
  2276. } else {
  2277. result0 = null;
  2278. pos = pos1;
  2279. }
  2280. } else {
  2281. result0 = null;
  2282. pos = pos1;
  2283. }
  2284. if (result0 !== null) {
  2285. result0 = (function(offset, n) { return nthLast(parseInt(n.join(''), 10)); })(pos0, result0[2]);
  2286. }
  2287. if (result0 === null) {
  2288. pos = pos0;
  2289. }
  2290. cache[cacheKey] = {
  2291. nextPos: pos,
  2292. result: result0
  2293. };
  2294. return result0;
  2295. }
  2296. function parse_class() {
  2297. var cacheKey = "class@" + pos;
  2298. var cachedResult = cache[cacheKey];
  2299. if (cachedResult) {
  2300. pos = cachedResult.nextPos;
  2301. return cachedResult.result;
  2302. }
  2303. var result0, result1;
  2304. var pos0, pos1;
  2305. pos0 = pos;
  2306. pos1 = pos;
  2307. if (input.charCodeAt(pos) === 58) {
  2308. result0 = ":";
  2309. pos++;
  2310. } else {
  2311. result0 = null;
  2312. if (reportFailures === 0) {
  2313. matchFailed("\":\"");
  2314. }
  2315. }
  2316. if (result0 !== null) {
  2317. if (input.substr(pos, 9).toLowerCase() === "statement") {
  2318. result1 = input.substr(pos, 9);
  2319. pos += 9;
  2320. } else {
  2321. result1 = null;
  2322. if (reportFailures === 0) {
  2323. matchFailed("\"statement\"");
  2324. }
  2325. }
  2326. if (result1 === null) {
  2327. if (input.substr(pos, 10).toLowerCase() === "expression") {
  2328. result1 = input.substr(pos, 10);
  2329. pos += 10;
  2330. } else {
  2331. result1 = null;
  2332. if (reportFailures === 0) {
  2333. matchFailed("\"expression\"");
  2334. }
  2335. }
  2336. if (result1 === null) {
  2337. if (input.substr(pos, 11).toLowerCase() === "declaration") {
  2338. result1 = input.substr(pos, 11);
  2339. pos += 11;
  2340. } else {
  2341. result1 = null;
  2342. if (reportFailures === 0) {
  2343. matchFailed("\"declaration\"");
  2344. }
  2345. }
  2346. if (result1 === null) {
  2347. if (input.substr(pos, 8).toLowerCase() === "function") {
  2348. result1 = input.substr(pos, 8);
  2349. pos += 8;
  2350. } else {
  2351. result1 = null;
  2352. if (reportFailures === 0) {
  2353. matchFailed("\"function\"");
  2354. }
  2355. }
  2356. if (result1 === null) {
  2357. if (input.substr(pos, 7).toLowerCase() === "pattern") {
  2358. result1 = input.substr(pos, 7);
  2359. pos += 7;
  2360. } else {
  2361. result1 = null;
  2362. if (reportFailures === 0) {
  2363. matchFailed("\"pattern\"");
  2364. }
  2365. }
  2366. }
  2367. }
  2368. }
  2369. }
  2370. if (result1 !== null) {
  2371. result0 = [result0, result1];
  2372. } else {
  2373. result0 = null;
  2374. pos = pos1;
  2375. }
  2376. } else {
  2377. result0 = null;
  2378. pos = pos1;
  2379. }
  2380. if (result0 !== null) {
  2381. result0 = (function(offset, c) {
  2382. return { type: 'class', name: c };
  2383. })(pos0, result0[1]);
  2384. }
  2385. if (result0 === null) {
  2386. pos = pos0;
  2387. }
  2388. cache[cacheKey] = {
  2389. nextPos: pos,
  2390. result: result0
  2391. };
  2392. return result0;
  2393. }
  2394. function cleanupExpected(expected) {
  2395. expected.sort();
  2396. var lastExpected = null;
  2397. var cleanExpected = [];
  2398. for (var i = 0; i < expected.length; i++) {
  2399. if (expected[i] !== lastExpected) {
  2400. cleanExpected.push(expected[i]);
  2401. lastExpected = expected[i];
  2402. }
  2403. }
  2404. return cleanExpected;
  2405. }
  2406. function computeErrorPosition() {
  2407. /*
  2408. * The first idea was to use |String.split| to break the input up to the
  2409. * error position along newlines and derive the line and column from
  2410. * there. However IE's |split| implementation is so broken that it was
  2411. * enough to prevent it.
  2412. */
  2413. var line = 1;
  2414. var column = 1;
  2415. var seenCR = false;
  2416. for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
  2417. var ch = input.charAt(i);
  2418. if (ch === "\n") {
  2419. if (!seenCR) { line++; }
  2420. column = 1;
  2421. seenCR = false;
  2422. } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
  2423. line++;
  2424. column = 1;
  2425. seenCR = true;
  2426. } else {
  2427. column++;
  2428. seenCR = false;
  2429. }
  2430. }
  2431. return { line: line, column: column };
  2432. }
  2433. function nth(n) { return { type: 'nth-child', index: { type: 'literal', value: n } }; }
  2434. function nthLast(n) { return { type: 'nth-last-child', index: { type: 'literal', value: n } }; }
  2435. function strUnescape(s) {
  2436. return s.replace(/\\(.)/g, function(match, ch) {
  2437. switch(ch) {
  2438. case 'a': return '\a';
  2439. case 'b': return '\b';
  2440. case 'f': return '\f';
  2441. case 'n': return '\n';
  2442. case 'r': return '\r';
  2443. case 't': return '\t';
  2444. case 'v': return '\v';
  2445. default: return ch;
  2446. }
  2447. });
  2448. }
  2449. var result = parseFunctions[startRule]();
  2450. /*
  2451. * The parser is now in one of the following three states:
  2452. *
  2453. * 1. The parser successfully parsed the whole input.
  2454. *
  2455. * - |result !== null|
  2456. * - |pos === input.length|
  2457. * - |rightmostFailuresExpected| may or may not contain something
  2458. *
  2459. * 2. The parser successfully parsed only a part of the input.
  2460. *
  2461. * - |result !== null|
  2462. * - |pos < input.length|
  2463. * - |rightmostFailuresExpected| may or may not contain something
  2464. *
  2465. * 3. The parser did not successfully parse any part of the input.
  2466. *
  2467. * - |result === null|
  2468. * - |pos === 0|
  2469. * - |rightmostFailuresExpected| contains at least one failure
  2470. *
  2471. * All code following this comment (including called functions) must
  2472. * handle these states.
  2473. */
  2474. if (result === null || pos !== input.length) {
  2475. var offset = Math.max(pos, rightmostFailuresPos);
  2476. var found = offset < input.length ? input.charAt(offset) : null;
  2477. var errorPosition = computeErrorPosition();
  2478. throw new this.SyntaxError(
  2479. cleanupExpected(rightmostFailuresExpected),
  2480. found,
  2481. offset,
  2482. errorPosition.line,
  2483. errorPosition.column
  2484. );
  2485. }
  2486. return result;
  2487. },
  2488. /* Returns the parser source code. */
  2489. toSource: function() { return this._source; }
  2490. };
  2491. /* Thrown when a parser encounters a syntax error. */
  2492. result.SyntaxError = function(expected, found, offset, line, column) {
  2493. function buildMessage(expected, found) {
  2494. var expectedHumanized, foundHumanized;
  2495. switch (expected.length) {
  2496. case 0:
  2497. expectedHumanized = "end of input";
  2498. break;
  2499. case 1:
  2500. expectedHumanized = expected[0];
  2501. break;
  2502. default:
  2503. expectedHumanized = expected.slice(0, expected.length - 1).join(", ")
  2504. + " or "
  2505. + expected[expected.length - 1];
  2506. }
  2507. foundHumanized = found ? quote(found) : "end of input";
  2508. return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
  2509. }
  2510. this.name = "SyntaxError";
  2511. this.expected = expected;
  2512. this.found = found;
  2513. this.message = buildMessage(expected, found);
  2514. this.offset = offset;
  2515. this.line = line;
  2516. this.column = column;
  2517. };
  2518. result.SyntaxError.prototype = Error.prototype;
  2519. return result;
  2520. })();
  2521. if (typeof define === "function" && define.amd) { define(function(){ return result; }); } else if (typeof module !== "undefined" && module.exports) { module.exports = result; } else { this.esquery = result; }