Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

esquery.lite.js 103KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('estraverse')) :
  3. typeof define === 'function' && define.amd ? define(['estraverse'], factory) :
  4. (global = global || self, global.esquery = factory(global.estraverse));
  5. }(this, (function (estraverse) { 'use strict';
  6. estraverse = estraverse && Object.prototype.hasOwnProperty.call(estraverse, 'default') ? estraverse['default'] : estraverse;
  7. function _typeof(obj) {
  8. "@babel/helpers - typeof";
  9. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  10. _typeof = function (obj) {
  11. return typeof obj;
  12. };
  13. } else {
  14. _typeof = function (obj) {
  15. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  16. };
  17. }
  18. return _typeof(obj);
  19. }
  20. function _slicedToArray(arr, i) {
  21. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
  22. }
  23. function _toConsumableArray(arr) {
  24. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  25. }
  26. function _arrayWithoutHoles(arr) {
  27. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  28. }
  29. function _arrayWithHoles(arr) {
  30. if (Array.isArray(arr)) return arr;
  31. }
  32. function _iterableToArray(iter) {
  33. if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
  34. }
  35. function _iterableToArrayLimit(arr, i) {
  36. if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
  37. var _arr = [];
  38. var _n = true;
  39. var _d = false;
  40. var _e = undefined;
  41. try {
  42. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  43. _arr.push(_s.value);
  44. if (i && _arr.length === i) break;
  45. }
  46. } catch (err) {
  47. _d = true;
  48. _e = err;
  49. } finally {
  50. try {
  51. if (!_n && _i["return"] != null) _i["return"]();
  52. } finally {
  53. if (_d) throw _e;
  54. }
  55. }
  56. return _arr;
  57. }
  58. function _unsupportedIterableToArray(o, minLen) {
  59. if (!o) return;
  60. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  61. var n = Object.prototype.toString.call(o).slice(8, -1);
  62. if (n === "Object" && o.constructor) n = o.constructor.name;
  63. if (n === "Map" || n === "Set") return Array.from(o);
  64. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  65. }
  66. function _arrayLikeToArray(arr, len) {
  67. if (len == null || len > arr.length) len = arr.length;
  68. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  69. return arr2;
  70. }
  71. function _nonIterableSpread() {
  72. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  73. }
  74. function _nonIterableRest() {
  75. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  76. }
  77. function _createForOfIteratorHelper(o, allowArrayLike) {
  78. var it;
  79. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  80. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  81. if (it) o = it;
  82. var i = 0;
  83. var F = function () {};
  84. return {
  85. s: F,
  86. n: function () {
  87. if (i >= o.length) return {
  88. done: true
  89. };
  90. return {
  91. done: false,
  92. value: o[i++]
  93. };
  94. },
  95. e: function (e) {
  96. throw e;
  97. },
  98. f: F
  99. };
  100. }
  101. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  102. }
  103. var normalCompletion = true,
  104. didErr = false,
  105. err;
  106. return {
  107. s: function () {
  108. it = o[Symbol.iterator]();
  109. },
  110. n: function () {
  111. var step = it.next();
  112. normalCompletion = step.done;
  113. return step;
  114. },
  115. e: function (e) {
  116. didErr = true;
  117. err = e;
  118. },
  119. f: function () {
  120. try {
  121. if (!normalCompletion && it.return != null) it.return();
  122. } finally {
  123. if (didErr) throw err;
  124. }
  125. }
  126. };
  127. }
  128. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  129. function createCommonjsModule(fn, module) {
  130. return module = { exports: {} }, fn(module, module.exports), module.exports;
  131. }
  132. var parser = createCommonjsModule(function (module) {
  133. /*
  134. * Generated by PEG.js 0.10.0.
  135. *
  136. * http://pegjs.org/
  137. */
  138. (function (root, factory) {
  139. if ( module.exports) {
  140. module.exports = factory();
  141. }
  142. })(commonjsGlobal, function () {
  143. function peg$subclass(child, parent) {
  144. function ctor() {
  145. this.constructor = child;
  146. }
  147. ctor.prototype = parent.prototype;
  148. child.prototype = new ctor();
  149. }
  150. function peg$SyntaxError(message, expected, found, location) {
  151. this.message = message;
  152. this.expected = expected;
  153. this.found = found;
  154. this.location = location;
  155. this.name = "SyntaxError";
  156. if (typeof Error.captureStackTrace === "function") {
  157. Error.captureStackTrace(this, peg$SyntaxError);
  158. }
  159. }
  160. peg$subclass(peg$SyntaxError, Error);
  161. peg$SyntaxError.buildMessage = function (expected, found) {
  162. var DESCRIBE_EXPECTATION_FNS = {
  163. literal: function literal(expectation) {
  164. return "\"" + literalEscape(expectation.text) + "\"";
  165. },
  166. "class": function _class(expectation) {
  167. var escapedParts = "",
  168. i;
  169. for (i = 0; i < expectation.parts.length; i++) {
  170. escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]);
  171. }
  172. return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
  173. },
  174. any: function any(expectation) {
  175. return "any character";
  176. },
  177. end: function end(expectation) {
  178. return "end of input";
  179. },
  180. other: function other(expectation) {
  181. return expectation.description;
  182. }
  183. };
  184. function hex(ch) {
  185. return ch.charCodeAt(0).toString(16).toUpperCase();
  186. }
  187. function literalEscape(s) {
  188. return s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
  189. return '\\x0' + hex(ch);
  190. }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
  191. return '\\x' + hex(ch);
  192. });
  193. }
  194. function classEscape(s) {
  195. return s.replace(/\\/g, '\\\\').replace(/\]/g, '\\]').replace(/\^/g, '\\^').replace(/-/g, '\\-').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
  196. return '\\x0' + hex(ch);
  197. }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
  198. return '\\x' + hex(ch);
  199. });
  200. }
  201. function describeExpectation(expectation) {
  202. return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
  203. }
  204. function describeExpected(expected) {
  205. var descriptions = new Array(expected.length),
  206. i,
  207. j;
  208. for (i = 0; i < expected.length; i++) {
  209. descriptions[i] = describeExpectation(expected[i]);
  210. }
  211. descriptions.sort();
  212. if (descriptions.length > 0) {
  213. for (i = 1, j = 1; i < descriptions.length; i++) {
  214. if (descriptions[i - 1] !== descriptions[i]) {
  215. descriptions[j] = descriptions[i];
  216. j++;
  217. }
  218. }
  219. descriptions.length = j;
  220. }
  221. switch (descriptions.length) {
  222. case 1:
  223. return descriptions[0];
  224. case 2:
  225. return descriptions[0] + " or " + descriptions[1];
  226. default:
  227. return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
  228. }
  229. }
  230. function describeFound(found) {
  231. return found ? "\"" + literalEscape(found) + "\"" : "end of input";
  232. }
  233. return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
  234. };
  235. function peg$parse(input, options) {
  236. options = options !== void 0 ? options : {};
  237. var peg$FAILED = {},
  238. peg$startRuleFunctions = {
  239. start: peg$parsestart
  240. },
  241. peg$startRuleFunction = peg$parsestart,
  242. peg$c0 = function peg$c0(ss) {
  243. return ss.length === 1 ? ss[0] : {
  244. type: 'matches',
  245. selectors: ss
  246. };
  247. },
  248. peg$c1 = function peg$c1() {
  249. return void 0;
  250. },
  251. peg$c2 = " ",
  252. peg$c3 = peg$literalExpectation(" ", false),
  253. peg$c4 = /^[^ [\],():#!=><~+.]/,
  254. peg$c5 = peg$classExpectation([" ", "[", "]", ",", "(", ")", ":", "#", "!", "=", ">", "<", "~", "+", "."], true, false),
  255. peg$c6 = function peg$c6(i) {
  256. return i.join('');
  257. },
  258. peg$c7 = ">",
  259. peg$c8 = peg$literalExpectation(">", false),
  260. peg$c9 = function peg$c9() {
  261. return 'child';
  262. },
  263. peg$c10 = "~",
  264. peg$c11 = peg$literalExpectation("~", false),
  265. peg$c12 = function peg$c12() {
  266. return 'sibling';
  267. },
  268. peg$c13 = "+",
  269. peg$c14 = peg$literalExpectation("+", false),
  270. peg$c15 = function peg$c15() {
  271. return 'adjacent';
  272. },
  273. peg$c16 = function peg$c16() {
  274. return 'descendant';
  275. },
  276. peg$c17 = ",",
  277. peg$c18 = peg$literalExpectation(",", false),
  278. peg$c19 = function peg$c19(s, ss) {
  279. return [s].concat(ss.map(function (s) {
  280. return s[3];
  281. }));
  282. },
  283. peg$c20 = function peg$c20(a, ops) {
  284. return ops.reduce(function (memo, rhs) {
  285. return {
  286. type: rhs[0],
  287. left: memo,
  288. right: rhs[1]
  289. };
  290. }, a);
  291. },
  292. peg$c21 = "!",
  293. peg$c22 = peg$literalExpectation("!", false),
  294. peg$c23 = function peg$c23(subject, as) {
  295. var b = as.length === 1 ? as[0] : {
  296. type: 'compound',
  297. selectors: as
  298. };
  299. if (subject) b.subject = true;
  300. return b;
  301. },
  302. peg$c24 = "*",
  303. peg$c25 = peg$literalExpectation("*", false),
  304. peg$c26 = function peg$c26(a) {
  305. return {
  306. type: 'wildcard',
  307. value: a
  308. };
  309. },
  310. peg$c27 = "#",
  311. peg$c28 = peg$literalExpectation("#", false),
  312. peg$c29 = function peg$c29(i) {
  313. return {
  314. type: 'identifier',
  315. value: i
  316. };
  317. },
  318. peg$c30 = "[",
  319. peg$c31 = peg$literalExpectation("[", false),
  320. peg$c32 = "]",
  321. peg$c33 = peg$literalExpectation("]", false),
  322. peg$c34 = function peg$c34(v) {
  323. return v;
  324. },
  325. peg$c35 = /^[><!]/,
  326. peg$c36 = peg$classExpectation([">", "<", "!"], false, false),
  327. peg$c37 = "=",
  328. peg$c38 = peg$literalExpectation("=", false),
  329. peg$c39 = function peg$c39(a) {
  330. return (a || '') + '=';
  331. },
  332. peg$c40 = /^[><]/,
  333. peg$c41 = peg$classExpectation([">", "<"], false, false),
  334. peg$c42 = ".",
  335. peg$c43 = peg$literalExpectation(".", false),
  336. peg$c44 = function peg$c44(a, as) {
  337. return [].concat.apply([a], as).join('');
  338. },
  339. peg$c45 = function peg$c45(name, op, value) {
  340. return {
  341. type: 'attribute',
  342. name: name,
  343. operator: op,
  344. value: value
  345. };
  346. },
  347. peg$c46 = function peg$c46(name) {
  348. return {
  349. type: 'attribute',
  350. name: name
  351. };
  352. },
  353. peg$c47 = "\"",
  354. peg$c48 = peg$literalExpectation("\"", false),
  355. peg$c49 = /^[^\\"]/,
  356. peg$c50 = peg$classExpectation(["\\", "\""], true, false),
  357. peg$c51 = "\\",
  358. peg$c52 = peg$literalExpectation("\\", false),
  359. peg$c53 = peg$anyExpectation(),
  360. peg$c54 = function peg$c54(a, b) {
  361. return a + b;
  362. },
  363. peg$c55 = function peg$c55(d) {
  364. return {
  365. type: 'literal',
  366. value: strUnescape(d.join(''))
  367. };
  368. },
  369. peg$c56 = "'",
  370. peg$c57 = peg$literalExpectation("'", false),
  371. peg$c58 = /^[^\\']/,
  372. peg$c59 = peg$classExpectation(["\\", "'"], true, false),
  373. peg$c60 = /^[0-9]/,
  374. peg$c61 = peg$classExpectation([["0", "9"]], false, false),
  375. peg$c62 = function peg$c62(a, b) {
  376. // Can use `a.flat().join('')` once supported
  377. var leadingDecimals = a ? [].concat.apply([], a).join('') : '';
  378. return {
  379. type: 'literal',
  380. value: parseFloat(leadingDecimals + b.join(''))
  381. };
  382. },
  383. peg$c63 = function peg$c63(i) {
  384. return {
  385. type: 'literal',
  386. value: i
  387. };
  388. },
  389. peg$c64 = "type(",
  390. peg$c65 = peg$literalExpectation("type(", false),
  391. peg$c66 = /^[^ )]/,
  392. peg$c67 = peg$classExpectation([" ", ")"], true, false),
  393. peg$c68 = ")",
  394. peg$c69 = peg$literalExpectation(")", false),
  395. peg$c70 = function peg$c70(t) {
  396. return {
  397. type: 'type',
  398. value: t.join('')
  399. };
  400. },
  401. peg$c71 = /^[imsu]/,
  402. peg$c72 = peg$classExpectation(["i", "m", "s", "u"], false, false),
  403. peg$c73 = "/",
  404. peg$c74 = peg$literalExpectation("/", false),
  405. peg$c75 = /^[^\/]/,
  406. peg$c76 = peg$classExpectation(["/"], true, false),
  407. peg$c77 = function peg$c77(d, flgs) {
  408. return {
  409. type: 'regexp',
  410. value: new RegExp(d.join(''), flgs ? flgs.join('') : '')
  411. };
  412. },
  413. peg$c78 = function peg$c78(i, is) {
  414. return {
  415. type: 'field',
  416. name: is.reduce(function (memo, p) {
  417. return memo + p[0] + p[1];
  418. }, i)
  419. };
  420. },
  421. peg$c79 = ":not(",
  422. peg$c80 = peg$literalExpectation(":not(", false),
  423. peg$c81 = function peg$c81(ss) {
  424. return {
  425. type: 'not',
  426. selectors: ss
  427. };
  428. },
  429. peg$c82 = ":matches(",
  430. peg$c83 = peg$literalExpectation(":matches(", false),
  431. peg$c84 = function peg$c84(ss) {
  432. return {
  433. type: 'matches',
  434. selectors: ss
  435. };
  436. },
  437. peg$c85 = ":has(",
  438. peg$c86 = peg$literalExpectation(":has(", false),
  439. peg$c87 = function peg$c87(ss) {
  440. return {
  441. type: 'has',
  442. selectors: ss
  443. };
  444. },
  445. peg$c88 = ":first-child",
  446. peg$c89 = peg$literalExpectation(":first-child", false),
  447. peg$c90 = function peg$c90() {
  448. return nth(1);
  449. },
  450. peg$c91 = ":last-child",
  451. peg$c92 = peg$literalExpectation(":last-child", false),
  452. peg$c93 = function peg$c93() {
  453. return nthLast(1);
  454. },
  455. peg$c94 = ":nth-child(",
  456. peg$c95 = peg$literalExpectation(":nth-child(", false),
  457. peg$c96 = function peg$c96(n) {
  458. return nth(parseInt(n.join(''), 10));
  459. },
  460. peg$c97 = ":nth-last-child(",
  461. peg$c98 = peg$literalExpectation(":nth-last-child(", false),
  462. peg$c99 = function peg$c99(n) {
  463. return nthLast(parseInt(n.join(''), 10));
  464. },
  465. peg$c100 = ":",
  466. peg$c101 = peg$literalExpectation(":", false),
  467. peg$c102 = "statement",
  468. peg$c103 = peg$literalExpectation("statement", true),
  469. peg$c104 = "expression",
  470. peg$c105 = peg$literalExpectation("expression", true),
  471. peg$c106 = "declaration",
  472. peg$c107 = peg$literalExpectation("declaration", true),
  473. peg$c108 = "function",
  474. peg$c109 = peg$literalExpectation("function", true),
  475. peg$c110 = "pattern",
  476. peg$c111 = peg$literalExpectation("pattern", true),
  477. peg$c112 = function peg$c112(c) {
  478. return {
  479. type: 'class',
  480. name: c
  481. };
  482. },
  483. peg$currPos = 0,
  484. peg$posDetailsCache = [{
  485. line: 1,
  486. column: 1
  487. }],
  488. peg$maxFailPos = 0,
  489. peg$maxFailExpected = [],
  490. peg$resultsCache = {},
  491. peg$result;
  492. if ("startRule" in options) {
  493. if (!(options.startRule in peg$startRuleFunctions)) {
  494. throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
  495. }
  496. peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
  497. }
  498. function peg$literalExpectation(text, ignoreCase) {
  499. return {
  500. type: "literal",
  501. text: text,
  502. ignoreCase: ignoreCase
  503. };
  504. }
  505. function peg$classExpectation(parts, inverted, ignoreCase) {
  506. return {
  507. type: "class",
  508. parts: parts,
  509. inverted: inverted,
  510. ignoreCase: ignoreCase
  511. };
  512. }
  513. function peg$anyExpectation() {
  514. return {
  515. type: "any"
  516. };
  517. }
  518. function peg$endExpectation() {
  519. return {
  520. type: "end"
  521. };
  522. }
  523. function peg$computePosDetails(pos) {
  524. var details = peg$posDetailsCache[pos],
  525. p;
  526. if (details) {
  527. return details;
  528. } else {
  529. p = pos - 1;
  530. while (!peg$posDetailsCache[p]) {
  531. p--;
  532. }
  533. details = peg$posDetailsCache[p];
  534. details = {
  535. line: details.line,
  536. column: details.column
  537. };
  538. while (p < pos) {
  539. if (input.charCodeAt(p) === 10) {
  540. details.line++;
  541. details.column = 1;
  542. } else {
  543. details.column++;
  544. }
  545. p++;
  546. }
  547. peg$posDetailsCache[pos] = details;
  548. return details;
  549. }
  550. }
  551. function peg$computeLocation(startPos, endPos) {
  552. var startPosDetails = peg$computePosDetails(startPos),
  553. endPosDetails = peg$computePosDetails(endPos);
  554. return {
  555. start: {
  556. offset: startPos,
  557. line: startPosDetails.line,
  558. column: startPosDetails.column
  559. },
  560. end: {
  561. offset: endPos,
  562. line: endPosDetails.line,
  563. column: endPosDetails.column
  564. }
  565. };
  566. }
  567. function peg$fail(expected) {
  568. if (peg$currPos < peg$maxFailPos) {
  569. return;
  570. }
  571. if (peg$currPos > peg$maxFailPos) {
  572. peg$maxFailPos = peg$currPos;
  573. peg$maxFailExpected = [];
  574. }
  575. peg$maxFailExpected.push(expected);
  576. }
  577. function peg$buildStructuredError(expected, found, location) {
  578. return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
  579. }
  580. function peg$parsestart() {
  581. var s0, s1, s2, s3;
  582. var key = peg$currPos * 30 + 0,
  583. cached = peg$resultsCache[key];
  584. if (cached) {
  585. peg$currPos = cached.nextPos;
  586. return cached.result;
  587. }
  588. s0 = peg$currPos;
  589. s1 = peg$parse_();
  590. if (s1 !== peg$FAILED) {
  591. s2 = peg$parseselectors();
  592. if (s2 !== peg$FAILED) {
  593. s3 = peg$parse_();
  594. if (s3 !== peg$FAILED) {
  595. s1 = peg$c0(s2);
  596. s0 = s1;
  597. } else {
  598. peg$currPos = s0;
  599. s0 = peg$FAILED;
  600. }
  601. } else {
  602. peg$currPos = s0;
  603. s0 = peg$FAILED;
  604. }
  605. } else {
  606. peg$currPos = s0;
  607. s0 = peg$FAILED;
  608. }
  609. if (s0 === peg$FAILED) {
  610. s0 = peg$currPos;
  611. s1 = peg$parse_();
  612. if (s1 !== peg$FAILED) {
  613. s1 = peg$c1();
  614. }
  615. s0 = s1;
  616. }
  617. peg$resultsCache[key] = {
  618. nextPos: peg$currPos,
  619. result: s0
  620. };
  621. return s0;
  622. }
  623. function peg$parse_() {
  624. var s0, s1;
  625. var key = peg$currPos * 30 + 1,
  626. cached = peg$resultsCache[key];
  627. if (cached) {
  628. peg$currPos = cached.nextPos;
  629. return cached.result;
  630. }
  631. s0 = [];
  632. if (input.charCodeAt(peg$currPos) === 32) {
  633. s1 = peg$c2;
  634. peg$currPos++;
  635. } else {
  636. s1 = peg$FAILED;
  637. {
  638. peg$fail(peg$c3);
  639. }
  640. }
  641. while (s1 !== peg$FAILED) {
  642. s0.push(s1);
  643. if (input.charCodeAt(peg$currPos) === 32) {
  644. s1 = peg$c2;
  645. peg$currPos++;
  646. } else {
  647. s1 = peg$FAILED;
  648. {
  649. peg$fail(peg$c3);
  650. }
  651. }
  652. }
  653. peg$resultsCache[key] = {
  654. nextPos: peg$currPos,
  655. result: s0
  656. };
  657. return s0;
  658. }
  659. function peg$parseidentifierName() {
  660. var s0, s1, s2;
  661. var key = peg$currPos * 30 + 2,
  662. cached = peg$resultsCache[key];
  663. if (cached) {
  664. peg$currPos = cached.nextPos;
  665. return cached.result;
  666. }
  667. s0 = peg$currPos;
  668. s1 = [];
  669. if (peg$c4.test(input.charAt(peg$currPos))) {
  670. s2 = input.charAt(peg$currPos);
  671. peg$currPos++;
  672. } else {
  673. s2 = peg$FAILED;
  674. {
  675. peg$fail(peg$c5);
  676. }
  677. }
  678. if (s2 !== peg$FAILED) {
  679. while (s2 !== peg$FAILED) {
  680. s1.push(s2);
  681. if (peg$c4.test(input.charAt(peg$currPos))) {
  682. s2 = input.charAt(peg$currPos);
  683. peg$currPos++;
  684. } else {
  685. s2 = peg$FAILED;
  686. {
  687. peg$fail(peg$c5);
  688. }
  689. }
  690. }
  691. } else {
  692. s1 = peg$FAILED;
  693. }
  694. if (s1 !== peg$FAILED) {
  695. s1 = peg$c6(s1);
  696. }
  697. s0 = s1;
  698. peg$resultsCache[key] = {
  699. nextPos: peg$currPos,
  700. result: s0
  701. };
  702. return s0;
  703. }
  704. function peg$parsebinaryOp() {
  705. var s0, s1, s2, s3;
  706. var key = peg$currPos * 30 + 3,
  707. cached = peg$resultsCache[key];
  708. if (cached) {
  709. peg$currPos = cached.nextPos;
  710. return cached.result;
  711. }
  712. s0 = peg$currPos;
  713. s1 = peg$parse_();
  714. if (s1 !== peg$FAILED) {
  715. if (input.charCodeAt(peg$currPos) === 62) {
  716. s2 = peg$c7;
  717. peg$currPos++;
  718. } else {
  719. s2 = peg$FAILED;
  720. {
  721. peg$fail(peg$c8);
  722. }
  723. }
  724. if (s2 !== peg$FAILED) {
  725. s3 = peg$parse_();
  726. if (s3 !== peg$FAILED) {
  727. s1 = peg$c9();
  728. s0 = s1;
  729. } else {
  730. peg$currPos = s0;
  731. s0 = peg$FAILED;
  732. }
  733. } else {
  734. peg$currPos = s0;
  735. s0 = peg$FAILED;
  736. }
  737. } else {
  738. peg$currPos = s0;
  739. s0 = peg$FAILED;
  740. }
  741. if (s0 === peg$FAILED) {
  742. s0 = peg$currPos;
  743. s1 = peg$parse_();
  744. if (s1 !== peg$FAILED) {
  745. if (input.charCodeAt(peg$currPos) === 126) {
  746. s2 = peg$c10;
  747. peg$currPos++;
  748. } else {
  749. s2 = peg$FAILED;
  750. {
  751. peg$fail(peg$c11);
  752. }
  753. }
  754. if (s2 !== peg$FAILED) {
  755. s3 = peg$parse_();
  756. if (s3 !== peg$FAILED) {
  757. s1 = peg$c12();
  758. s0 = s1;
  759. } else {
  760. peg$currPos = s0;
  761. s0 = peg$FAILED;
  762. }
  763. } else {
  764. peg$currPos = s0;
  765. s0 = peg$FAILED;
  766. }
  767. } else {
  768. peg$currPos = s0;
  769. s0 = peg$FAILED;
  770. }
  771. if (s0 === peg$FAILED) {
  772. s0 = peg$currPos;
  773. s1 = peg$parse_();
  774. if (s1 !== peg$FAILED) {
  775. if (input.charCodeAt(peg$currPos) === 43) {
  776. s2 = peg$c13;
  777. peg$currPos++;
  778. } else {
  779. s2 = peg$FAILED;
  780. {
  781. peg$fail(peg$c14);
  782. }
  783. }
  784. if (s2 !== peg$FAILED) {
  785. s3 = peg$parse_();
  786. if (s3 !== peg$FAILED) {
  787. s1 = peg$c15();
  788. s0 = s1;
  789. } else {
  790. peg$currPos = s0;
  791. s0 = peg$FAILED;
  792. }
  793. } else {
  794. peg$currPos = s0;
  795. s0 = peg$FAILED;
  796. }
  797. } else {
  798. peg$currPos = s0;
  799. s0 = peg$FAILED;
  800. }
  801. if (s0 === peg$FAILED) {
  802. s0 = peg$currPos;
  803. if (input.charCodeAt(peg$currPos) === 32) {
  804. s1 = peg$c2;
  805. peg$currPos++;
  806. } else {
  807. s1 = peg$FAILED;
  808. {
  809. peg$fail(peg$c3);
  810. }
  811. }
  812. if (s1 !== peg$FAILED) {
  813. s2 = peg$parse_();
  814. if (s2 !== peg$FAILED) {
  815. s1 = peg$c16();
  816. s0 = s1;
  817. } else {
  818. peg$currPos = s0;
  819. s0 = peg$FAILED;
  820. }
  821. } else {
  822. peg$currPos = s0;
  823. s0 = peg$FAILED;
  824. }
  825. }
  826. }
  827. }
  828. peg$resultsCache[key] = {
  829. nextPos: peg$currPos,
  830. result: s0
  831. };
  832. return s0;
  833. }
  834. function peg$parseselectors() {
  835. var s0, s1, s2, s3, s4, s5, s6, s7;
  836. var key = peg$currPos * 30 + 4,
  837. cached = peg$resultsCache[key];
  838. if (cached) {
  839. peg$currPos = cached.nextPos;
  840. return cached.result;
  841. }
  842. s0 = peg$currPos;
  843. s1 = peg$parseselector();
  844. if (s1 !== peg$FAILED) {
  845. s2 = [];
  846. s3 = peg$currPos;
  847. s4 = peg$parse_();
  848. if (s4 !== peg$FAILED) {
  849. if (input.charCodeAt(peg$currPos) === 44) {
  850. s5 = peg$c17;
  851. peg$currPos++;
  852. } else {
  853. s5 = peg$FAILED;
  854. {
  855. peg$fail(peg$c18);
  856. }
  857. }
  858. if (s5 !== peg$FAILED) {
  859. s6 = peg$parse_();
  860. if (s6 !== peg$FAILED) {
  861. s7 = peg$parseselector();
  862. if (s7 !== peg$FAILED) {
  863. s4 = [s4, s5, s6, s7];
  864. s3 = s4;
  865. } else {
  866. peg$currPos = s3;
  867. s3 = peg$FAILED;
  868. }
  869. } else {
  870. peg$currPos = s3;
  871. s3 = peg$FAILED;
  872. }
  873. } else {
  874. peg$currPos = s3;
  875. s3 = peg$FAILED;
  876. }
  877. } else {
  878. peg$currPos = s3;
  879. s3 = peg$FAILED;
  880. }
  881. while (s3 !== peg$FAILED) {
  882. s2.push(s3);
  883. s3 = peg$currPos;
  884. s4 = peg$parse_();
  885. if (s4 !== peg$FAILED) {
  886. if (input.charCodeAt(peg$currPos) === 44) {
  887. s5 = peg$c17;
  888. peg$currPos++;
  889. } else {
  890. s5 = peg$FAILED;
  891. {
  892. peg$fail(peg$c18);
  893. }
  894. }
  895. if (s5 !== peg$FAILED) {
  896. s6 = peg$parse_();
  897. if (s6 !== peg$FAILED) {
  898. s7 = peg$parseselector();
  899. if (s7 !== peg$FAILED) {
  900. s4 = [s4, s5, s6, s7];
  901. s3 = s4;
  902. } else {
  903. peg$currPos = s3;
  904. s3 = peg$FAILED;
  905. }
  906. } else {
  907. peg$currPos = s3;
  908. s3 = peg$FAILED;
  909. }
  910. } else {
  911. peg$currPos = s3;
  912. s3 = peg$FAILED;
  913. }
  914. } else {
  915. peg$currPos = s3;
  916. s3 = peg$FAILED;
  917. }
  918. }
  919. if (s2 !== peg$FAILED) {
  920. s1 = peg$c19(s1, s2);
  921. s0 = s1;
  922. } else {
  923. peg$currPos = s0;
  924. s0 = peg$FAILED;
  925. }
  926. } else {
  927. peg$currPos = s0;
  928. s0 = peg$FAILED;
  929. }
  930. peg$resultsCache[key] = {
  931. nextPos: peg$currPos,
  932. result: s0
  933. };
  934. return s0;
  935. }
  936. function peg$parseselector() {
  937. var s0, s1, s2, s3, s4, s5;
  938. var key = peg$currPos * 30 + 5,
  939. cached = peg$resultsCache[key];
  940. if (cached) {
  941. peg$currPos = cached.nextPos;
  942. return cached.result;
  943. }
  944. s0 = peg$currPos;
  945. s1 = peg$parsesequence();
  946. if (s1 !== peg$FAILED) {
  947. s2 = [];
  948. s3 = peg$currPos;
  949. s4 = peg$parsebinaryOp();
  950. if (s4 !== peg$FAILED) {
  951. s5 = peg$parsesequence();
  952. if (s5 !== peg$FAILED) {
  953. s4 = [s4, s5];
  954. s3 = s4;
  955. } else {
  956. peg$currPos = s3;
  957. s3 = peg$FAILED;
  958. }
  959. } else {
  960. peg$currPos = s3;
  961. s3 = peg$FAILED;
  962. }
  963. while (s3 !== peg$FAILED) {
  964. s2.push(s3);
  965. s3 = peg$currPos;
  966. s4 = peg$parsebinaryOp();
  967. if (s4 !== peg$FAILED) {
  968. s5 = peg$parsesequence();
  969. if (s5 !== peg$FAILED) {
  970. s4 = [s4, s5];
  971. s3 = s4;
  972. } else {
  973. peg$currPos = s3;
  974. s3 = peg$FAILED;
  975. }
  976. } else {
  977. peg$currPos = s3;
  978. s3 = peg$FAILED;
  979. }
  980. }
  981. if (s2 !== peg$FAILED) {
  982. s1 = peg$c20(s1, s2);
  983. s0 = s1;
  984. } else {
  985. peg$currPos = s0;
  986. s0 = peg$FAILED;
  987. }
  988. } else {
  989. peg$currPos = s0;
  990. s0 = peg$FAILED;
  991. }
  992. peg$resultsCache[key] = {
  993. nextPos: peg$currPos,
  994. result: s0
  995. };
  996. return s0;
  997. }
  998. function peg$parsesequence() {
  999. var s0, s1, s2, s3;
  1000. var key = peg$currPos * 30 + 6,
  1001. cached = peg$resultsCache[key];
  1002. if (cached) {
  1003. peg$currPos = cached.nextPos;
  1004. return cached.result;
  1005. }
  1006. s0 = peg$currPos;
  1007. if (input.charCodeAt(peg$currPos) === 33) {
  1008. s1 = peg$c21;
  1009. peg$currPos++;
  1010. } else {
  1011. s1 = peg$FAILED;
  1012. {
  1013. peg$fail(peg$c22);
  1014. }
  1015. }
  1016. if (s1 === peg$FAILED) {
  1017. s1 = null;
  1018. }
  1019. if (s1 !== peg$FAILED) {
  1020. s2 = [];
  1021. s3 = peg$parseatom();
  1022. if (s3 !== peg$FAILED) {
  1023. while (s3 !== peg$FAILED) {
  1024. s2.push(s3);
  1025. s3 = peg$parseatom();
  1026. }
  1027. } else {
  1028. s2 = peg$FAILED;
  1029. }
  1030. if (s2 !== peg$FAILED) {
  1031. s1 = peg$c23(s1, s2);
  1032. s0 = s1;
  1033. } else {
  1034. peg$currPos = s0;
  1035. s0 = peg$FAILED;
  1036. }
  1037. } else {
  1038. peg$currPos = s0;
  1039. s0 = peg$FAILED;
  1040. }
  1041. peg$resultsCache[key] = {
  1042. nextPos: peg$currPos,
  1043. result: s0
  1044. };
  1045. return s0;
  1046. }
  1047. function peg$parseatom() {
  1048. var s0;
  1049. var key = peg$currPos * 30 + 7,
  1050. cached = peg$resultsCache[key];
  1051. if (cached) {
  1052. peg$currPos = cached.nextPos;
  1053. return cached.result;
  1054. }
  1055. s0 = peg$parsewildcard();
  1056. if (s0 === peg$FAILED) {
  1057. s0 = peg$parseidentifier();
  1058. if (s0 === peg$FAILED) {
  1059. s0 = peg$parseattr();
  1060. if (s0 === peg$FAILED) {
  1061. s0 = peg$parsefield();
  1062. if (s0 === peg$FAILED) {
  1063. s0 = peg$parsenegation();
  1064. if (s0 === peg$FAILED) {
  1065. s0 = peg$parsematches();
  1066. if (s0 === peg$FAILED) {
  1067. s0 = peg$parsehas();
  1068. if (s0 === peg$FAILED) {
  1069. s0 = peg$parsefirstChild();
  1070. if (s0 === peg$FAILED) {
  1071. s0 = peg$parselastChild();
  1072. if (s0 === peg$FAILED) {
  1073. s0 = peg$parsenthChild();
  1074. if (s0 === peg$FAILED) {
  1075. s0 = peg$parsenthLastChild();
  1076. if (s0 === peg$FAILED) {
  1077. s0 = peg$parseclass();
  1078. }
  1079. }
  1080. }
  1081. }
  1082. }
  1083. }
  1084. }
  1085. }
  1086. }
  1087. }
  1088. }
  1089. peg$resultsCache[key] = {
  1090. nextPos: peg$currPos,
  1091. result: s0
  1092. };
  1093. return s0;
  1094. }
  1095. function peg$parsewildcard() {
  1096. var s0, s1;
  1097. var key = peg$currPos * 30 + 8,
  1098. cached = peg$resultsCache[key];
  1099. if (cached) {
  1100. peg$currPos = cached.nextPos;
  1101. return cached.result;
  1102. }
  1103. s0 = peg$currPos;
  1104. if (input.charCodeAt(peg$currPos) === 42) {
  1105. s1 = peg$c24;
  1106. peg$currPos++;
  1107. } else {
  1108. s1 = peg$FAILED;
  1109. {
  1110. peg$fail(peg$c25);
  1111. }
  1112. }
  1113. if (s1 !== peg$FAILED) {
  1114. s1 = peg$c26(s1);
  1115. }
  1116. s0 = s1;
  1117. peg$resultsCache[key] = {
  1118. nextPos: peg$currPos,
  1119. result: s0
  1120. };
  1121. return s0;
  1122. }
  1123. function peg$parseidentifier() {
  1124. var s0, s1, s2;
  1125. var key = peg$currPos * 30 + 9,
  1126. cached = peg$resultsCache[key];
  1127. if (cached) {
  1128. peg$currPos = cached.nextPos;
  1129. return cached.result;
  1130. }
  1131. s0 = peg$currPos;
  1132. if (input.charCodeAt(peg$currPos) === 35) {
  1133. s1 = peg$c27;
  1134. peg$currPos++;
  1135. } else {
  1136. s1 = peg$FAILED;
  1137. {
  1138. peg$fail(peg$c28);
  1139. }
  1140. }
  1141. if (s1 === peg$FAILED) {
  1142. s1 = null;
  1143. }
  1144. if (s1 !== peg$FAILED) {
  1145. s2 = peg$parseidentifierName();
  1146. if (s2 !== peg$FAILED) {
  1147. s1 = peg$c29(s2);
  1148. s0 = s1;
  1149. } else {
  1150. peg$currPos = s0;
  1151. s0 = peg$FAILED;
  1152. }
  1153. } else {
  1154. peg$currPos = s0;
  1155. s0 = peg$FAILED;
  1156. }
  1157. peg$resultsCache[key] = {
  1158. nextPos: peg$currPos,
  1159. result: s0
  1160. };
  1161. return s0;
  1162. }
  1163. function peg$parseattr() {
  1164. var s0, s1, s2, s3, s4, s5;
  1165. var key = peg$currPos * 30 + 10,
  1166. cached = peg$resultsCache[key];
  1167. if (cached) {
  1168. peg$currPos = cached.nextPos;
  1169. return cached.result;
  1170. }
  1171. s0 = peg$currPos;
  1172. if (input.charCodeAt(peg$currPos) === 91) {
  1173. s1 = peg$c30;
  1174. peg$currPos++;
  1175. } else {
  1176. s1 = peg$FAILED;
  1177. {
  1178. peg$fail(peg$c31);
  1179. }
  1180. }
  1181. if (s1 !== peg$FAILED) {
  1182. s2 = peg$parse_();
  1183. if (s2 !== peg$FAILED) {
  1184. s3 = peg$parseattrValue();
  1185. if (s3 !== peg$FAILED) {
  1186. s4 = peg$parse_();
  1187. if (s4 !== peg$FAILED) {
  1188. if (input.charCodeAt(peg$currPos) === 93) {
  1189. s5 = peg$c32;
  1190. peg$currPos++;
  1191. } else {
  1192. s5 = peg$FAILED;
  1193. {
  1194. peg$fail(peg$c33);
  1195. }
  1196. }
  1197. if (s5 !== peg$FAILED) {
  1198. s1 = peg$c34(s3);
  1199. s0 = s1;
  1200. } else {
  1201. peg$currPos = s0;
  1202. s0 = peg$FAILED;
  1203. }
  1204. } else {
  1205. peg$currPos = s0;
  1206. s0 = peg$FAILED;
  1207. }
  1208. } else {
  1209. peg$currPos = s0;
  1210. s0 = peg$FAILED;
  1211. }
  1212. } else {
  1213. peg$currPos = s0;
  1214. s0 = peg$FAILED;
  1215. }
  1216. } else {
  1217. peg$currPos = s0;
  1218. s0 = peg$FAILED;
  1219. }
  1220. peg$resultsCache[key] = {
  1221. nextPos: peg$currPos,
  1222. result: s0
  1223. };
  1224. return s0;
  1225. }
  1226. function peg$parseattrOps() {
  1227. var s0, s1, s2;
  1228. var key = peg$currPos * 30 + 11,
  1229. cached = peg$resultsCache[key];
  1230. if (cached) {
  1231. peg$currPos = cached.nextPos;
  1232. return cached.result;
  1233. }
  1234. s0 = peg$currPos;
  1235. if (peg$c35.test(input.charAt(peg$currPos))) {
  1236. s1 = input.charAt(peg$currPos);
  1237. peg$currPos++;
  1238. } else {
  1239. s1 = peg$FAILED;
  1240. {
  1241. peg$fail(peg$c36);
  1242. }
  1243. }
  1244. if (s1 === peg$FAILED) {
  1245. s1 = null;
  1246. }
  1247. if (s1 !== peg$FAILED) {
  1248. if (input.charCodeAt(peg$currPos) === 61) {
  1249. s2 = peg$c37;
  1250. peg$currPos++;
  1251. } else {
  1252. s2 = peg$FAILED;
  1253. {
  1254. peg$fail(peg$c38);
  1255. }
  1256. }
  1257. if (s2 !== peg$FAILED) {
  1258. s1 = peg$c39(s1);
  1259. s0 = s1;
  1260. } else {
  1261. peg$currPos = s0;
  1262. s0 = peg$FAILED;
  1263. }
  1264. } else {
  1265. peg$currPos = s0;
  1266. s0 = peg$FAILED;
  1267. }
  1268. if (s0 === peg$FAILED) {
  1269. if (peg$c40.test(input.charAt(peg$currPos))) {
  1270. s0 = input.charAt(peg$currPos);
  1271. peg$currPos++;
  1272. } else {
  1273. s0 = peg$FAILED;
  1274. {
  1275. peg$fail(peg$c41);
  1276. }
  1277. }
  1278. }
  1279. peg$resultsCache[key] = {
  1280. nextPos: peg$currPos,
  1281. result: s0
  1282. };
  1283. return s0;
  1284. }
  1285. function peg$parseattrEqOps() {
  1286. var s0, s1, s2;
  1287. var key = peg$currPos * 30 + 12,
  1288. cached = peg$resultsCache[key];
  1289. if (cached) {
  1290. peg$currPos = cached.nextPos;
  1291. return cached.result;
  1292. }
  1293. s0 = peg$currPos;
  1294. if (input.charCodeAt(peg$currPos) === 33) {
  1295. s1 = peg$c21;
  1296. peg$currPos++;
  1297. } else {
  1298. s1 = peg$FAILED;
  1299. {
  1300. peg$fail(peg$c22);
  1301. }
  1302. }
  1303. if (s1 === peg$FAILED) {
  1304. s1 = null;
  1305. }
  1306. if (s1 !== peg$FAILED) {
  1307. if (input.charCodeAt(peg$currPos) === 61) {
  1308. s2 = peg$c37;
  1309. peg$currPos++;
  1310. } else {
  1311. s2 = peg$FAILED;
  1312. {
  1313. peg$fail(peg$c38);
  1314. }
  1315. }
  1316. if (s2 !== peg$FAILED) {
  1317. s1 = peg$c39(s1);
  1318. s0 = s1;
  1319. } else {
  1320. peg$currPos = s0;
  1321. s0 = peg$FAILED;
  1322. }
  1323. } else {
  1324. peg$currPos = s0;
  1325. s0 = peg$FAILED;
  1326. }
  1327. peg$resultsCache[key] = {
  1328. nextPos: peg$currPos,
  1329. result: s0
  1330. };
  1331. return s0;
  1332. }
  1333. function peg$parseattrName() {
  1334. var s0, s1, s2, s3, s4, s5;
  1335. var key = peg$currPos * 30 + 13,
  1336. cached = peg$resultsCache[key];
  1337. if (cached) {
  1338. peg$currPos = cached.nextPos;
  1339. return cached.result;
  1340. }
  1341. s0 = peg$currPos;
  1342. s1 = peg$parseidentifierName();
  1343. if (s1 !== peg$FAILED) {
  1344. s2 = [];
  1345. s3 = peg$currPos;
  1346. if (input.charCodeAt(peg$currPos) === 46) {
  1347. s4 = peg$c42;
  1348. peg$currPos++;
  1349. } else {
  1350. s4 = peg$FAILED;
  1351. {
  1352. peg$fail(peg$c43);
  1353. }
  1354. }
  1355. if (s4 !== peg$FAILED) {
  1356. s5 = peg$parseidentifierName();
  1357. if (s5 !== peg$FAILED) {
  1358. s4 = [s4, s5];
  1359. s3 = s4;
  1360. } else {
  1361. peg$currPos = s3;
  1362. s3 = peg$FAILED;
  1363. }
  1364. } else {
  1365. peg$currPos = s3;
  1366. s3 = peg$FAILED;
  1367. }
  1368. while (s3 !== peg$FAILED) {
  1369. s2.push(s3);
  1370. s3 = peg$currPos;
  1371. if (input.charCodeAt(peg$currPos) === 46) {
  1372. s4 = peg$c42;
  1373. peg$currPos++;
  1374. } else {
  1375. s4 = peg$FAILED;
  1376. {
  1377. peg$fail(peg$c43);
  1378. }
  1379. }
  1380. if (s4 !== peg$FAILED) {
  1381. s5 = peg$parseidentifierName();
  1382. if (s5 !== peg$FAILED) {
  1383. s4 = [s4, s5];
  1384. s3 = s4;
  1385. } else {
  1386. peg$currPos = s3;
  1387. s3 = peg$FAILED;
  1388. }
  1389. } else {
  1390. peg$currPos = s3;
  1391. s3 = peg$FAILED;
  1392. }
  1393. }
  1394. if (s2 !== peg$FAILED) {
  1395. s1 = peg$c44(s1, s2);
  1396. s0 = s1;
  1397. } else {
  1398. peg$currPos = s0;
  1399. s0 = peg$FAILED;
  1400. }
  1401. } else {
  1402. peg$currPos = s0;
  1403. s0 = peg$FAILED;
  1404. }
  1405. peg$resultsCache[key] = {
  1406. nextPos: peg$currPos,
  1407. result: s0
  1408. };
  1409. return s0;
  1410. }
  1411. function peg$parseattrValue() {
  1412. var s0, s1, s2, s3, s4, s5;
  1413. var key = peg$currPos * 30 + 14,
  1414. cached = peg$resultsCache[key];
  1415. if (cached) {
  1416. peg$currPos = cached.nextPos;
  1417. return cached.result;
  1418. }
  1419. s0 = peg$currPos;
  1420. s1 = peg$parseattrName();
  1421. if (s1 !== peg$FAILED) {
  1422. s2 = peg$parse_();
  1423. if (s2 !== peg$FAILED) {
  1424. s3 = peg$parseattrEqOps();
  1425. if (s3 !== peg$FAILED) {
  1426. s4 = peg$parse_();
  1427. if (s4 !== peg$FAILED) {
  1428. s5 = peg$parsetype();
  1429. if (s5 === peg$FAILED) {
  1430. s5 = peg$parseregex();
  1431. }
  1432. if (s5 !== peg$FAILED) {
  1433. s1 = peg$c45(s1, s3, s5);
  1434. s0 = s1;
  1435. } else {
  1436. peg$currPos = s0;
  1437. s0 = peg$FAILED;
  1438. }
  1439. } else {
  1440. peg$currPos = s0;
  1441. s0 = peg$FAILED;
  1442. }
  1443. } else {
  1444. peg$currPos = s0;
  1445. s0 = peg$FAILED;
  1446. }
  1447. } else {
  1448. peg$currPos = s0;
  1449. s0 = peg$FAILED;
  1450. }
  1451. } else {
  1452. peg$currPos = s0;
  1453. s0 = peg$FAILED;
  1454. }
  1455. if (s0 === peg$FAILED) {
  1456. s0 = peg$currPos;
  1457. s1 = peg$parseattrName();
  1458. if (s1 !== peg$FAILED) {
  1459. s2 = peg$parse_();
  1460. if (s2 !== peg$FAILED) {
  1461. s3 = peg$parseattrOps();
  1462. if (s3 !== peg$FAILED) {
  1463. s4 = peg$parse_();
  1464. if (s4 !== peg$FAILED) {
  1465. s5 = peg$parsestring();
  1466. if (s5 === peg$FAILED) {
  1467. s5 = peg$parsenumber();
  1468. if (s5 === peg$FAILED) {
  1469. s5 = peg$parsepath();
  1470. }
  1471. }
  1472. if (s5 !== peg$FAILED) {
  1473. s1 = peg$c45(s1, s3, s5);
  1474. s0 = s1;
  1475. } else {
  1476. peg$currPos = s0;
  1477. s0 = peg$FAILED;
  1478. }
  1479. } else {
  1480. peg$currPos = s0;
  1481. s0 = peg$FAILED;
  1482. }
  1483. } else {
  1484. peg$currPos = s0;
  1485. s0 = peg$FAILED;
  1486. }
  1487. } else {
  1488. peg$currPos = s0;
  1489. s0 = peg$FAILED;
  1490. }
  1491. } else {
  1492. peg$currPos = s0;
  1493. s0 = peg$FAILED;
  1494. }
  1495. if (s0 === peg$FAILED) {
  1496. s0 = peg$currPos;
  1497. s1 = peg$parseattrName();
  1498. if (s1 !== peg$FAILED) {
  1499. s1 = peg$c46(s1);
  1500. }
  1501. s0 = s1;
  1502. }
  1503. }
  1504. peg$resultsCache[key] = {
  1505. nextPos: peg$currPos,
  1506. result: s0
  1507. };
  1508. return s0;
  1509. }
  1510. function peg$parsestring() {
  1511. var s0, s1, s2, s3, s4, s5;
  1512. var key = peg$currPos * 30 + 15,
  1513. cached = peg$resultsCache[key];
  1514. if (cached) {
  1515. peg$currPos = cached.nextPos;
  1516. return cached.result;
  1517. }
  1518. s0 = peg$currPos;
  1519. if (input.charCodeAt(peg$currPos) === 34) {
  1520. s1 = peg$c47;
  1521. peg$currPos++;
  1522. } else {
  1523. s1 = peg$FAILED;
  1524. {
  1525. peg$fail(peg$c48);
  1526. }
  1527. }
  1528. if (s1 !== peg$FAILED) {
  1529. s2 = [];
  1530. if (peg$c49.test(input.charAt(peg$currPos))) {
  1531. s3 = input.charAt(peg$currPos);
  1532. peg$currPos++;
  1533. } else {
  1534. s3 = peg$FAILED;
  1535. {
  1536. peg$fail(peg$c50);
  1537. }
  1538. }
  1539. if (s3 === peg$FAILED) {
  1540. s3 = peg$currPos;
  1541. if (input.charCodeAt(peg$currPos) === 92) {
  1542. s4 = peg$c51;
  1543. peg$currPos++;
  1544. } else {
  1545. s4 = peg$FAILED;
  1546. {
  1547. peg$fail(peg$c52);
  1548. }
  1549. }
  1550. if (s4 !== peg$FAILED) {
  1551. if (input.length > peg$currPos) {
  1552. s5 = input.charAt(peg$currPos);
  1553. peg$currPos++;
  1554. } else {
  1555. s5 = peg$FAILED;
  1556. {
  1557. peg$fail(peg$c53);
  1558. }
  1559. }
  1560. if (s5 !== peg$FAILED) {
  1561. s4 = peg$c54(s4, s5);
  1562. s3 = s4;
  1563. } else {
  1564. peg$currPos = s3;
  1565. s3 = peg$FAILED;
  1566. }
  1567. } else {
  1568. peg$currPos = s3;
  1569. s3 = peg$FAILED;
  1570. }
  1571. }
  1572. while (s3 !== peg$FAILED) {
  1573. s2.push(s3);
  1574. if (peg$c49.test(input.charAt(peg$currPos))) {
  1575. s3 = input.charAt(peg$currPos);
  1576. peg$currPos++;
  1577. } else {
  1578. s3 = peg$FAILED;
  1579. {
  1580. peg$fail(peg$c50);
  1581. }
  1582. }
  1583. if (s3 === peg$FAILED) {
  1584. s3 = peg$currPos;
  1585. if (input.charCodeAt(peg$currPos) === 92) {
  1586. s4 = peg$c51;
  1587. peg$currPos++;
  1588. } else {
  1589. s4 = peg$FAILED;
  1590. {
  1591. peg$fail(peg$c52);
  1592. }
  1593. }
  1594. if (s4 !== peg$FAILED) {
  1595. if (input.length > peg$currPos) {
  1596. s5 = input.charAt(peg$currPos);
  1597. peg$currPos++;
  1598. } else {
  1599. s5 = peg$FAILED;
  1600. {
  1601. peg$fail(peg$c53);
  1602. }
  1603. }
  1604. if (s5 !== peg$FAILED) {
  1605. s4 = peg$c54(s4, s5);
  1606. s3 = s4;
  1607. } else {
  1608. peg$currPos = s3;
  1609. s3 = peg$FAILED;
  1610. }
  1611. } else {
  1612. peg$currPos = s3;
  1613. s3 = peg$FAILED;
  1614. }
  1615. }
  1616. }
  1617. if (s2 !== peg$FAILED) {
  1618. if (input.charCodeAt(peg$currPos) === 34) {
  1619. s3 = peg$c47;
  1620. peg$currPos++;
  1621. } else {
  1622. s3 = peg$FAILED;
  1623. {
  1624. peg$fail(peg$c48);
  1625. }
  1626. }
  1627. if (s3 !== peg$FAILED) {
  1628. s1 = peg$c55(s2);
  1629. s0 = s1;
  1630. } else {
  1631. peg$currPos = s0;
  1632. s0 = peg$FAILED;
  1633. }
  1634. } else {
  1635. peg$currPos = s0;
  1636. s0 = peg$FAILED;
  1637. }
  1638. } else {
  1639. peg$currPos = s0;
  1640. s0 = peg$FAILED;
  1641. }
  1642. if (s0 === peg$FAILED) {
  1643. s0 = peg$currPos;
  1644. if (input.charCodeAt(peg$currPos) === 39) {
  1645. s1 = peg$c56;
  1646. peg$currPos++;
  1647. } else {
  1648. s1 = peg$FAILED;
  1649. {
  1650. peg$fail(peg$c57);
  1651. }
  1652. }
  1653. if (s1 !== peg$FAILED) {
  1654. s2 = [];
  1655. if (peg$c58.test(input.charAt(peg$currPos))) {
  1656. s3 = input.charAt(peg$currPos);
  1657. peg$currPos++;
  1658. } else {
  1659. s3 = peg$FAILED;
  1660. {
  1661. peg$fail(peg$c59);
  1662. }
  1663. }
  1664. if (s3 === peg$FAILED) {
  1665. s3 = peg$currPos;
  1666. if (input.charCodeAt(peg$currPos) === 92) {
  1667. s4 = peg$c51;
  1668. peg$currPos++;
  1669. } else {
  1670. s4 = peg$FAILED;
  1671. {
  1672. peg$fail(peg$c52);
  1673. }
  1674. }
  1675. if (s4 !== peg$FAILED) {
  1676. if (input.length > peg$currPos) {
  1677. s5 = input.charAt(peg$currPos);
  1678. peg$currPos++;
  1679. } else {
  1680. s5 = peg$FAILED;
  1681. {
  1682. peg$fail(peg$c53);
  1683. }
  1684. }
  1685. if (s5 !== peg$FAILED) {
  1686. s4 = peg$c54(s4, s5);
  1687. s3 = s4;
  1688. } else {
  1689. peg$currPos = s3;
  1690. s3 = peg$FAILED;
  1691. }
  1692. } else {
  1693. peg$currPos = s3;
  1694. s3 = peg$FAILED;
  1695. }
  1696. }
  1697. while (s3 !== peg$FAILED) {
  1698. s2.push(s3);
  1699. if (peg$c58.test(input.charAt(peg$currPos))) {
  1700. s3 = input.charAt(peg$currPos);
  1701. peg$currPos++;
  1702. } else {
  1703. s3 = peg$FAILED;
  1704. {
  1705. peg$fail(peg$c59);
  1706. }
  1707. }
  1708. if (s3 === peg$FAILED) {
  1709. s3 = peg$currPos;
  1710. if (input.charCodeAt(peg$currPos) === 92) {
  1711. s4 = peg$c51;
  1712. peg$currPos++;
  1713. } else {
  1714. s4 = peg$FAILED;
  1715. {
  1716. peg$fail(peg$c52);
  1717. }
  1718. }
  1719. if (s4 !== peg$FAILED) {
  1720. if (input.length > peg$currPos) {
  1721. s5 = input.charAt(peg$currPos);
  1722. peg$currPos++;
  1723. } else {
  1724. s5 = peg$FAILED;
  1725. {
  1726. peg$fail(peg$c53);
  1727. }
  1728. }
  1729. if (s5 !== peg$FAILED) {
  1730. s4 = peg$c54(s4, s5);
  1731. s3 = s4;
  1732. } else {
  1733. peg$currPos = s3;
  1734. s3 = peg$FAILED;
  1735. }
  1736. } else {
  1737. peg$currPos = s3;
  1738. s3 = peg$FAILED;
  1739. }
  1740. }
  1741. }
  1742. if (s2 !== peg$FAILED) {
  1743. if (input.charCodeAt(peg$currPos) === 39) {
  1744. s3 = peg$c56;
  1745. peg$currPos++;
  1746. } else {
  1747. s3 = peg$FAILED;
  1748. {
  1749. peg$fail(peg$c57);
  1750. }
  1751. }
  1752. if (s3 !== peg$FAILED) {
  1753. s1 = peg$c55(s2);
  1754. s0 = s1;
  1755. } else {
  1756. peg$currPos = s0;
  1757. s0 = peg$FAILED;
  1758. }
  1759. } else {
  1760. peg$currPos = s0;
  1761. s0 = peg$FAILED;
  1762. }
  1763. } else {
  1764. peg$currPos = s0;
  1765. s0 = peg$FAILED;
  1766. }
  1767. }
  1768. peg$resultsCache[key] = {
  1769. nextPos: peg$currPos,
  1770. result: s0
  1771. };
  1772. return s0;
  1773. }
  1774. function peg$parsenumber() {
  1775. var s0, s1, s2, s3;
  1776. var key = peg$currPos * 30 + 16,
  1777. cached = peg$resultsCache[key];
  1778. if (cached) {
  1779. peg$currPos = cached.nextPos;
  1780. return cached.result;
  1781. }
  1782. s0 = peg$currPos;
  1783. s1 = peg$currPos;
  1784. s2 = [];
  1785. if (peg$c60.test(input.charAt(peg$currPos))) {
  1786. s3 = input.charAt(peg$currPos);
  1787. peg$currPos++;
  1788. } else {
  1789. s3 = peg$FAILED;
  1790. {
  1791. peg$fail(peg$c61);
  1792. }
  1793. }
  1794. while (s3 !== peg$FAILED) {
  1795. s2.push(s3);
  1796. if (peg$c60.test(input.charAt(peg$currPos))) {
  1797. s3 = input.charAt(peg$currPos);
  1798. peg$currPos++;
  1799. } else {
  1800. s3 = peg$FAILED;
  1801. {
  1802. peg$fail(peg$c61);
  1803. }
  1804. }
  1805. }
  1806. if (s2 !== peg$FAILED) {
  1807. if (input.charCodeAt(peg$currPos) === 46) {
  1808. s3 = peg$c42;
  1809. peg$currPos++;
  1810. } else {
  1811. s3 = peg$FAILED;
  1812. {
  1813. peg$fail(peg$c43);
  1814. }
  1815. }
  1816. if (s3 !== peg$FAILED) {
  1817. s2 = [s2, s3];
  1818. s1 = s2;
  1819. } else {
  1820. peg$currPos = s1;
  1821. s1 = peg$FAILED;
  1822. }
  1823. } else {
  1824. peg$currPos = s1;
  1825. s1 = peg$FAILED;
  1826. }
  1827. if (s1 === peg$FAILED) {
  1828. s1 = null;
  1829. }
  1830. if (s1 !== peg$FAILED) {
  1831. s2 = [];
  1832. if (peg$c60.test(input.charAt(peg$currPos))) {
  1833. s3 = input.charAt(peg$currPos);
  1834. peg$currPos++;
  1835. } else {
  1836. s3 = peg$FAILED;
  1837. {
  1838. peg$fail(peg$c61);
  1839. }
  1840. }
  1841. if (s3 !== peg$FAILED) {
  1842. while (s3 !== peg$FAILED) {
  1843. s2.push(s3);
  1844. if (peg$c60.test(input.charAt(peg$currPos))) {
  1845. s3 = input.charAt(peg$currPos);
  1846. peg$currPos++;
  1847. } else {
  1848. s3 = peg$FAILED;
  1849. {
  1850. peg$fail(peg$c61);
  1851. }
  1852. }
  1853. }
  1854. } else {
  1855. s2 = peg$FAILED;
  1856. }
  1857. if (s2 !== peg$FAILED) {
  1858. s1 = peg$c62(s1, s2);
  1859. s0 = s1;
  1860. } else {
  1861. peg$currPos = s0;
  1862. s0 = peg$FAILED;
  1863. }
  1864. } else {
  1865. peg$currPos = s0;
  1866. s0 = peg$FAILED;
  1867. }
  1868. peg$resultsCache[key] = {
  1869. nextPos: peg$currPos,
  1870. result: s0
  1871. };
  1872. return s0;
  1873. }
  1874. function peg$parsepath() {
  1875. var s0, s1;
  1876. var key = peg$currPos * 30 + 17,
  1877. cached = peg$resultsCache[key];
  1878. if (cached) {
  1879. peg$currPos = cached.nextPos;
  1880. return cached.result;
  1881. }
  1882. s0 = peg$currPos;
  1883. s1 = peg$parseidentifierName();
  1884. if (s1 !== peg$FAILED) {
  1885. s1 = peg$c63(s1);
  1886. }
  1887. s0 = s1;
  1888. peg$resultsCache[key] = {
  1889. nextPos: peg$currPos,
  1890. result: s0
  1891. };
  1892. return s0;
  1893. }
  1894. function peg$parsetype() {
  1895. var s0, s1, s2, s3, s4, s5;
  1896. var key = peg$currPos * 30 + 18,
  1897. cached = peg$resultsCache[key];
  1898. if (cached) {
  1899. peg$currPos = cached.nextPos;
  1900. return cached.result;
  1901. }
  1902. s0 = peg$currPos;
  1903. if (input.substr(peg$currPos, 5) === peg$c64) {
  1904. s1 = peg$c64;
  1905. peg$currPos += 5;
  1906. } else {
  1907. s1 = peg$FAILED;
  1908. {
  1909. peg$fail(peg$c65);
  1910. }
  1911. }
  1912. if (s1 !== peg$FAILED) {
  1913. s2 = peg$parse_();
  1914. if (s2 !== peg$FAILED) {
  1915. s3 = [];
  1916. if (peg$c66.test(input.charAt(peg$currPos))) {
  1917. s4 = input.charAt(peg$currPos);
  1918. peg$currPos++;
  1919. } else {
  1920. s4 = peg$FAILED;
  1921. {
  1922. peg$fail(peg$c67);
  1923. }
  1924. }
  1925. if (s4 !== peg$FAILED) {
  1926. while (s4 !== peg$FAILED) {
  1927. s3.push(s4);
  1928. if (peg$c66.test(input.charAt(peg$currPos))) {
  1929. s4 = input.charAt(peg$currPos);
  1930. peg$currPos++;
  1931. } else {
  1932. s4 = peg$FAILED;
  1933. {
  1934. peg$fail(peg$c67);
  1935. }
  1936. }
  1937. }
  1938. } else {
  1939. s3 = peg$FAILED;
  1940. }
  1941. if (s3 !== peg$FAILED) {
  1942. s4 = peg$parse_();
  1943. if (s4 !== peg$FAILED) {
  1944. if (input.charCodeAt(peg$currPos) === 41) {
  1945. s5 = peg$c68;
  1946. peg$currPos++;
  1947. } else {
  1948. s5 = peg$FAILED;
  1949. {
  1950. peg$fail(peg$c69);
  1951. }
  1952. }
  1953. if (s5 !== peg$FAILED) {
  1954. s1 = peg$c70(s3);
  1955. s0 = s1;
  1956. } else {
  1957. peg$currPos = s0;
  1958. s0 = peg$FAILED;
  1959. }
  1960. } else {
  1961. peg$currPos = s0;
  1962. s0 = peg$FAILED;
  1963. }
  1964. } else {
  1965. peg$currPos = s0;
  1966. s0 = peg$FAILED;
  1967. }
  1968. } else {
  1969. peg$currPos = s0;
  1970. s0 = peg$FAILED;
  1971. }
  1972. } else {
  1973. peg$currPos = s0;
  1974. s0 = peg$FAILED;
  1975. }
  1976. peg$resultsCache[key] = {
  1977. nextPos: peg$currPos,
  1978. result: s0
  1979. };
  1980. return s0;
  1981. }
  1982. function peg$parseflags() {
  1983. var s0, s1;
  1984. var key = peg$currPos * 30 + 19,
  1985. cached = peg$resultsCache[key];
  1986. if (cached) {
  1987. peg$currPos = cached.nextPos;
  1988. return cached.result;
  1989. }
  1990. s0 = [];
  1991. if (peg$c71.test(input.charAt(peg$currPos))) {
  1992. s1 = input.charAt(peg$currPos);
  1993. peg$currPos++;
  1994. } else {
  1995. s1 = peg$FAILED;
  1996. {
  1997. peg$fail(peg$c72);
  1998. }
  1999. }
  2000. if (s1 !== peg$FAILED) {
  2001. while (s1 !== peg$FAILED) {
  2002. s0.push(s1);
  2003. if (peg$c71.test(input.charAt(peg$currPos))) {
  2004. s1 = input.charAt(peg$currPos);
  2005. peg$currPos++;
  2006. } else {
  2007. s1 = peg$FAILED;
  2008. {
  2009. peg$fail(peg$c72);
  2010. }
  2011. }
  2012. }
  2013. } else {
  2014. s0 = peg$FAILED;
  2015. }
  2016. peg$resultsCache[key] = {
  2017. nextPos: peg$currPos,
  2018. result: s0
  2019. };
  2020. return s0;
  2021. }
  2022. function peg$parseregex() {
  2023. var s0, s1, s2, s3, s4;
  2024. var key = peg$currPos * 30 + 20,
  2025. cached = peg$resultsCache[key];
  2026. if (cached) {
  2027. peg$currPos = cached.nextPos;
  2028. return cached.result;
  2029. }
  2030. s0 = peg$currPos;
  2031. if (input.charCodeAt(peg$currPos) === 47) {
  2032. s1 = peg$c73;
  2033. peg$currPos++;
  2034. } else {
  2035. s1 = peg$FAILED;
  2036. {
  2037. peg$fail(peg$c74);
  2038. }
  2039. }
  2040. if (s1 !== peg$FAILED) {
  2041. s2 = [];
  2042. if (peg$c75.test(input.charAt(peg$currPos))) {
  2043. s3 = input.charAt(peg$currPos);
  2044. peg$currPos++;
  2045. } else {
  2046. s3 = peg$FAILED;
  2047. {
  2048. peg$fail(peg$c76);
  2049. }
  2050. }
  2051. if (s3 !== peg$FAILED) {
  2052. while (s3 !== peg$FAILED) {
  2053. s2.push(s3);
  2054. if (peg$c75.test(input.charAt(peg$currPos))) {
  2055. s3 = input.charAt(peg$currPos);
  2056. peg$currPos++;
  2057. } else {
  2058. s3 = peg$FAILED;
  2059. {
  2060. peg$fail(peg$c76);
  2061. }
  2062. }
  2063. }
  2064. } else {
  2065. s2 = peg$FAILED;
  2066. }
  2067. if (s2 !== peg$FAILED) {
  2068. if (input.charCodeAt(peg$currPos) === 47) {
  2069. s3 = peg$c73;
  2070. peg$currPos++;
  2071. } else {
  2072. s3 = peg$FAILED;
  2073. {
  2074. peg$fail(peg$c74);
  2075. }
  2076. }
  2077. if (s3 !== peg$FAILED) {
  2078. s4 = peg$parseflags();
  2079. if (s4 === peg$FAILED) {
  2080. s4 = null;
  2081. }
  2082. if (s4 !== peg$FAILED) {
  2083. s1 = peg$c77(s2, s4);
  2084. s0 = s1;
  2085. } else {
  2086. peg$currPos = s0;
  2087. s0 = peg$FAILED;
  2088. }
  2089. } else {
  2090. peg$currPos = s0;
  2091. s0 = peg$FAILED;
  2092. }
  2093. } else {
  2094. peg$currPos = s0;
  2095. s0 = peg$FAILED;
  2096. }
  2097. } else {
  2098. peg$currPos = s0;
  2099. s0 = peg$FAILED;
  2100. }
  2101. peg$resultsCache[key] = {
  2102. nextPos: peg$currPos,
  2103. result: s0
  2104. };
  2105. return s0;
  2106. }
  2107. function peg$parsefield() {
  2108. var s0, s1, s2, s3, s4, s5, s6;
  2109. var key = peg$currPos * 30 + 21,
  2110. cached = peg$resultsCache[key];
  2111. if (cached) {
  2112. peg$currPos = cached.nextPos;
  2113. return cached.result;
  2114. }
  2115. s0 = peg$currPos;
  2116. if (input.charCodeAt(peg$currPos) === 46) {
  2117. s1 = peg$c42;
  2118. peg$currPos++;
  2119. } else {
  2120. s1 = peg$FAILED;
  2121. {
  2122. peg$fail(peg$c43);
  2123. }
  2124. }
  2125. if (s1 !== peg$FAILED) {
  2126. s2 = peg$parseidentifierName();
  2127. if (s2 !== peg$FAILED) {
  2128. s3 = [];
  2129. s4 = peg$currPos;
  2130. if (input.charCodeAt(peg$currPos) === 46) {
  2131. s5 = peg$c42;
  2132. peg$currPos++;
  2133. } else {
  2134. s5 = peg$FAILED;
  2135. {
  2136. peg$fail(peg$c43);
  2137. }
  2138. }
  2139. if (s5 !== peg$FAILED) {
  2140. s6 = peg$parseidentifierName();
  2141. if (s6 !== peg$FAILED) {
  2142. s5 = [s5, s6];
  2143. s4 = s5;
  2144. } else {
  2145. peg$currPos = s4;
  2146. s4 = peg$FAILED;
  2147. }
  2148. } else {
  2149. peg$currPos = s4;
  2150. s4 = peg$FAILED;
  2151. }
  2152. while (s4 !== peg$FAILED) {
  2153. s3.push(s4);
  2154. s4 = peg$currPos;
  2155. if (input.charCodeAt(peg$currPos) === 46) {
  2156. s5 = peg$c42;
  2157. peg$currPos++;
  2158. } else {
  2159. s5 = peg$FAILED;
  2160. {
  2161. peg$fail(peg$c43);
  2162. }
  2163. }
  2164. if (s5 !== peg$FAILED) {
  2165. s6 = peg$parseidentifierName();
  2166. if (s6 !== peg$FAILED) {
  2167. s5 = [s5, s6];
  2168. s4 = s5;
  2169. } else {
  2170. peg$currPos = s4;
  2171. s4 = peg$FAILED;
  2172. }
  2173. } else {
  2174. peg$currPos = s4;
  2175. s4 = peg$FAILED;
  2176. }
  2177. }
  2178. if (s3 !== peg$FAILED) {
  2179. s1 = peg$c78(s2, s3);
  2180. s0 = s1;
  2181. } else {
  2182. peg$currPos = s0;
  2183. s0 = peg$FAILED;
  2184. }
  2185. } else {
  2186. peg$currPos = s0;
  2187. s0 = peg$FAILED;
  2188. }
  2189. } else {
  2190. peg$currPos = s0;
  2191. s0 = peg$FAILED;
  2192. }
  2193. peg$resultsCache[key] = {
  2194. nextPos: peg$currPos,
  2195. result: s0
  2196. };
  2197. return s0;
  2198. }
  2199. function peg$parsenegation() {
  2200. var s0, s1, s2, s3, s4, s5;
  2201. var key = peg$currPos * 30 + 22,
  2202. cached = peg$resultsCache[key];
  2203. if (cached) {
  2204. peg$currPos = cached.nextPos;
  2205. return cached.result;
  2206. }
  2207. s0 = peg$currPos;
  2208. if (input.substr(peg$currPos, 5) === peg$c79) {
  2209. s1 = peg$c79;
  2210. peg$currPos += 5;
  2211. } else {
  2212. s1 = peg$FAILED;
  2213. {
  2214. peg$fail(peg$c80);
  2215. }
  2216. }
  2217. if (s1 !== peg$FAILED) {
  2218. s2 = peg$parse_();
  2219. if (s2 !== peg$FAILED) {
  2220. s3 = peg$parseselectors();
  2221. if (s3 !== peg$FAILED) {
  2222. s4 = peg$parse_();
  2223. if (s4 !== peg$FAILED) {
  2224. if (input.charCodeAt(peg$currPos) === 41) {
  2225. s5 = peg$c68;
  2226. peg$currPos++;
  2227. } else {
  2228. s5 = peg$FAILED;
  2229. {
  2230. peg$fail(peg$c69);
  2231. }
  2232. }
  2233. if (s5 !== peg$FAILED) {
  2234. s1 = peg$c81(s3);
  2235. s0 = s1;
  2236. } else {
  2237. peg$currPos = s0;
  2238. s0 = peg$FAILED;
  2239. }
  2240. } else {
  2241. peg$currPos = s0;
  2242. s0 = peg$FAILED;
  2243. }
  2244. } else {
  2245. peg$currPos = s0;
  2246. s0 = peg$FAILED;
  2247. }
  2248. } else {
  2249. peg$currPos = s0;
  2250. s0 = peg$FAILED;
  2251. }
  2252. } else {
  2253. peg$currPos = s0;
  2254. s0 = peg$FAILED;
  2255. }
  2256. peg$resultsCache[key] = {
  2257. nextPos: peg$currPos,
  2258. result: s0
  2259. };
  2260. return s0;
  2261. }
  2262. function peg$parsematches() {
  2263. var s0, s1, s2, s3, s4, s5;
  2264. var key = peg$currPos * 30 + 23,
  2265. cached = peg$resultsCache[key];
  2266. if (cached) {
  2267. peg$currPos = cached.nextPos;
  2268. return cached.result;
  2269. }
  2270. s0 = peg$currPos;
  2271. if (input.substr(peg$currPos, 9) === peg$c82) {
  2272. s1 = peg$c82;
  2273. peg$currPos += 9;
  2274. } else {
  2275. s1 = peg$FAILED;
  2276. {
  2277. peg$fail(peg$c83);
  2278. }
  2279. }
  2280. if (s1 !== peg$FAILED) {
  2281. s2 = peg$parse_();
  2282. if (s2 !== peg$FAILED) {
  2283. s3 = peg$parseselectors();
  2284. if (s3 !== peg$FAILED) {
  2285. s4 = peg$parse_();
  2286. if (s4 !== peg$FAILED) {
  2287. if (input.charCodeAt(peg$currPos) === 41) {
  2288. s5 = peg$c68;
  2289. peg$currPos++;
  2290. } else {
  2291. s5 = peg$FAILED;
  2292. {
  2293. peg$fail(peg$c69);
  2294. }
  2295. }
  2296. if (s5 !== peg$FAILED) {
  2297. s1 = peg$c84(s3);
  2298. s0 = s1;
  2299. } else {
  2300. peg$currPos = s0;
  2301. s0 = peg$FAILED;
  2302. }
  2303. } else {
  2304. peg$currPos = s0;
  2305. s0 = peg$FAILED;
  2306. }
  2307. } else {
  2308. peg$currPos = s0;
  2309. s0 = peg$FAILED;
  2310. }
  2311. } else {
  2312. peg$currPos = s0;
  2313. s0 = peg$FAILED;
  2314. }
  2315. } else {
  2316. peg$currPos = s0;
  2317. s0 = peg$FAILED;
  2318. }
  2319. peg$resultsCache[key] = {
  2320. nextPos: peg$currPos,
  2321. result: s0
  2322. };
  2323. return s0;
  2324. }
  2325. function peg$parsehas() {
  2326. var s0, s1, s2, s3, s4, s5;
  2327. var key = peg$currPos * 30 + 24,
  2328. cached = peg$resultsCache[key];
  2329. if (cached) {
  2330. peg$currPos = cached.nextPos;
  2331. return cached.result;
  2332. }
  2333. s0 = peg$currPos;
  2334. if (input.substr(peg$currPos, 5) === peg$c85) {
  2335. s1 = peg$c85;
  2336. peg$currPos += 5;
  2337. } else {
  2338. s1 = peg$FAILED;
  2339. {
  2340. peg$fail(peg$c86);
  2341. }
  2342. }
  2343. if (s1 !== peg$FAILED) {
  2344. s2 = peg$parse_();
  2345. if (s2 !== peg$FAILED) {
  2346. s3 = peg$parseselectors();
  2347. if (s3 !== peg$FAILED) {
  2348. s4 = peg$parse_();
  2349. if (s4 !== peg$FAILED) {
  2350. if (input.charCodeAt(peg$currPos) === 41) {
  2351. s5 = peg$c68;
  2352. peg$currPos++;
  2353. } else {
  2354. s5 = peg$FAILED;
  2355. {
  2356. peg$fail(peg$c69);
  2357. }
  2358. }
  2359. if (s5 !== peg$FAILED) {
  2360. s1 = peg$c87(s3);
  2361. s0 = s1;
  2362. } else {
  2363. peg$currPos = s0;
  2364. s0 = peg$FAILED;
  2365. }
  2366. } else {
  2367. peg$currPos = s0;
  2368. s0 = peg$FAILED;
  2369. }
  2370. } else {
  2371. peg$currPos = s0;
  2372. s0 = peg$FAILED;
  2373. }
  2374. } else {
  2375. peg$currPos = s0;
  2376. s0 = peg$FAILED;
  2377. }
  2378. } else {
  2379. peg$currPos = s0;
  2380. s0 = peg$FAILED;
  2381. }
  2382. peg$resultsCache[key] = {
  2383. nextPos: peg$currPos,
  2384. result: s0
  2385. };
  2386. return s0;
  2387. }
  2388. function peg$parsefirstChild() {
  2389. var s0, s1;
  2390. var key = peg$currPos * 30 + 25,
  2391. cached = peg$resultsCache[key];
  2392. if (cached) {
  2393. peg$currPos = cached.nextPos;
  2394. return cached.result;
  2395. }
  2396. s0 = peg$currPos;
  2397. if (input.substr(peg$currPos, 12) === peg$c88) {
  2398. s1 = peg$c88;
  2399. peg$currPos += 12;
  2400. } else {
  2401. s1 = peg$FAILED;
  2402. {
  2403. peg$fail(peg$c89);
  2404. }
  2405. }
  2406. if (s1 !== peg$FAILED) {
  2407. s1 = peg$c90();
  2408. }
  2409. s0 = s1;
  2410. peg$resultsCache[key] = {
  2411. nextPos: peg$currPos,
  2412. result: s0
  2413. };
  2414. return s0;
  2415. }
  2416. function peg$parselastChild() {
  2417. var s0, s1;
  2418. var key = peg$currPos * 30 + 26,
  2419. cached = peg$resultsCache[key];
  2420. if (cached) {
  2421. peg$currPos = cached.nextPos;
  2422. return cached.result;
  2423. }
  2424. s0 = peg$currPos;
  2425. if (input.substr(peg$currPos, 11) === peg$c91) {
  2426. s1 = peg$c91;
  2427. peg$currPos += 11;
  2428. } else {
  2429. s1 = peg$FAILED;
  2430. {
  2431. peg$fail(peg$c92);
  2432. }
  2433. }
  2434. if (s1 !== peg$FAILED) {
  2435. s1 = peg$c93();
  2436. }
  2437. s0 = s1;
  2438. peg$resultsCache[key] = {
  2439. nextPos: peg$currPos,
  2440. result: s0
  2441. };
  2442. return s0;
  2443. }
  2444. function peg$parsenthChild() {
  2445. var s0, s1, s2, s3, s4, s5;
  2446. var key = peg$currPos * 30 + 27,
  2447. cached = peg$resultsCache[key];
  2448. if (cached) {
  2449. peg$currPos = cached.nextPos;
  2450. return cached.result;
  2451. }
  2452. s0 = peg$currPos;
  2453. if (input.substr(peg$currPos, 11) === peg$c94) {
  2454. s1 = peg$c94;
  2455. peg$currPos += 11;
  2456. } else {
  2457. s1 = peg$FAILED;
  2458. {
  2459. peg$fail(peg$c95);
  2460. }
  2461. }
  2462. if (s1 !== peg$FAILED) {
  2463. s2 = peg$parse_();
  2464. if (s2 !== peg$FAILED) {
  2465. s3 = [];
  2466. if (peg$c60.test(input.charAt(peg$currPos))) {
  2467. s4 = input.charAt(peg$currPos);
  2468. peg$currPos++;
  2469. } else {
  2470. s4 = peg$FAILED;
  2471. {
  2472. peg$fail(peg$c61);
  2473. }
  2474. }
  2475. if (s4 !== peg$FAILED) {
  2476. while (s4 !== peg$FAILED) {
  2477. s3.push(s4);
  2478. if (peg$c60.test(input.charAt(peg$currPos))) {
  2479. s4 = input.charAt(peg$currPos);
  2480. peg$currPos++;
  2481. } else {
  2482. s4 = peg$FAILED;
  2483. {
  2484. peg$fail(peg$c61);
  2485. }
  2486. }
  2487. }
  2488. } else {
  2489. s3 = peg$FAILED;
  2490. }
  2491. if (s3 !== peg$FAILED) {
  2492. s4 = peg$parse_();
  2493. if (s4 !== peg$FAILED) {
  2494. if (input.charCodeAt(peg$currPos) === 41) {
  2495. s5 = peg$c68;
  2496. peg$currPos++;
  2497. } else {
  2498. s5 = peg$FAILED;
  2499. {
  2500. peg$fail(peg$c69);
  2501. }
  2502. }
  2503. if (s5 !== peg$FAILED) {
  2504. s1 = peg$c96(s3);
  2505. s0 = s1;
  2506. } else {
  2507. peg$currPos = s0;
  2508. s0 = peg$FAILED;
  2509. }
  2510. } else {
  2511. peg$currPos = s0;
  2512. s0 = peg$FAILED;
  2513. }
  2514. } else {
  2515. peg$currPos = s0;
  2516. s0 = peg$FAILED;
  2517. }
  2518. } else {
  2519. peg$currPos = s0;
  2520. s0 = peg$FAILED;
  2521. }
  2522. } else {
  2523. peg$currPos = s0;
  2524. s0 = peg$FAILED;
  2525. }
  2526. peg$resultsCache[key] = {
  2527. nextPos: peg$currPos,
  2528. result: s0
  2529. };
  2530. return s0;
  2531. }
  2532. function peg$parsenthLastChild() {
  2533. var s0, s1, s2, s3, s4, s5;
  2534. var key = peg$currPos * 30 + 28,
  2535. cached = peg$resultsCache[key];
  2536. if (cached) {
  2537. peg$currPos = cached.nextPos;
  2538. return cached.result;
  2539. }
  2540. s0 = peg$currPos;
  2541. if (input.substr(peg$currPos, 16) === peg$c97) {
  2542. s1 = peg$c97;
  2543. peg$currPos += 16;
  2544. } else {
  2545. s1 = peg$FAILED;
  2546. {
  2547. peg$fail(peg$c98);
  2548. }
  2549. }
  2550. if (s1 !== peg$FAILED) {
  2551. s2 = peg$parse_();
  2552. if (s2 !== peg$FAILED) {
  2553. s3 = [];
  2554. if (peg$c60.test(input.charAt(peg$currPos))) {
  2555. s4 = input.charAt(peg$currPos);
  2556. peg$currPos++;
  2557. } else {
  2558. s4 = peg$FAILED;
  2559. {
  2560. peg$fail(peg$c61);
  2561. }
  2562. }
  2563. if (s4 !== peg$FAILED) {
  2564. while (s4 !== peg$FAILED) {
  2565. s3.push(s4);
  2566. if (peg$c60.test(input.charAt(peg$currPos))) {
  2567. s4 = input.charAt(peg$currPos);
  2568. peg$currPos++;
  2569. } else {
  2570. s4 = peg$FAILED;
  2571. {
  2572. peg$fail(peg$c61);
  2573. }
  2574. }
  2575. }
  2576. } else {
  2577. s3 = peg$FAILED;
  2578. }
  2579. if (s3 !== peg$FAILED) {
  2580. s4 = peg$parse_();
  2581. if (s4 !== peg$FAILED) {
  2582. if (input.charCodeAt(peg$currPos) === 41) {
  2583. s5 = peg$c68;
  2584. peg$currPos++;
  2585. } else {
  2586. s5 = peg$FAILED;
  2587. {
  2588. peg$fail(peg$c69);
  2589. }
  2590. }
  2591. if (s5 !== peg$FAILED) {
  2592. s1 = peg$c99(s3);
  2593. s0 = s1;
  2594. } else {
  2595. peg$currPos = s0;
  2596. s0 = peg$FAILED;
  2597. }
  2598. } else {
  2599. peg$currPos = s0;
  2600. s0 = peg$FAILED;
  2601. }
  2602. } else {
  2603. peg$currPos = s0;
  2604. s0 = peg$FAILED;
  2605. }
  2606. } else {
  2607. peg$currPos = s0;
  2608. s0 = peg$FAILED;
  2609. }
  2610. } else {
  2611. peg$currPos = s0;
  2612. s0 = peg$FAILED;
  2613. }
  2614. peg$resultsCache[key] = {
  2615. nextPos: peg$currPos,
  2616. result: s0
  2617. };
  2618. return s0;
  2619. }
  2620. function peg$parseclass() {
  2621. var s0, s1, s2;
  2622. var key = peg$currPos * 30 + 29,
  2623. cached = peg$resultsCache[key];
  2624. if (cached) {
  2625. peg$currPos = cached.nextPos;
  2626. return cached.result;
  2627. }
  2628. s0 = peg$currPos;
  2629. if (input.charCodeAt(peg$currPos) === 58) {
  2630. s1 = peg$c100;
  2631. peg$currPos++;
  2632. } else {
  2633. s1 = peg$FAILED;
  2634. {
  2635. peg$fail(peg$c101);
  2636. }
  2637. }
  2638. if (s1 !== peg$FAILED) {
  2639. if (input.substr(peg$currPos, 9).toLowerCase() === peg$c102) {
  2640. s2 = input.substr(peg$currPos, 9);
  2641. peg$currPos += 9;
  2642. } else {
  2643. s2 = peg$FAILED;
  2644. {
  2645. peg$fail(peg$c103);
  2646. }
  2647. }
  2648. if (s2 === peg$FAILED) {
  2649. if (input.substr(peg$currPos, 10).toLowerCase() === peg$c104) {
  2650. s2 = input.substr(peg$currPos, 10);
  2651. peg$currPos += 10;
  2652. } else {
  2653. s2 = peg$FAILED;
  2654. {
  2655. peg$fail(peg$c105);
  2656. }
  2657. }
  2658. if (s2 === peg$FAILED) {
  2659. if (input.substr(peg$currPos, 11).toLowerCase() === peg$c106) {
  2660. s2 = input.substr(peg$currPos, 11);
  2661. peg$currPos += 11;
  2662. } else {
  2663. s2 = peg$FAILED;
  2664. {
  2665. peg$fail(peg$c107);
  2666. }
  2667. }
  2668. if (s2 === peg$FAILED) {
  2669. if (input.substr(peg$currPos, 8).toLowerCase() === peg$c108) {
  2670. s2 = input.substr(peg$currPos, 8);
  2671. peg$currPos += 8;
  2672. } else {
  2673. s2 = peg$FAILED;
  2674. {
  2675. peg$fail(peg$c109);
  2676. }
  2677. }
  2678. if (s2 === peg$FAILED) {
  2679. if (input.substr(peg$currPos, 7).toLowerCase() === peg$c110) {
  2680. s2 = input.substr(peg$currPos, 7);
  2681. peg$currPos += 7;
  2682. } else {
  2683. s2 = peg$FAILED;
  2684. {
  2685. peg$fail(peg$c111);
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. }
  2692. if (s2 !== peg$FAILED) {
  2693. s1 = peg$c112(s2);
  2694. s0 = s1;
  2695. } else {
  2696. peg$currPos = s0;
  2697. s0 = peg$FAILED;
  2698. }
  2699. } else {
  2700. peg$currPos = s0;
  2701. s0 = peg$FAILED;
  2702. }
  2703. peg$resultsCache[key] = {
  2704. nextPos: peg$currPos,
  2705. result: s0
  2706. };
  2707. return s0;
  2708. }
  2709. function nth(n) {
  2710. return {
  2711. type: 'nth-child',
  2712. index: {
  2713. type: 'literal',
  2714. value: n
  2715. }
  2716. };
  2717. }
  2718. function nthLast(n) {
  2719. return {
  2720. type: 'nth-last-child',
  2721. index: {
  2722. type: 'literal',
  2723. value: n
  2724. }
  2725. };
  2726. }
  2727. function strUnescape(s) {
  2728. return s.replace(/\\(.)/g, function (match, ch) {
  2729. switch (ch) {
  2730. case 'b':
  2731. return '\b';
  2732. case 'f':
  2733. return '\f';
  2734. case 'n':
  2735. return '\n';
  2736. case 'r':
  2737. return '\r';
  2738. case 't':
  2739. return '\t';
  2740. case 'v':
  2741. return '\v';
  2742. default:
  2743. return ch;
  2744. }
  2745. });
  2746. }
  2747. peg$result = peg$startRuleFunction();
  2748. if (peg$result !== peg$FAILED && peg$currPos === input.length) {
  2749. return peg$result;
  2750. } else {
  2751. if (peg$result !== peg$FAILED && peg$currPos < input.length) {
  2752. peg$fail(peg$endExpectation());
  2753. }
  2754. throw peg$buildStructuredError(peg$maxFailExpected, peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : peg$computeLocation(peg$maxFailPos, peg$maxFailPos));
  2755. }
  2756. }
  2757. return {
  2758. SyntaxError: peg$SyntaxError,
  2759. parse: peg$parse
  2760. };
  2761. });
  2762. });
  2763. function _objectEntries(obj) {
  2764. var entries = [];
  2765. var keys = Object.keys(obj);
  2766. for (var k = 0; k < keys.length; k++) entries.push([keys[k], obj[keys[k]]]);
  2767. return entries;
  2768. }
  2769. /**
  2770. * @typedef {"LEFT_SIDE"|"RIGHT_SIDE"} Side
  2771. */
  2772. var LEFT_SIDE = 'LEFT_SIDE';
  2773. var RIGHT_SIDE = 'RIGHT_SIDE';
  2774. /**
  2775. * @external AST
  2776. * @see https://esprima.readthedocs.io/en/latest/syntax-tree-format.html
  2777. */
  2778. /**
  2779. * One of the rules of `grammar.pegjs`
  2780. * @typedef {PlainObject} SelectorAST
  2781. * @see grammar.pegjs
  2782. */
  2783. /**
  2784. * The `sequence` production of `grammar.pegjs`
  2785. * @typedef {PlainObject} SelectorSequenceAST
  2786. */
  2787. /**
  2788. * Get the value of a property which may be multiple levels down
  2789. * in the object.
  2790. * @param {?PlainObject} obj
  2791. * @param {string} key
  2792. * @returns {undefined|boolean|string|number|external:AST}
  2793. */
  2794. function getPath(obj, key) {
  2795. var keys = key.split('.');
  2796. var _iterator = _createForOfIteratorHelper(keys),
  2797. _step;
  2798. try {
  2799. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  2800. var _key = _step.value;
  2801. if (obj == null) {
  2802. return obj;
  2803. }
  2804. obj = obj[_key];
  2805. }
  2806. } catch (err) {
  2807. _iterator.e(err);
  2808. } finally {
  2809. _iterator.f();
  2810. }
  2811. return obj;
  2812. }
  2813. /**
  2814. * Determine whether `node` can be reached by following `path`,
  2815. * starting at `ancestor`.
  2816. * @param {?external:AST} node
  2817. * @param {?external:AST} ancestor
  2818. * @param {string[]} path
  2819. * @returns {boolean}
  2820. */
  2821. function inPath(node, ancestor, path) {
  2822. if (path.length === 0) {
  2823. return node === ancestor;
  2824. }
  2825. if (ancestor == null) {
  2826. return false;
  2827. }
  2828. var field = ancestor[path[0]];
  2829. var remainingPath = path.slice(1);
  2830. if (Array.isArray(field)) {
  2831. var _iterator2 = _createForOfIteratorHelper(field),
  2832. _step2;
  2833. try {
  2834. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  2835. var component = _step2.value;
  2836. if (inPath(node, component, remainingPath)) {
  2837. return true;
  2838. }
  2839. }
  2840. } catch (err) {
  2841. _iterator2.e(err);
  2842. } finally {
  2843. _iterator2.f();
  2844. }
  2845. return false;
  2846. } else {
  2847. return inPath(node, field, remainingPath);
  2848. }
  2849. }
  2850. /**
  2851. * @callback TraverseOptionFallback
  2852. * @param {external:AST} node The given node.
  2853. * @returns {string[]} An array of visitor keys for the given node.
  2854. */
  2855. /**
  2856. * @typedef {object} ESQueryOptions
  2857. * @property { { [nodeType: string]: string[] } } [visitorKeys] By passing `visitorKeys` mapping, we can extend the properties of the nodes that traverse the node.
  2858. * @property {TraverseOptionFallback} [fallback] By passing `fallback` option, we can control the properties of traversing nodes when encountering unknown nodes.
  2859. */
  2860. /**
  2861. * Given a `node` and its ancestors, determine if `node` is matched
  2862. * by `selector`.
  2863. * @param {?external:AST} node
  2864. * @param {?SelectorAST} selector
  2865. * @param {external:AST[]} [ancestry=[]]
  2866. * @param {ESQueryOptions} [options]
  2867. * @throws {Error} Unknowns (operator, class name, selector type, or
  2868. * selector value type)
  2869. * @returns {boolean}
  2870. */
  2871. function matches(node, selector, ancestry, options) {
  2872. if (!selector) {
  2873. return true;
  2874. }
  2875. if (!node) {
  2876. return false;
  2877. }
  2878. if (!ancestry) {
  2879. ancestry = [];
  2880. }
  2881. switch (selector.type) {
  2882. case 'wildcard':
  2883. return true;
  2884. case 'identifier':
  2885. return selector.value.toLowerCase() === node.type.toLowerCase();
  2886. case 'field':
  2887. {
  2888. var path = selector.name.split('.');
  2889. var ancestor = ancestry[path.length - 1];
  2890. return inPath(node, ancestor, path);
  2891. }
  2892. case 'matches':
  2893. var _iterator3 = _createForOfIteratorHelper(selector.selectors),
  2894. _step3;
  2895. try {
  2896. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  2897. var sel = _step3.value;
  2898. if (matches(node, sel, ancestry, options)) {
  2899. return true;
  2900. }
  2901. }
  2902. } catch (err) {
  2903. _iterator3.e(err);
  2904. } finally {
  2905. _iterator3.f();
  2906. }
  2907. return false;
  2908. case 'compound':
  2909. var _iterator4 = _createForOfIteratorHelper(selector.selectors),
  2910. _step4;
  2911. try {
  2912. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  2913. var _sel = _step4.value;
  2914. if (!matches(node, _sel, ancestry, options)) {
  2915. return false;
  2916. }
  2917. }
  2918. } catch (err) {
  2919. _iterator4.e(err);
  2920. } finally {
  2921. _iterator4.f();
  2922. }
  2923. return true;
  2924. case 'not':
  2925. var _iterator5 = _createForOfIteratorHelper(selector.selectors),
  2926. _step5;
  2927. try {
  2928. for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
  2929. var _sel2 = _step5.value;
  2930. if (matches(node, _sel2, ancestry, options)) {
  2931. return false;
  2932. }
  2933. }
  2934. } catch (err) {
  2935. _iterator5.e(err);
  2936. } finally {
  2937. _iterator5.f();
  2938. }
  2939. return true;
  2940. case 'has':
  2941. {
  2942. var _ret = function () {
  2943. var collector = [];
  2944. var _iterator6 = _createForOfIteratorHelper(selector.selectors),
  2945. _step6;
  2946. try {
  2947. var _loop = function _loop() {
  2948. var sel = _step6.value;
  2949. var a = [];
  2950. estraverse.traverse(node, {
  2951. enter: function enter(node, parent) {
  2952. if (parent != null) {
  2953. a.unshift(parent);
  2954. }
  2955. if (matches(node, sel, a, options)) {
  2956. collector.push(node);
  2957. }
  2958. },
  2959. leave: function leave() {
  2960. a.shift();
  2961. },
  2962. keys: options && options.visitorKeys,
  2963. fallback: options && options.fallback || 'iteration'
  2964. });
  2965. };
  2966. for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
  2967. _loop();
  2968. }
  2969. } catch (err) {
  2970. _iterator6.e(err);
  2971. } finally {
  2972. _iterator6.f();
  2973. }
  2974. return {
  2975. v: collector.length !== 0
  2976. };
  2977. }();
  2978. if (_typeof(_ret) === "object") return _ret.v;
  2979. }
  2980. case 'child':
  2981. if (matches(node, selector.right, ancestry, options)) {
  2982. return matches(ancestry[0], selector.left, ancestry.slice(1), options);
  2983. }
  2984. return false;
  2985. case 'descendant':
  2986. if (matches(node, selector.right, ancestry, options)) {
  2987. for (var i = 0, l = ancestry.length; i < l; ++i) {
  2988. if (matches(ancestry[i], selector.left, ancestry.slice(i + 1), options)) {
  2989. return true;
  2990. }
  2991. }
  2992. }
  2993. return false;
  2994. case 'attribute':
  2995. {
  2996. var p = getPath(node, selector.name);
  2997. switch (selector.operator) {
  2998. case void 0:
  2999. return p != null;
  3000. case '=':
  3001. switch (selector.value.type) {
  3002. case 'regexp':
  3003. return typeof p === 'string' && selector.value.value.test(p);
  3004. case 'literal':
  3005. return "".concat(selector.value.value) === "".concat(p);
  3006. case 'type':
  3007. return selector.value.value === _typeof(p);
  3008. }
  3009. throw new Error("Unknown selector value type: ".concat(selector.value.type));
  3010. case '!=':
  3011. switch (selector.value.type) {
  3012. case 'regexp':
  3013. return !selector.value.value.test(p);
  3014. case 'literal':
  3015. return "".concat(selector.value.value) !== "".concat(p);
  3016. case 'type':
  3017. return selector.value.value !== _typeof(p);
  3018. }
  3019. throw new Error("Unknown selector value type: ".concat(selector.value.type));
  3020. case '<=':
  3021. return p <= selector.value.value;
  3022. case '<':
  3023. return p < selector.value.value;
  3024. case '>':
  3025. return p > selector.value.value;
  3026. case '>=':
  3027. return p >= selector.value.value;
  3028. }
  3029. throw new Error("Unknown operator: ".concat(selector.operator));
  3030. }
  3031. case 'sibling':
  3032. return matches(node, selector.right, ancestry, options) && sibling(node, selector.left, ancestry, LEFT_SIDE, options) || selector.left.subject && matches(node, selector.left, ancestry, options) && sibling(node, selector.right, ancestry, RIGHT_SIDE, options);
  3033. case 'adjacent':
  3034. return matches(node, selector.right, ancestry, options) && adjacent(node, selector.left, ancestry, LEFT_SIDE, options) || selector.right.subject && matches(node, selector.left, ancestry, options) && adjacent(node, selector.right, ancestry, RIGHT_SIDE, options);
  3035. case 'nth-child':
  3036. return matches(node, selector.right, ancestry, options) && nthChild(node, ancestry, function () {
  3037. return selector.index.value - 1;
  3038. }, options);
  3039. case 'nth-last-child':
  3040. return matches(node, selector.right, ancestry, options) && nthChild(node, ancestry, function (length) {
  3041. return length - selector.index.value;
  3042. }, options);
  3043. case 'class':
  3044. switch (selector.name.toLowerCase()) {
  3045. case 'statement':
  3046. if (node.type.slice(-9) === 'Statement') return true;
  3047. // fallthrough: interface Declaration <: Statement { }
  3048. case 'declaration':
  3049. return node.type.slice(-11) === 'Declaration';
  3050. case 'pattern':
  3051. if (node.type.slice(-7) === 'Pattern') return true;
  3052. // fallthrough: interface Expression <: Node, Pattern { }
  3053. case 'expression':
  3054. return node.type.slice(-10) === 'Expression' || node.type.slice(-7) === 'Literal' || node.type === 'Identifier' && (ancestry.length === 0 || ancestry[0].type !== 'MetaProperty') || node.type === 'MetaProperty';
  3055. case 'function':
  3056. return node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression';
  3057. }
  3058. throw new Error("Unknown class name: ".concat(selector.name));
  3059. }
  3060. throw new Error("Unknown selector type: ".concat(selector.type));
  3061. }
  3062. /**
  3063. * Get visitor keys of a given node.
  3064. * @param {external:AST} node The AST node to get keys.
  3065. * @param {ESQueryOptions|undefined} options
  3066. * @returns {string[]} Visitor keys of the node.
  3067. */
  3068. function getVisitorKeys(node, options) {
  3069. var nodeType = node.type;
  3070. if (options && options.visitorKeys && options.visitorKeys[nodeType]) {
  3071. return options.visitorKeys[nodeType];
  3072. }
  3073. if (estraverse.VisitorKeys[nodeType]) {
  3074. return estraverse.VisitorKeys[nodeType];
  3075. }
  3076. if (options && typeof options.fallback === 'function') {
  3077. return options.fallback(node);
  3078. } // 'iteration' fallback
  3079. return Object.keys(node).filter(function (key) {
  3080. return key !== 'type';
  3081. });
  3082. }
  3083. /**
  3084. * Check whether the given value is an ASTNode or not.
  3085. * @param {any} node The value to check.
  3086. * @returns {boolean} `true` if the value is an ASTNode.
  3087. */
  3088. function isNode(node) {
  3089. return node !== null && _typeof(node) === 'object' && typeof node.type === 'string';
  3090. }
  3091. /**
  3092. * Determines if the given node has a sibling that matches the
  3093. * given selector.
  3094. * @param {external:AST} node
  3095. * @param {SelectorSequenceAST} selector
  3096. * @param {external:AST[]} ancestry
  3097. * @param {Side} side
  3098. * @param {ESQueryOptions|undefined} options
  3099. * @returns {boolean}
  3100. */
  3101. function sibling(node, selector, ancestry, side, options) {
  3102. var _ancestry = _slicedToArray(ancestry, 1),
  3103. parent = _ancestry[0];
  3104. if (!parent) {
  3105. return false;
  3106. }
  3107. var keys = getVisitorKeys(parent, options);
  3108. var _iterator7 = _createForOfIteratorHelper(keys),
  3109. _step7;
  3110. try {
  3111. for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
  3112. var key = _step7.value;
  3113. var listProp = parent[key];
  3114. if (Array.isArray(listProp)) {
  3115. var startIndex = listProp.indexOf(node);
  3116. if (startIndex < 0) {
  3117. continue;
  3118. }
  3119. var lowerBound = void 0,
  3120. upperBound = void 0;
  3121. if (side === LEFT_SIDE) {
  3122. lowerBound = 0;
  3123. upperBound = startIndex;
  3124. } else {
  3125. lowerBound = startIndex + 1;
  3126. upperBound = listProp.length;
  3127. }
  3128. for (var k = lowerBound; k < upperBound; ++k) {
  3129. if (isNode(listProp[k]) && matches(listProp[k], selector, ancestry, options)) {
  3130. return true;
  3131. }
  3132. }
  3133. }
  3134. }
  3135. } catch (err) {
  3136. _iterator7.e(err);
  3137. } finally {
  3138. _iterator7.f();
  3139. }
  3140. return false;
  3141. }
  3142. /**
  3143. * Determines if the given node has an adjacent sibling that matches
  3144. * the given selector.
  3145. * @param {external:AST} node
  3146. * @param {SelectorSequenceAST} selector
  3147. * @param {external:AST[]} ancestry
  3148. * @param {Side} side
  3149. * @param {ESQueryOptions|undefined} options
  3150. * @returns {boolean}
  3151. */
  3152. function adjacent(node, selector, ancestry, side, options) {
  3153. var _ancestry2 = _slicedToArray(ancestry, 1),
  3154. parent = _ancestry2[0];
  3155. if (!parent) {
  3156. return false;
  3157. }
  3158. var keys = getVisitorKeys(parent, options);
  3159. var _iterator8 = _createForOfIteratorHelper(keys),
  3160. _step8;
  3161. try {
  3162. for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
  3163. var key = _step8.value;
  3164. var listProp = parent[key];
  3165. if (Array.isArray(listProp)) {
  3166. var idx = listProp.indexOf(node);
  3167. if (idx < 0) {
  3168. continue;
  3169. }
  3170. if (side === LEFT_SIDE && idx > 0 && isNode(listProp[idx - 1]) && matches(listProp[idx - 1], selector, ancestry, options)) {
  3171. return true;
  3172. }
  3173. if (side === RIGHT_SIDE && idx < listProp.length - 1 && isNode(listProp[idx + 1]) && matches(listProp[idx + 1], selector, ancestry, options)) {
  3174. return true;
  3175. }
  3176. }
  3177. }
  3178. } catch (err) {
  3179. _iterator8.e(err);
  3180. } finally {
  3181. _iterator8.f();
  3182. }
  3183. return false;
  3184. }
  3185. /**
  3186. * @callback IndexFunction
  3187. * @param {Integer} len Containing list's length
  3188. * @returns {Integer}
  3189. */
  3190. /**
  3191. * Determines if the given node is the nth child, determined by
  3192. * `idxFn`, which is given the containing list's length.
  3193. * @param {external:AST} node
  3194. * @param {external:AST[]} ancestry
  3195. * @param {IndexFunction} idxFn
  3196. * @param {ESQueryOptions|undefined} options
  3197. * @returns {boolean}
  3198. */
  3199. function nthChild(node, ancestry, idxFn, options) {
  3200. var _ancestry3 = _slicedToArray(ancestry, 1),
  3201. parent = _ancestry3[0];
  3202. if (!parent) {
  3203. return false;
  3204. }
  3205. var keys = getVisitorKeys(parent, options);
  3206. var _iterator9 = _createForOfIteratorHelper(keys),
  3207. _step9;
  3208. try {
  3209. for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
  3210. var key = _step9.value;
  3211. var listProp = parent[key];
  3212. if (Array.isArray(listProp)) {
  3213. var idx = listProp.indexOf(node);
  3214. if (idx >= 0 && idx === idxFn(listProp.length)) {
  3215. return true;
  3216. }
  3217. }
  3218. }
  3219. } catch (err) {
  3220. _iterator9.e(err);
  3221. } finally {
  3222. _iterator9.f();
  3223. }
  3224. return false;
  3225. }
  3226. /**
  3227. * For each selector node marked as a subject, find the portion of the
  3228. * selector that the subject must match.
  3229. * @param {SelectorAST} selector
  3230. * @param {SelectorAST} [ancestor] Defaults to `selector`
  3231. * @returns {SelectorAST[]}
  3232. */
  3233. function subjects(selector, ancestor) {
  3234. if (selector == null || _typeof(selector) != 'object') {
  3235. return [];
  3236. }
  3237. if (ancestor == null) {
  3238. ancestor = selector;
  3239. }
  3240. var results = selector.subject ? [ancestor] : [];
  3241. for (var _i = 0, _Object$entries = _objectEntries(selector); _i < _Object$entries.length; _i++) {
  3242. var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
  3243. p = _Object$entries$_i[0],
  3244. sel = _Object$entries$_i[1];
  3245. results.push.apply(results, _toConsumableArray(subjects(sel, p === 'left' ? sel : ancestor)));
  3246. }
  3247. return results;
  3248. }
  3249. /**
  3250. * @callback TraverseVisitor
  3251. * @param {?external:AST} node
  3252. * @param {?external:AST} parent
  3253. * @param {external:AST[]} ancestry
  3254. */
  3255. /**
  3256. * From a JS AST and a selector AST, collect all JS AST nodes that
  3257. * match the selector.
  3258. * @param {external:AST} ast
  3259. * @param {?SelectorAST} selector
  3260. * @param {TraverseVisitor} visitor
  3261. * @param {ESQueryOptions} [options]
  3262. * @returns {external:AST[]}
  3263. */
  3264. function traverse(ast, selector, visitor, options) {
  3265. if (!selector) {
  3266. return;
  3267. }
  3268. var ancestry = [];
  3269. var altSubjects = subjects(selector);
  3270. estraverse.traverse(ast, {
  3271. enter: function enter(node, parent) {
  3272. if (parent != null) {
  3273. ancestry.unshift(parent);
  3274. }
  3275. if (matches(node, selector, ancestry, options)) {
  3276. if (altSubjects.length) {
  3277. for (var i = 0, l = altSubjects.length; i < l; ++i) {
  3278. if (matches(node, altSubjects[i], ancestry, options)) {
  3279. visitor(node, parent, ancestry);
  3280. }
  3281. for (var k = 0, m = ancestry.length; k < m; ++k) {
  3282. var succeedingAncestry = ancestry.slice(k + 1);
  3283. if (matches(ancestry[k], altSubjects[i], succeedingAncestry, options)) {
  3284. visitor(ancestry[k], parent, succeedingAncestry);
  3285. }
  3286. }
  3287. }
  3288. } else {
  3289. visitor(node, parent, ancestry);
  3290. }
  3291. }
  3292. },
  3293. leave: function leave() {
  3294. ancestry.shift();
  3295. },
  3296. keys: options && options.visitorKeys,
  3297. fallback: options && options.fallback || 'iteration'
  3298. });
  3299. }
  3300. /**
  3301. * From a JS AST and a selector AST, collect all JS AST nodes that
  3302. * match the selector.
  3303. * @param {external:AST} ast
  3304. * @param {?SelectorAST} selector
  3305. * @param {ESQueryOptions} [options]
  3306. * @returns {external:AST[]}
  3307. */
  3308. function match(ast, selector, options) {
  3309. var results = [];
  3310. traverse(ast, selector, function (node) {
  3311. results.push(node);
  3312. }, options);
  3313. return results;
  3314. }
  3315. /**
  3316. * Parse a selector string and return its AST.
  3317. * @param {string} selector
  3318. * @returns {SelectorAST}
  3319. */
  3320. function parse(selector) {
  3321. return parser.parse(selector);
  3322. }
  3323. /**
  3324. * Query the code AST using the selector string.
  3325. * @param {external:AST} ast
  3326. * @param {string} selector
  3327. * @param {ESQueryOptions} [options]
  3328. * @returns {external:AST[]}
  3329. */
  3330. function query(ast, selector, options) {
  3331. return match(ast, parse(selector), options);
  3332. }
  3333. query.parse = parse;
  3334. query.match = match;
  3335. query.traverse = traverse;
  3336. query.matches = matches;
  3337. query.query = query;
  3338. return query;
  3339. })));