parser.js 120 KB

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