parser.js 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808
  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. this.$ = yyvstack[yysp - 1];
  780. break;
  781. case 3:
  782. /*! Production:: math_expression : math_expression ADD math_expression */
  783. case 4:
  784. /*! Production:: math_expression : math_expression SUB math_expression */
  785. case 5:
  786. /*! Production:: math_expression : math_expression MUL math_expression */
  787. case 6:
  788. /*! Production:: math_expression : math_expression DIV math_expression */
  789. this.$ = { type: 'MathExpression', operator: yyvstack[yysp - 1], left: yyvstack[yysp - 2], right: yyvstack[yysp] };
  790. break;
  791. case 7:
  792. /*! Production:: math_expression : LPAREN math_expression RPAREN */
  793. this.$ = { type: 'ParenthesizedExpression', content: yyvstack[yysp - 1] };
  794. break;
  795. case 8:
  796. /*! Production:: math_expression : function */
  797. case 9:
  798. /*! Production:: math_expression : dimension */
  799. case 10:
  800. /*! Production:: math_expression : number */
  801. this.$ = yyvstack[yysp];
  802. break;
  803. case 11:
  804. /*! Production:: function : FUNCTION */
  805. this.$ = { type: 'Function', value: yyvstack[yysp] };
  806. break;
  807. case 12:
  808. /*! Production:: dimension : LENGTH */
  809. this.$ = { type: 'LengthValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
  810. break;
  811. case 13:
  812. /*! Production:: dimension : ANGLE */
  813. this.$ = { type: 'AngleValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
  814. break;
  815. case 14:
  816. /*! Production:: dimension : TIME */
  817. this.$ = { type: 'TimeValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
  818. break;
  819. case 15:
  820. /*! Production:: dimension : FREQ */
  821. this.$ = { type: 'FrequencyValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
  822. break;
  823. case 16:
  824. /*! Production:: dimension : RES */
  825. this.$ = { type: 'ResolutionValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
  826. break;
  827. case 17:
  828. /*! Production:: dimension : UNKNOWN_DIMENSION */
  829. this.$ = { type: 'UnknownDimension', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+$/i.exec(yyvstack[yysp])[0] };
  830. break;
  831. case 18:
  832. /*! Production:: dimension : EMS */
  833. this.$ = { type: 'EmValue', value: parseFloat(yyvstack[yysp]), unit: 'em' };
  834. break;
  835. case 19:
  836. /*! Production:: dimension : EXS */
  837. this.$ = { type: 'ExValue', value: parseFloat(yyvstack[yysp]), unit: 'ex' };
  838. break;
  839. case 20:
  840. /*! Production:: dimension : CHS */
  841. this.$ = { type: 'ChValue', value: parseFloat(yyvstack[yysp]), unit: 'ch' };
  842. break;
  843. case 21:
  844. /*! Production:: dimension : REMS */
  845. this.$ = { type: 'RemValue', value: parseFloat(yyvstack[yysp]), unit: 'rem' };
  846. break;
  847. case 22:
  848. /*! Production:: dimension : VHS */
  849. this.$ = { type: 'VhValue', value: parseFloat(yyvstack[yysp]), unit: 'vh' };
  850. break;
  851. case 23:
  852. /*! Production:: dimension : VWS */
  853. this.$ = { type: 'VwValue', value: parseFloat(yyvstack[yysp]), unit: 'vw' };
  854. break;
  855. case 24:
  856. /*! Production:: dimension : VMINS */
  857. this.$ = { type: 'VminValue', value: parseFloat(yyvstack[yysp]), unit: 'vmin' };
  858. break;
  859. case 25:
  860. /*! Production:: dimension : VMAXS */
  861. this.$ = { type: 'VmaxValue', value: parseFloat(yyvstack[yysp]), unit: 'vmax' };
  862. break;
  863. case 26:
  864. /*! Production:: dimension : PERCENTAGE */
  865. this.$ = { type: 'PercentageValue', value: parseFloat(yyvstack[yysp]), unit: '%' };
  866. break;
  867. case 27:
  868. /*! Production:: dimension : ADD dimension */
  869. var prev = yyvstack[yysp]; this.$ = prev;
  870. break;
  871. case 28:
  872. /*! Production:: dimension : SUB dimension */
  873. var prev = yyvstack[yysp]; prev.value *= -1; this.$ = prev;
  874. break;
  875. case 29:
  876. /*! Production:: number : NUMBER */
  877. case 30:
  878. /*! Production:: number : ADD NUMBER */
  879. this.$ = { type: 'Number', value: parseFloat(yyvstack[yysp]) };
  880. break;
  881. case 31:
  882. /*! Production:: number : SUB NUMBER */
  883. this.$ = { type: 'Number', value: parseFloat(yyvstack[yysp]) * -1 };
  884. break;
  885. }
  886. },
  887. table: bt({
  888. len: u([
  889. 26,
  890. 1,
  891. 5,
  892. 1,
  893. 25,
  894. s,
  895. [0, 19],
  896. 19,
  897. 19,
  898. 0,
  899. 0,
  900. s,
  901. [25, 5],
  902. 5,
  903. 0,
  904. 0,
  905. 18,
  906. 18,
  907. 0,
  908. 0,
  909. 6,
  910. 6,
  911. 0,
  912. 0,
  913. c,
  914. [11, 3]
  915. ]),
  916. symbol: u([
  917. 3,
  918. 4,
  919. 6,
  920. 7,
  921. s,
  922. [10, 22, 1],
  923. 1,
  924. 1,
  925. s,
  926. [6, 4, 1],
  927. 4,
  928. c,
  929. [33, 21],
  930. c,
  931. [32, 4],
  932. 6,
  933. 7,
  934. c,
  935. [22, 16],
  936. 30,
  937. c,
  938. [19, 19],
  939. c,
  940. [63, 25],
  941. c,
  942. [25, 100],
  943. s,
  944. [5, 5, 1],
  945. c,
  946. [149, 17],
  947. c,
  948. [167, 18],
  949. 30,
  950. 1,
  951. c,
  952. [42, 5],
  953. c,
  954. [6, 6],
  955. c,
  956. [5, 5]
  957. ]),
  958. type: u([
  959. s,
  960. [2, 21],
  961. s,
  962. [0, 5],
  963. 1,
  964. s,
  965. [2, 27],
  966. s,
  967. [0, 4],
  968. c,
  969. [22, 19],
  970. c,
  971. [19, 37],
  972. c,
  973. [63, 25],
  974. c,
  975. [25, 103],
  976. c,
  977. [148, 19],
  978. c,
  979. [18, 18]
  980. ]),
  981. state: u([
  982. 1,
  983. 2,
  984. 5,
  985. 6,
  986. 7,
  987. 33,
  988. c,
  989. [4, 3],
  990. 34,
  991. 38,
  992. 40,
  993. c,
  994. [6, 3],
  995. 41,
  996. c,
  997. [4, 3],
  998. 42,
  999. c,
  1000. [4, 3],
  1001. 43,
  1002. c,
  1003. [4, 3],
  1004. 44,
  1005. c,
  1006. [22, 5]
  1007. ]),
  1008. mode: u([
  1009. s,
  1010. [1, 228],
  1011. s,
  1012. [2, 4],
  1013. c,
  1014. [6, 8],
  1015. s,
  1016. [1, 5]
  1017. ]),
  1018. goto: u([
  1019. 3,
  1020. 4,
  1021. 24,
  1022. 25,
  1023. s,
  1024. [8, 16, 1],
  1025. s,
  1026. [26, 7, 1],
  1027. c,
  1028. [27, 21],
  1029. 36,
  1030. 37,
  1031. c,
  1032. [18, 15],
  1033. 35,
  1034. c,
  1035. [18, 17],
  1036. 39,
  1037. c,
  1038. [57, 21],
  1039. c,
  1040. [21, 84],
  1041. 45,
  1042. c,
  1043. [168, 4],
  1044. c,
  1045. [128, 17],
  1046. c,
  1047. [17, 17],
  1048. s,
  1049. [3, 4],
  1050. 30,
  1051. 31,
  1052. s,
  1053. [4, 4],
  1054. 30,
  1055. 31,
  1056. 46,
  1057. c,
  1058. [51, 4]
  1059. ])
  1060. }),
  1061. defaultActions: bda({
  1062. idx: u([
  1063. s,
  1064. [5, 19, 1],
  1065. 26,
  1066. 27,
  1067. 34,
  1068. 35,
  1069. 38,
  1070. 39,
  1071. 42,
  1072. 43,
  1073. 45,
  1074. 46
  1075. ]),
  1076. goto: u([
  1077. s,
  1078. [8, 19, 1],
  1079. 29,
  1080. 1,
  1081. 27,
  1082. 30,
  1083. 28,
  1084. 31,
  1085. 5,
  1086. 6,
  1087. 7,
  1088. 2
  1089. ])
  1090. }),
  1091. parseError: function parseError(str, hash, ExceptionClass) {
  1092. if (hash.recoverable) {
  1093. if (typeof this.trace === 'function') {
  1094. this.trace(str);
  1095. }
  1096. hash.destroy(); // destroy... well, *almost*!
  1097. } else {
  1098. if (typeof this.trace === 'function') {
  1099. this.trace(str);
  1100. }
  1101. if (!ExceptionClass) {
  1102. ExceptionClass = this.JisonParserError;
  1103. }
  1104. throw new ExceptionClass(str, hash);
  1105. }
  1106. },
  1107. parse: function parse(input) {
  1108. var self = this;
  1109. var stack = new Array(128); // token stack: stores token which leads to state at the same index (column storage)
  1110. var sstack = new Array(128); // state stack: stores states (column storage)
  1111. var vstack = new Array(128); // semantic value stack
  1112. var table = this.table;
  1113. var sp = 0; // 'stack pointer': index into the stacks
  1114. var symbol = 0;
  1115. var TERROR = this.TERROR;
  1116. var EOF = this.EOF;
  1117. var ERROR_RECOVERY_TOKEN_DISCARD_COUNT = (this.options.errorRecoveryTokenDiscardCount | 0) || 3;
  1118. var NO_ACTION = [0, 47 /* === table.length :: ensures that anyone using this new state will fail dramatically! */];
  1119. var lexer;
  1120. if (this.__lexer__) {
  1121. lexer = this.__lexer__;
  1122. } else {
  1123. lexer = this.__lexer__ = Object.create(this.lexer);
  1124. }
  1125. var sharedState_yy = {
  1126. parseError: undefined,
  1127. quoteName: undefined,
  1128. lexer: undefined,
  1129. parser: undefined,
  1130. pre_parse: undefined,
  1131. post_parse: undefined,
  1132. pre_lex: undefined,
  1133. post_lex: undefined // WARNING: must be written this way for the code expanders to work correctly in both ES5 and ES6 modes!
  1134. };
  1135. var ASSERT;
  1136. if (typeof assert !== 'function') {
  1137. ASSERT = function JisonAssert(cond, msg) {
  1138. if (!cond) {
  1139. throw new Error('assertion failed: ' + (msg || '***'));
  1140. }
  1141. };
  1142. } else {
  1143. ASSERT = assert;
  1144. }
  1145. this.yyGetSharedState = function yyGetSharedState() {
  1146. return sharedState_yy;
  1147. };
  1148. function shallow_copy_noclobber(dst, src) {
  1149. for (var k in src) {
  1150. if (typeof dst[k] === 'undefined' && Object.prototype.hasOwnProperty.call(src, k)) {
  1151. dst[k] = src[k];
  1152. }
  1153. }
  1154. }
  1155. // copy state
  1156. shallow_copy_noclobber(sharedState_yy, this.yy);
  1157. sharedState_yy.lexer = lexer;
  1158. sharedState_yy.parser = this;
  1159. // Does the shared state override the default `parseError` that already comes with this instance?
  1160. if (typeof sharedState_yy.parseError === 'function') {
  1161. this.parseError = function parseErrorAlt(str, hash, ExceptionClass) {
  1162. if (!ExceptionClass) {
  1163. ExceptionClass = this.JisonParserError;
  1164. }
  1165. return sharedState_yy.parseError.call(this, str, hash, ExceptionClass);
  1166. };
  1167. } else {
  1168. this.parseError = this.originalParseError;
  1169. }
  1170. // Does the shared state override the default `quoteName` that already comes with this instance?
  1171. if (typeof sharedState_yy.quoteName === 'function') {
  1172. this.quoteName = function quoteNameAlt(id_str) {
  1173. return sharedState_yy.quoteName.call(this, id_str);
  1174. };
  1175. } else {
  1176. this.quoteName = this.originalQuoteName;
  1177. }
  1178. // set up the cleanup function; make it an API so that external code can re-use this one in case of
  1179. // calamities or when the `%options no-try-catch` option has been specified for the grammar, in which
  1180. // case this parse() API method doesn't come with a `finally { ... }` block any more!
  1181. //
  1182. // NOTE: as this API uses parse() as a closure, it MUST be set again on every parse() invocation,
  1183. // or else your `sharedState`, etc. references will be *wrong*!
  1184. this.cleanupAfterParse = function parser_cleanupAfterParse(resultValue, invoke_post_methods, do_not_nuke_errorinfos) {
  1185. var rv;
  1186. if (invoke_post_methods) {
  1187. var hash;
  1188. if (sharedState_yy.post_parse || this.post_parse) {
  1189. // create an error hash info instance: we re-use this API in a **non-error situation**
  1190. // as this one delivers all parser internals ready for access by userland code.
  1191. hash = this.constructParseErrorInfo(null /* no error! */, null /* no exception! */, null, false);
  1192. }
  1193. if (sharedState_yy.post_parse) {
  1194. rv = sharedState_yy.post_parse.call(this, sharedState_yy, resultValue, hash);
  1195. if (typeof rv !== 'undefined') resultValue = rv;
  1196. }
  1197. if (this.post_parse) {
  1198. rv = this.post_parse.call(this, sharedState_yy, resultValue, hash);
  1199. if (typeof rv !== 'undefined') resultValue = rv;
  1200. }
  1201. // cleanup:
  1202. if (hash && hash.destroy) {
  1203. hash.destroy();
  1204. }
  1205. }
  1206. if (this.__reentrant_call_depth > 1) return resultValue; // do not (yet) kill the sharedState when this is a reentrant run.
  1207. // clean up the lingering lexer structures as well:
  1208. if (lexer.cleanupAfterLex) {
  1209. lexer.cleanupAfterLex(do_not_nuke_errorinfos);
  1210. }
  1211. // prevent lingering circular references from causing memory leaks:
  1212. if (sharedState_yy) {
  1213. sharedState_yy.lexer = undefined;
  1214. sharedState_yy.parser = undefined;
  1215. if (lexer.yy === sharedState_yy) {
  1216. lexer.yy = undefined;
  1217. }
  1218. }
  1219. sharedState_yy = undefined;
  1220. this.parseError = this.originalParseError;
  1221. this.quoteName = this.originalQuoteName;
  1222. // nuke the vstack[] array at least as that one will still reference obsoleted user values.
  1223. // To be safe, we nuke the other internal stack columns as well...
  1224. stack.length = 0; // fastest way to nuke an array without overly bothering the GC
  1225. sstack.length = 0;
  1226. vstack.length = 0;
  1227. sp = 0;
  1228. // nuke the error hash info instances created during this run.
  1229. // Userland code must COPY any data/references
  1230. // in the error hash instance(s) it is more permanently interested in.
  1231. if (!do_not_nuke_errorinfos) {
  1232. for (var i = this.__error_infos.length - 1; i >= 0; i--) {
  1233. var el = this.__error_infos[i];
  1234. if (el && typeof el.destroy === 'function') {
  1235. el.destroy();
  1236. }
  1237. }
  1238. this.__error_infos.length = 0;
  1239. }
  1240. return resultValue;
  1241. };
  1242. // NOTE: as this API uses parse() as a closure, it MUST be set again on every parse() invocation,
  1243. // or else your `lexer`, `sharedState`, etc. references will be *wrong*!
  1244. this.constructParseErrorInfo = function parser_constructParseErrorInfo(msg, ex, expected, recoverable) {
  1245. var pei = {
  1246. errStr: msg,
  1247. exception: ex,
  1248. text: lexer.match,
  1249. value: lexer.yytext,
  1250. token: this.describeSymbol(symbol) || symbol,
  1251. token_id: symbol,
  1252. line: lexer.yylineno,
  1253. expected: expected,
  1254. recoverable: recoverable,
  1255. state: state,
  1256. action: action,
  1257. new_state: newState,
  1258. symbol_stack: stack,
  1259. state_stack: sstack,
  1260. value_stack: vstack,
  1261. stack_pointer: sp,
  1262. yy: sharedState_yy,
  1263. lexer: lexer,
  1264. parser: this,
  1265. // and make sure the error info doesn't stay due to potential
  1266. // ref cycle via userland code manipulations.
  1267. // These would otherwise all be memory leak opportunities!
  1268. //
  1269. // Note that only array and object references are nuked as those
  1270. // constitute the set of elements which can produce a cyclic ref.
  1271. // The rest of the members is kept intact as they are harmless.
  1272. destroy: function destructParseErrorInfo() {
  1273. // remove cyclic references added to error info:
  1274. // info.yy = null;
  1275. // info.lexer = null;
  1276. // info.value = null;
  1277. // info.value_stack = null;
  1278. // ...
  1279. var rec = !!this.recoverable;
  1280. for (var key in this) {
  1281. if (this.hasOwnProperty(key) && typeof key === 'object') {
  1282. this[key] = undefined;
  1283. }
  1284. }
  1285. this.recoverable = rec;
  1286. }
  1287. };
  1288. // track this instance so we can `destroy()` it once we deem it superfluous and ready for garbage collection!
  1289. this.__error_infos.push(pei);
  1290. return pei;
  1291. };
  1292. function getNonTerminalFromCode(symbol) {
  1293. var tokenName = self.getSymbolName(symbol);
  1294. if (!tokenName) {
  1295. tokenName = symbol;
  1296. }
  1297. return tokenName;
  1298. }
  1299. function stdLex() {
  1300. var token = lexer.lex();
  1301. // if token isn't its numeric value, convert
  1302. if (typeof token !== 'number') {
  1303. token = self.symbols_[token] || token;
  1304. }
  1305. return token || EOF;
  1306. }
  1307. function fastLex() {
  1308. var token = lexer.fastLex();
  1309. // if token isn't its numeric value, convert
  1310. if (typeof token !== 'number') {
  1311. token = self.symbols_[token] || token;
  1312. }
  1313. return token || EOF;
  1314. }
  1315. var lex = stdLex;
  1316. var state, action, r, t;
  1317. var yyval = {
  1318. $: true,
  1319. _$: undefined,
  1320. yy: sharedState_yy
  1321. };
  1322. var p;
  1323. var yyrulelen;
  1324. var this_production;
  1325. var newState;
  1326. var retval = false;
  1327. try {
  1328. this.__reentrant_call_depth++;
  1329. lexer.setInput(input, sharedState_yy);
  1330. // NOTE: we *assume* no lexer pre/post handlers are set up *after*
  1331. // this initial `setInput()` call: hence we can now check and decide
  1332. // whether we'll go with the standard, slower, lex() API or the
  1333. // `fast_lex()` one:
  1334. if (typeof lexer.canIUse === 'function') {
  1335. var lexerInfo = lexer.canIUse();
  1336. if (lexerInfo.fastLex && typeof fastLex === 'function') {
  1337. lex = fastLex;
  1338. }
  1339. }
  1340. vstack[sp] = null;
  1341. sstack[sp] = 0;
  1342. stack[sp] = 0;
  1343. ++sp;
  1344. if (this.pre_parse) {
  1345. this.pre_parse.call(this, sharedState_yy);
  1346. }
  1347. if (sharedState_yy.pre_parse) {
  1348. sharedState_yy.pre_parse.call(this, sharedState_yy);
  1349. }
  1350. newState = sstack[sp - 1];
  1351. for (;;) {
  1352. // retrieve state number from top of stack
  1353. state = newState; // sstack[sp - 1];
  1354. // use default actions if available
  1355. if (this.defaultActions[state]) {
  1356. action = 2;
  1357. newState = this.defaultActions[state];
  1358. } else {
  1359. // The single `==` condition below covers both these `===` comparisons in a single
  1360. // operation:
  1361. //
  1362. // if (symbol === null || typeof symbol === 'undefined') ...
  1363. if (!symbol) {
  1364. symbol = lex();
  1365. }
  1366. // read action for current state and first input
  1367. t = (table[state] && table[state][symbol]) || NO_ACTION;
  1368. newState = t[1];
  1369. action = t[0];
  1370. // handle parse error
  1371. if (!action) {
  1372. var errStr;
  1373. var errSymbolDescr = (this.describeSymbol(symbol) || symbol);
  1374. var expected = this.collect_expected_token_set(state);
  1375. // Report error
  1376. if (typeof lexer.yylineno === 'number') {
  1377. errStr = 'Parse error on line ' + (lexer.yylineno + 1) + ': ';
  1378. } else {
  1379. errStr = 'Parse error: ';
  1380. }
  1381. if (typeof lexer.showPosition === 'function') {
  1382. errStr += '\n' + lexer.showPosition(79 - 10, 10) + '\n';
  1383. }
  1384. if (expected.length) {
  1385. errStr += 'Expecting ' + expected.join(', ') + ', got unexpected ' + errSymbolDescr;
  1386. } else {
  1387. errStr += 'Unexpected ' + errSymbolDescr;
  1388. }
  1389. // we cannot recover from the error!
  1390. p = this.constructParseErrorInfo(errStr, null, expected, false);
  1391. r = this.parseError(p.errStr, p, this.JisonParserError);
  1392. if (typeof r !== 'undefined') {
  1393. retval = r;
  1394. }
  1395. break;
  1396. }
  1397. }
  1398. switch (action) {
  1399. // catch misc. parse failures:
  1400. default:
  1401. // this shouldn't happen, unless resolve defaults are off
  1402. if (action instanceof Array) {
  1403. p = this.constructParseErrorInfo('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol, null, null, false);
  1404. r = this.parseError(p.errStr, p, this.JisonParserError);
  1405. if (typeof r !== 'undefined') {
  1406. retval = r;
  1407. }
  1408. break;
  1409. }
  1410. // Another case of better safe than sorry: in case state transitions come out of another error recovery process
  1411. // or a buggy LUT (LookUp Table):
  1412. p = this.constructParseErrorInfo('Parsing halted. No viable error recovery approach available due to internal system failure.', null, null, false);
  1413. r = this.parseError(p.errStr, p, this.JisonParserError);
  1414. if (typeof r !== 'undefined') {
  1415. retval = r;
  1416. }
  1417. break;
  1418. // shift:
  1419. case 1:
  1420. stack[sp] = symbol;
  1421. vstack[sp] = lexer.yytext;
  1422. sstack[sp] = newState; // push state
  1423. ++sp;
  1424. symbol = 0;
  1425. // Pick up the lexer details for the current symbol as that one is not 'look-ahead' any more:
  1426. continue;
  1427. // reduce:
  1428. case 2:
  1429. this_production = this.productions_[newState - 1]; // `this.productions_[]` is zero-based indexed while states start from 1 upwards...
  1430. yyrulelen = this_production[1];
  1431. r = this.performAction.call(yyval, newState, sp - 1, vstack);
  1432. if (typeof r !== 'undefined') {
  1433. retval = r;
  1434. break;
  1435. }
  1436. // pop off stack
  1437. sp -= yyrulelen;
  1438. // don't overwrite the `symbol` variable: use a local var to speed things up:
  1439. var ntsymbol = this_production[0]; // push nonterminal (reduce)
  1440. stack[sp] = ntsymbol;
  1441. vstack[sp] = yyval.$;
  1442. // goto new state = table[STATE][NONTERMINAL]
  1443. newState = table[sstack[sp - 1]][ntsymbol];
  1444. sstack[sp] = newState;
  1445. ++sp;
  1446. continue;
  1447. // accept:
  1448. case 3:
  1449. if (sp !== -2) {
  1450. retval = true;
  1451. // Return the `$accept` rule's `$$` result, if available.
  1452. //
  1453. // Also note that JISON always adds this top-most `$accept` rule (with implicit,
  1454. // default, action):
  1455. //
  1456. // $accept: <startSymbol> $end
  1457. // %{ $$ = $1; @$ = @1; %}
  1458. //
  1459. // which, combined with the parse kernel's `$accept` state behaviour coded below,
  1460. // will produce the `$$` value output of the <startSymbol> rule as the parse result,
  1461. // IFF that result is *not* `undefined`. (See also the parser kernel code.)
  1462. //
  1463. // In code:
  1464. //
  1465. // %{
  1466. // @$ = @1; // if location tracking support is included
  1467. // if (typeof $1 !== 'undefined')
  1468. // return $1;
  1469. // else
  1470. // return true; // the default parse result if the rule actions don't produce anything
  1471. // %}
  1472. sp--;
  1473. if (typeof vstack[sp] !== 'undefined') {
  1474. retval = vstack[sp];
  1475. }
  1476. }
  1477. break;
  1478. }
  1479. // break out of loop: we accept or fail with error
  1480. break;
  1481. }
  1482. } catch (ex) {
  1483. // report exceptions through the parseError callback too, but keep the exception intact
  1484. // if it is a known parser or lexer error which has been thrown by parseError() already:
  1485. if (ex instanceof this.JisonParserError) {
  1486. throw ex;
  1487. }
  1488. else if (lexer && typeof lexer.JisonLexerError === 'function' && ex instanceof lexer.JisonLexerError) {
  1489. throw ex;
  1490. }
  1491. p = this.constructParseErrorInfo('Parsing aborted due to exception.', ex, null, false);
  1492. retval = false;
  1493. r = this.parseError(p.errStr, p, this.JisonParserError);
  1494. if (typeof r !== 'undefined') {
  1495. retval = r;
  1496. }
  1497. } finally {
  1498. retval = this.cleanupAfterParse(retval, true, true);
  1499. this.__reentrant_call_depth--;
  1500. } // /finally
  1501. return retval;
  1502. }
  1503. };
  1504. parser.originalParseError = parser.parseError;
  1505. parser.originalQuoteName = parser.quoteName;
  1506. /* lexer generated by jison-lex 0.6.1-215 */
  1507. /*
  1508. * Returns a Lexer object of the following structure:
  1509. *
  1510. * Lexer: {
  1511. * yy: {} The so-called "shared state" or rather the *source* of it;
  1512. * the real "shared state" `yy` passed around to
  1513. * the rule actions, etc. is a direct reference!
  1514. *
  1515. * This "shared context" object was passed to the lexer by way of
  1516. * the `lexer.setInput(str, yy)` API before you may use it.
  1517. *
  1518. * This "shared context" object is passed to the lexer action code in `performAction()`
  1519. * so userland code in the lexer actions may communicate with the outside world
  1520. * and/or other lexer rules' actions in more or less complex ways.
  1521. *
  1522. * }
  1523. *
  1524. * Lexer.prototype: {
  1525. * EOF: 1,
  1526. * ERROR: 2,
  1527. *
  1528. * yy: The overall "shared context" object reference.
  1529. *
  1530. * JisonLexerError: function(msg, hash),
  1531. *
  1532. * performAction: function lexer__performAction(yy, yyrulenumber, YY_START),
  1533. *
  1534. * The function parameters and `this` have the following value/meaning:
  1535. * - `this` : reference to the `lexer` instance.
  1536. * `yy_` is an alias for `this` lexer instance reference used internally.
  1537. *
  1538. * - `yy` : a reference to the `yy` "shared state" object which was passed to the lexer
  1539. * by way of the `lexer.setInput(str, yy)` API before.
  1540. *
  1541. * Note:
  1542. * The extra arguments you specified in the `%parse-param` statement in your
  1543. * **parser** grammar definition file are passed to the lexer via this object
  1544. * reference as member variables.
  1545. *
  1546. * - `yyrulenumber` : index of the matched lexer rule (regex), used internally.
  1547. *
  1548. * - `YY_START`: the current lexer "start condition" state.
  1549. *
  1550. * parseError: function(str, hash, ExceptionClass),
  1551. *
  1552. * constructLexErrorInfo: function(error_message, is_recoverable),
  1553. * Helper function.
  1554. * Produces a new errorInfo 'hash object' which can be passed into `parseError()`.
  1555. * See it's use in this lexer kernel in many places; example usage:
  1556. *
  1557. * var infoObj = lexer.constructParseErrorInfo('fail!', true);
  1558. * var retVal = lexer.parseError(infoObj.errStr, infoObj, lexer.JisonLexerError);
  1559. *
  1560. * options: { ... lexer %options ... },
  1561. *
  1562. * lex: function(),
  1563. * Produce one token of lexed input, which was passed in earlier via the `lexer.setInput()` API.
  1564. * You MAY use the additional `args...` parameters as per `%parse-param` spec of the **lexer** grammar:
  1565. * these extra `args...` are added verbatim to the `yy` object reference as member variables.
  1566. *
  1567. * WARNING:
  1568. * Lexer's additional `args...` parameters (via lexer's `%parse-param`) MAY conflict with
  1569. * any attributes already added to `yy` by the **parser** or the jison run-time;
  1570. * when such a collision is detected an exception is thrown to prevent the generated run-time
  1571. * from silently accepting this confusing and potentially hazardous situation!
  1572. *
  1573. * cleanupAfterLex: function(do_not_nuke_errorinfos),
  1574. * Helper function.
  1575. *
  1576. * This helper API is invoked when the **parse process** has completed: it is the responsibility
  1577. * of the **parser** (or the calling userland code) to invoke this method once cleanup is desired.
  1578. *
  1579. * This helper may be invoked by user code to ensure the internal lexer gets properly garbage collected.
  1580. *
  1581. * setInput: function(input, [yy]),
  1582. *
  1583. *
  1584. * input: function(),
  1585. *
  1586. *
  1587. * unput: function(str),
  1588. *
  1589. *
  1590. * more: function(),
  1591. *
  1592. *
  1593. * reject: function(),
  1594. *
  1595. *
  1596. * less: function(n),
  1597. *
  1598. *
  1599. * pastInput: function(n),
  1600. *
  1601. *
  1602. * upcomingInput: function(n),
  1603. *
  1604. *
  1605. * showPosition: function(),
  1606. *
  1607. *
  1608. * test_match: function(regex_match_array, rule_index),
  1609. *
  1610. *
  1611. * next: function(),
  1612. *
  1613. *
  1614. * begin: function(condition),
  1615. *
  1616. *
  1617. * pushState: function(condition),
  1618. *
  1619. *
  1620. * popState: function(),
  1621. *
  1622. *
  1623. * topState: function(),
  1624. *
  1625. *
  1626. * _currentRules: function(),
  1627. *
  1628. *
  1629. * stateStackSize: function(),
  1630. *
  1631. *
  1632. * performAction: function(yy, yy_, yyrulenumber, YY_START),
  1633. *
  1634. *
  1635. * rules: [...],
  1636. *
  1637. *
  1638. * conditions: {associative list: name ==> set},
  1639. * }
  1640. *
  1641. *
  1642. * token location info (`yylloc`): {
  1643. * first_line: n,
  1644. * last_line: n,
  1645. * first_column: n,
  1646. * last_column: n,
  1647. * range: [start_number, end_number]
  1648. * (where the numbers are indexes into the input string, zero-based)
  1649. * }
  1650. *
  1651. * ---
  1652. *
  1653. * The `parseError` function receives a 'hash' object with these members for lexer errors:
  1654. *
  1655. * {
  1656. * text: (matched text)
  1657. * token: (the produced terminal token, if any)
  1658. * token_id: (the produced terminal token numeric ID, if any)
  1659. * line: (yylineno)
  1660. * loc: (yylloc)
  1661. * recoverable: (boolean: TRUE when the parser MAY have an error recovery rule
  1662. * available for this particular error)
  1663. * yy: (object: the current parser internal "shared state" `yy`
  1664. * as is also available in the rule actions; this can be used,
  1665. * for instance, for advanced error analysis and reporting)
  1666. * lexer: (reference to the current lexer instance used by the parser)
  1667. * }
  1668. *
  1669. * while `this` will reference the current lexer instance.
  1670. *
  1671. * When `parseError` is invoked by the lexer, the default implementation will
  1672. * attempt to invoke `yy.parser.parseError()`; when this callback is not provided
  1673. * it will try to invoke `yy.parseError()` instead. When that callback is also not
  1674. * provided, a `JisonLexerError` exception will be thrown containing the error
  1675. * message and `hash`, as constructed by the `constructLexErrorInfo()` API.
  1676. *
  1677. * Note that the lexer's `JisonLexerError` error class is passed via the
  1678. * `ExceptionClass` argument, which is invoked to construct the exception
  1679. * instance to be thrown, so technically `parseError` will throw the object
  1680. * produced by the `new ExceptionClass(str, hash)` JavaScript expression.
  1681. *
  1682. * ---
  1683. *
  1684. * You can specify lexer options by setting / modifying the `.options` object of your Lexer instance.
  1685. * These options are available:
  1686. *
  1687. * (Options are permanent.)
  1688. *
  1689. * yy: {
  1690. * parseError: function(str, hash, ExceptionClass)
  1691. * optional: overrides the default `parseError` function.
  1692. * }
  1693. *
  1694. * lexer.options: {
  1695. * pre_lex: function()
  1696. * optional: is invoked before the lexer is invoked to produce another token.
  1697. * `this` refers to the Lexer object.
  1698. * post_lex: function(token) { return token; }
  1699. * optional: is invoked when the lexer has produced a token `token`;
  1700. * this function can override the returned token value by returning another.
  1701. * When it does not return any (truthy) value, the lexer will return
  1702. * the original `token`.
  1703. * `this` refers to the Lexer object.
  1704. *
  1705. * WARNING: the next set of options are not meant to be changed. They echo the abilities of
  1706. * the lexer as per when it was compiled!
  1707. *
  1708. * ranges: boolean
  1709. * optional: `true` ==> token location info will include a .range[] member.
  1710. * flex: boolean
  1711. * optional: `true` ==> flex-like lexing behaviour where the rules are tested
  1712. * exhaustively to find the longest match.
  1713. * backtrack_lexer: boolean
  1714. * optional: `true` ==> lexer regexes are tested in order and for invoked;
  1715. * the lexer terminates the scan when a token is returned by the action code.
  1716. * xregexp: boolean
  1717. * optional: `true` ==> lexer rule regexes are "extended regex format" requiring the
  1718. * `XRegExp` library. When this %option has not been specified at compile time, all lexer
  1719. * rule regexes have been written as standard JavaScript RegExp expressions.
  1720. * }
  1721. */
  1722. var lexer = function() {
  1723. /**
  1724. * See also:
  1725. * http://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript/#35881508
  1726. * but we keep the prototype.constructor and prototype.name assignment lines too for compatibility
  1727. * with userland code which might access the derived class in a 'classic' way.
  1728. *
  1729. * @public
  1730. * @constructor
  1731. * @nocollapse
  1732. */
  1733. function JisonLexerError(msg, hash) {
  1734. Object.defineProperty(this, 'name', {
  1735. enumerable: false,
  1736. writable: false,
  1737. value: 'JisonLexerError'
  1738. });
  1739. if (msg == null)
  1740. msg = '???';
  1741. Object.defineProperty(this, 'message', {
  1742. enumerable: false,
  1743. writable: true,
  1744. value: msg
  1745. });
  1746. this.hash = hash;
  1747. var stacktrace;
  1748. if (hash && hash.exception instanceof Error) {
  1749. var ex2 = hash.exception;
  1750. this.message = ex2.message || msg;
  1751. stacktrace = ex2.stack;
  1752. }
  1753. if (!stacktrace) {
  1754. if (Error.hasOwnProperty('captureStackTrace')) {
  1755. // V8
  1756. Error.captureStackTrace(this, this.constructor);
  1757. } else {
  1758. stacktrace = new Error(msg).stack;
  1759. }
  1760. }
  1761. if (stacktrace) {
  1762. Object.defineProperty(this, 'stack', {
  1763. enumerable: false,
  1764. writable: false,
  1765. value: stacktrace
  1766. });
  1767. }
  1768. }
  1769. if (typeof Object.setPrototypeOf === 'function') {
  1770. Object.setPrototypeOf(JisonLexerError.prototype, Error.prototype);
  1771. } else {
  1772. JisonLexerError.prototype = Object.create(Error.prototype);
  1773. }
  1774. JisonLexerError.prototype.constructor = JisonLexerError;
  1775. JisonLexerError.prototype.name = 'JisonLexerError';
  1776. var lexer = {
  1777. // Code Generator Information Report
  1778. // ---------------------------------
  1779. //
  1780. // Options:
  1781. //
  1782. // backtracking: .................... false
  1783. // location.ranges: ................. false
  1784. // location line+column tracking: ... true
  1785. //
  1786. //
  1787. // Forwarded Parser Analysis flags:
  1788. //
  1789. // uses yyleng: ..................... false
  1790. // uses yylineno: ................... false
  1791. // uses yytext: ..................... false
  1792. // uses yylloc: ..................... false
  1793. // uses lexer values: ............... true / true
  1794. // location tracking: ............... false
  1795. // location assignment: ............. false
  1796. //
  1797. //
  1798. // Lexer Analysis flags:
  1799. //
  1800. // uses yyleng: ..................... ???
  1801. // uses yylineno: ................... ???
  1802. // uses yytext: ..................... ???
  1803. // uses yylloc: ..................... ???
  1804. // uses ParseError API: ............. ???
  1805. // uses yyerror: .................... ???
  1806. // uses location tracking & editing: ???
  1807. // uses more() API: ................. ???
  1808. // uses unput() API: ................ ???
  1809. // uses reject() API: ............... ???
  1810. // uses less() API: ................. ???
  1811. // uses display APIs pastInput(), upcomingInput(), showPosition():
  1812. // ............................. ???
  1813. // uses describeYYLLOC() API: ....... ???
  1814. //
  1815. // --------- END OF REPORT -----------
  1816. EOF: 1,
  1817. ERROR: 2,
  1818. // JisonLexerError: JisonLexerError, /// <-- injected by the code generator
  1819. // options: {}, /// <-- injected by the code generator
  1820. // yy: ..., /// <-- injected by setInput()
  1821. __currentRuleSet__: null, /// INTERNAL USE ONLY: internal rule set cache for the current lexer state
  1822. __error_infos: [], /// INTERNAL USE ONLY: the set of lexErrorInfo objects created since the last cleanup
  1823. __decompressed: false, /// INTERNAL USE ONLY: mark whether the lexer instance has been 'unfolded' completely and is now ready for use
  1824. done: false, /// INTERNAL USE ONLY
  1825. _backtrack: false, /// INTERNAL USE ONLY
  1826. _input: '', /// INTERNAL USE ONLY
  1827. _more: false, /// INTERNAL USE ONLY
  1828. _signaled_error_token: false, /// INTERNAL USE ONLY
  1829. conditionStack: [], /// INTERNAL USE ONLY; managed via `pushState()`, `popState()`, `topState()` and `stateStackSize()`
  1830. 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!
  1831. matched: '', /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: tracks entire input which has been matched so far
  1832. matches: false, /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: tracks RE match result for last (successful) match attempt
  1833. 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.
  1834. 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
  1835. yyleng: 0, /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: length of matched input for the token under construction (`yytext`)
  1836. yylineno: 0, /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: 'line number' at which the token under construction is located
  1837. yylloc: null, /// READ-ONLY EXTERNAL ACCESS - ADVANCED USE ONLY: tracks location info (lines + columns) for the token under construction
  1838. /**
  1839. * INTERNAL USE: construct a suitable error info hash object instance for `parseError`.
  1840. *
  1841. * @public
  1842. * @this {RegExpLexer}
  1843. */
  1844. constructLexErrorInfo: function lexer_constructLexErrorInfo(msg, recoverable, show_input_position) {
  1845. msg = '' + msg;
  1846. // heuristic to determine if the error message already contains a (partial) source code dump
  1847. // as produced by either `showPosition()` or `prettyPrintRange()`:
  1848. if (show_input_position == undefined) {
  1849. show_input_position = !(msg.indexOf('\n') > 0 && msg.indexOf('^') > 0);
  1850. }
  1851. if (this.yylloc && show_input_position) {
  1852. if (typeof this.prettyPrintRange === 'function') {
  1853. var pretty_src = this.prettyPrintRange(this.yylloc);
  1854. if (!/\n\s*$/.test(msg)) {
  1855. msg += '\n';
  1856. }
  1857. msg += '\n Erroneous area:\n' + this.prettyPrintRange(this.yylloc);
  1858. } else if (typeof this.showPosition === 'function') {
  1859. var pos_str = this.showPosition();
  1860. if (pos_str) {
  1861. if (msg.length && msg[msg.length - 1] !== '\n' && pos_str[0] !== '\n') {
  1862. msg += '\n' + pos_str;
  1863. } else {
  1864. msg += pos_str;
  1865. }
  1866. }
  1867. }
  1868. }
  1869. /** @constructor */
  1870. var pei = {
  1871. errStr: msg,
  1872. recoverable: !!recoverable,
  1873. 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'...
  1874. token: null,
  1875. line: this.yylineno,
  1876. loc: this.yylloc,
  1877. yy: this.yy,
  1878. lexer: this,
  1879. /**
  1880. * and make sure the error info doesn't stay due to potential
  1881. * ref cycle via userland code manipulations.
  1882. * These would otherwise all be memory leak opportunities!
  1883. *
  1884. * Note that only array and object references are nuked as those
  1885. * constitute the set of elements which can produce a cyclic ref.
  1886. * The rest of the members is kept intact as they are harmless.
  1887. *
  1888. * @public
  1889. * @this {LexErrorInfo}
  1890. */
  1891. destroy: function destructLexErrorInfo() {
  1892. // remove cyclic references added to error info:
  1893. // info.yy = null;
  1894. // info.lexer = null;
  1895. // ...
  1896. var rec = !!this.recoverable;
  1897. for (var key in this) {
  1898. if (this.hasOwnProperty(key) && typeof key === 'object') {
  1899. this[key] = undefined;
  1900. }
  1901. }
  1902. this.recoverable = rec;
  1903. }
  1904. };
  1905. // track this instance so we can `destroy()` it once we deem it superfluous and ready for garbage collection!
  1906. this.__error_infos.push(pei);
  1907. return pei;
  1908. },
  1909. /**
  1910. * handler which is invoked when a lexer error occurs.
  1911. *
  1912. * @public
  1913. * @this {RegExpLexer}
  1914. */
  1915. parseError: function lexer_parseError(str, hash, ExceptionClass) {
  1916. if (!ExceptionClass) {
  1917. ExceptionClass = this.JisonLexerError;
  1918. }
  1919. if (this.yy) {
  1920. if (this.yy.parser && typeof this.yy.parser.parseError === 'function') {
  1921. return this.yy.parser.parseError.call(this, str, hash, ExceptionClass) || this.ERROR;
  1922. } else if (typeof this.yy.parseError === 'function') {
  1923. return this.yy.parseError.call(this, str, hash, ExceptionClass) || this.ERROR;
  1924. }
  1925. }
  1926. throw new ExceptionClass(str, hash);
  1927. },
  1928. /**
  1929. * method which implements `yyerror(str, ...args)` functionality for use inside lexer actions.
  1930. *
  1931. * @public
  1932. * @this {RegExpLexer}
  1933. */
  1934. yyerror: function yyError(str /*, ...args */) {
  1935. var lineno_msg = '';
  1936. if (this.yylloc) {
  1937. lineno_msg = ' on line ' + (this.yylineno + 1);
  1938. }
  1939. var p = this.constructLexErrorInfo(
  1940. 'Lexical error' + lineno_msg + ': ' + str,
  1941. this.options.lexerErrorsAreRecoverable
  1942. );
  1943. // Add any extra args to the hash under the name `extra_error_attributes`:
  1944. var args = Array.prototype.slice.call(arguments, 1);
  1945. if (args.length) {
  1946. p.extra_error_attributes = args;
  1947. }
  1948. return this.parseError(p.errStr, p, this.JisonLexerError) || this.ERROR;
  1949. },
  1950. /**
  1951. * final cleanup function for when we have completed lexing the input;
  1952. * make it an API so that external code can use this one once userland
  1953. * code has decided it's time to destroy any lingering lexer error
  1954. * hash object instances and the like: this function helps to clean
  1955. * up these constructs, which *may* carry cyclic references which would
  1956. * otherwise prevent the instances from being properly and timely
  1957. * garbage-collected, i.e. this function helps prevent memory leaks!
  1958. *
  1959. * @public
  1960. * @this {RegExpLexer}
  1961. */
  1962. cleanupAfterLex: function lexer_cleanupAfterLex(do_not_nuke_errorinfos) {
  1963. // prevent lingering circular references from causing memory leaks:
  1964. this.setInput('', {});
  1965. // nuke the error hash info instances created during this run.
  1966. // Userland code must COPY any data/references
  1967. // in the error hash instance(s) it is more permanently interested in.
  1968. if (!do_not_nuke_errorinfos) {
  1969. for (var i = this.__error_infos.length - 1; i >= 0; i--) {
  1970. var el = this.__error_infos[i];
  1971. if (el && typeof el.destroy === 'function') {
  1972. el.destroy();
  1973. }
  1974. }
  1975. this.__error_infos.length = 0;
  1976. }
  1977. return this;
  1978. },
  1979. /**
  1980. * clear the lexer token context; intended for internal use only
  1981. *
  1982. * @public
  1983. * @this {RegExpLexer}
  1984. */
  1985. clear: function lexer_clear() {
  1986. this.yytext = '';
  1987. this.yyleng = 0;
  1988. this.match = '';
  1989. // - DO NOT reset `this.matched`
  1990. this.matches = false;
  1991. this._more = false;
  1992. this._backtrack = false;
  1993. var col = (this.yylloc ? this.yylloc.last_column : 0);
  1994. this.yylloc = {
  1995. first_line: this.yylineno + 1,
  1996. first_column: col,
  1997. last_line: this.yylineno + 1,
  1998. last_column: col,
  1999. range: [this.offset, this.offset]
  2000. };
  2001. },
  2002. /**
  2003. * resets the lexer, sets new input
  2004. *
  2005. * @public
  2006. * @this {RegExpLexer}
  2007. */
  2008. setInput: function lexer_setInput(input, yy) {
  2009. this.yy = yy || this.yy || {};
  2010. // also check if we've fully initialized the lexer instance,
  2011. // including expansion work to be done to go from a loaded
  2012. // lexer to a usable lexer:
  2013. if (!this.__decompressed) {
  2014. // step 1: decompress the regex list:
  2015. var rules = this.rules;
  2016. for (var i = 0, len = rules.length; i < len; i++) {
  2017. var rule_re = rules[i];
  2018. // compression: is the RE an xref to another RE slot in the rules[] table?
  2019. if (typeof rule_re === 'number') {
  2020. rules[i] = rules[rule_re];
  2021. }
  2022. }
  2023. // step 2: unfold the conditions[] set to make these ready for use:
  2024. var conditions = this.conditions;
  2025. for (var k in conditions) {
  2026. var spec = conditions[k];
  2027. var rule_ids = spec.rules;
  2028. var len = rule_ids.length;
  2029. 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!
  2030. var rule_new_ids = new Array(len + 1);
  2031. for (var i = 0; i < len; i++) {
  2032. var idx = rule_ids[i];
  2033. var rule_re = rules[idx];
  2034. rule_regexes[i + 1] = rule_re;
  2035. rule_new_ids[i + 1] = idx;
  2036. }
  2037. spec.rules = rule_new_ids;
  2038. spec.__rule_regexes = rule_regexes;
  2039. spec.__rule_count = len;
  2040. }
  2041. this.__decompressed = true;
  2042. }
  2043. this._input = input || '';
  2044. this.clear();
  2045. this._signaled_error_token = false;
  2046. this.done = false;
  2047. this.yylineno = 0;
  2048. this.matched = '';
  2049. this.conditionStack = ['INITIAL'];
  2050. this.__currentRuleSet__ = null;
  2051. this.yylloc = {
  2052. first_line: 1,
  2053. first_column: 0,
  2054. last_line: 1,
  2055. last_column: 0,
  2056. range: [0, 0]
  2057. };
  2058. this.offset = 0;
  2059. return this;
  2060. },
  2061. /**
  2062. * edit the remaining input via user-specified callback.
  2063. * This can be used to forward-adjust the input-to-parse,
  2064. * e.g. inserting macro expansions and alike in the
  2065. * input which has yet to be lexed.
  2066. * The behaviour of this API contrasts the `unput()` et al
  2067. * APIs as those act on the *consumed* input, while this
  2068. * one allows one to manipulate the future, without impacting
  2069. * the current `yyloc` cursor location or any history.
  2070. *
  2071. * Use this API to help implement C-preprocessor-like
  2072. * `#include` statements, etc.
  2073. *
  2074. * The provided callback must be synchronous and is
  2075. * expected to return the edited input (string).
  2076. *
  2077. * The `cpsArg` argument value is passed to the callback
  2078. * as-is.
  2079. *
  2080. * `callback` interface:
  2081. * `function callback(input, cpsArg)`
  2082. *
  2083. * - `input` will carry the remaining-input-to-lex string
  2084. * from the lexer.
  2085. * - `cpsArg` is `cpsArg` passed into this API.
  2086. *
  2087. * The `this` reference for the callback will be set to
  2088. * reference this lexer instance so that userland code
  2089. * in the callback can easily and quickly access any lexer
  2090. * API.
  2091. *
  2092. * When the callback returns a non-string-type falsey value,
  2093. * we assume the callback did not edit the input and we
  2094. * will using the input as-is.
  2095. *
  2096. * When the callback returns a non-string-type value, it
  2097. * is converted to a string for lexing via the `"" + retval`
  2098. * operation. (See also why: http://2ality.com/2012/03/converting-to-string.html
  2099. * -- that way any returned object's `toValue()` and `toString()`
  2100. * methods will be invoked in a proper/desirable order.)
  2101. *
  2102. * @public
  2103. * @this {RegExpLexer}
  2104. */
  2105. editRemainingInput: function lexer_editRemainingInput(callback, cpsArg) {
  2106. var rv = callback.call(this, this._input, cpsArg);
  2107. if (typeof rv !== 'string') {
  2108. if (rv) {
  2109. this._input = '' + rv;
  2110. }
  2111. // else: keep `this._input` as is.
  2112. } else {
  2113. this._input = rv;
  2114. }
  2115. return this;
  2116. },
  2117. /**
  2118. * consumes and returns one char from the input
  2119. *
  2120. * @public
  2121. * @this {RegExpLexer}
  2122. */
  2123. input: function lexer_input() {
  2124. if (!this._input) {
  2125. //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*)
  2126. return null;
  2127. }
  2128. var ch = this._input[0];
  2129. this.yytext += ch;
  2130. this.yyleng++;
  2131. this.offset++;
  2132. this.match += ch;
  2133. this.matched += ch;
  2134. // Count the linenumber up when we hit the LF (or a stand-alone CR).
  2135. // On CRLF, the linenumber is incremented when you fetch the CR or the CRLF combo
  2136. // and we advance immediately past the LF as well, returning both together as if
  2137. // it was all a single 'character' only.
  2138. var slice_len = 1;
  2139. var lines = false;
  2140. if (ch === '\n') {
  2141. lines = true;
  2142. } else if (ch === '\r') {
  2143. lines = true;
  2144. var ch2 = this._input[1];
  2145. if (ch2 === '\n') {
  2146. slice_len++;
  2147. ch += ch2;
  2148. this.yytext += ch2;
  2149. this.yyleng++;
  2150. this.offset++;
  2151. this.match += ch2;
  2152. this.matched += ch2;
  2153. this.yylloc.range[1]++;
  2154. }
  2155. }
  2156. if (lines) {
  2157. this.yylineno++;
  2158. this.yylloc.last_line++;
  2159. this.yylloc.last_column = 0;
  2160. } else {
  2161. this.yylloc.last_column++;
  2162. }
  2163. this.yylloc.range[1]++;
  2164. this._input = this._input.slice(slice_len);
  2165. return ch;
  2166. },
  2167. /**
  2168. * unshifts one char (or an entire string) into the input
  2169. *
  2170. * @public
  2171. * @this {RegExpLexer}
  2172. */
  2173. unput: function lexer_unput(ch) {
  2174. var len = ch.length;
  2175. var lines = ch.split(/(?:\r\n?|\n)/g);
  2176. this._input = ch + this._input;
  2177. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  2178. this.yyleng = this.yytext.length;
  2179. this.offset -= len;
  2180. this.match = this.match.substr(0, this.match.length - len);
  2181. this.matched = this.matched.substr(0, this.matched.length - len);
  2182. if (lines.length > 1) {
  2183. this.yylineno -= lines.length - 1;
  2184. this.yylloc.last_line = this.yylineno + 1;
  2185. // Get last entirely matched line into the `pre_lines[]` array's
  2186. // last index slot; we don't mind when other previously
  2187. // matched lines end up in the array too.
  2188. var pre = this.match;
  2189. var pre_lines = pre.split(/(?:\r\n?|\n)/g);
  2190. if (pre_lines.length === 1) {
  2191. pre = this.matched;
  2192. pre_lines = pre.split(/(?:\r\n?|\n)/g);
  2193. }
  2194. this.yylloc.last_column = pre_lines[pre_lines.length - 1].length;
  2195. } else {
  2196. this.yylloc.last_column -= len;
  2197. }
  2198. this.yylloc.range[1] = this.yylloc.range[0] + this.yyleng;
  2199. this.done = false;
  2200. return this;
  2201. },
  2202. /**
  2203. * cache matched text and append it on next action
  2204. *
  2205. * @public
  2206. * @this {RegExpLexer}
  2207. */
  2208. more: function lexer_more() {
  2209. this._more = true;
  2210. return this;
  2211. },
  2212. /**
  2213. * signal the lexer that this rule fails to match the input, so the
  2214. * next matching rule (regex) should be tested instead.
  2215. *
  2216. * @public
  2217. * @this {RegExpLexer}
  2218. */
  2219. reject: function lexer_reject() {
  2220. if (this.options.backtrack_lexer) {
  2221. this._backtrack = true;
  2222. } else {
  2223. // when the `parseError()` call returns, we MUST ensure that the error is registered.
  2224. // We accomplish this by signaling an 'error' token to be produced for the current
  2225. // `.lex()` run.
  2226. var lineno_msg = '';
  2227. if (this.yylloc) {
  2228. lineno_msg = ' on line ' + (this.yylineno + 1);
  2229. }
  2230. var p = this.constructLexErrorInfo(
  2231. 'Lexical error' + lineno_msg + ': You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).',
  2232. false
  2233. );
  2234. this._signaled_error_token = this.parseError(p.errStr, p, this.JisonLexerError) || this.ERROR;
  2235. }
  2236. return this;
  2237. },
  2238. /**
  2239. * retain first n characters of the match
  2240. *
  2241. * @public
  2242. * @this {RegExpLexer}
  2243. */
  2244. less: function lexer_less(n) {
  2245. return this.unput(this.match.slice(n));
  2246. },
  2247. /**
  2248. * return (part of the) already matched input, i.e. for error
  2249. * messages.
  2250. *
  2251. * Limit the returned string length to `maxSize` (default: 20).
  2252. *
  2253. * Limit the returned string to the `maxLines` number of lines of
  2254. * input (default: 1).
  2255. *
  2256. * Negative limit values equal *unlimited*.
  2257. *
  2258. * @public
  2259. * @this {RegExpLexer}
  2260. */
  2261. pastInput: function lexer_pastInput(maxSize, maxLines) {
  2262. var past = this.matched.substring(0, this.matched.length - this.match.length);
  2263. if (maxSize < 0)
  2264. maxSize = past.length;
  2265. else if (!maxSize)
  2266. maxSize = 20;
  2267. if (maxLines < 0)
  2268. maxLines = past.length; // can't ever have more input lines than this!
  2269. else if (!maxLines)
  2270. maxLines = 1;
  2271. // `substr` anticipation: treat \r\n as a single character and take a little
  2272. // more than necessary so that we can still properly check against maxSize
  2273. // after we've transformed and limited the newLines in here:
  2274. past = past.substr(-maxSize * 2 - 2);
  2275. // now that we have a significantly reduced string to process, transform the newlines
  2276. // and chop them, then limit them:
  2277. var a = past.replace(/\r\n|\r/g, '\n').split('\n');
  2278. a = a.slice(-maxLines);
  2279. past = a.join('\n');
  2280. // When, after limiting to maxLines, we still have too much to return,
  2281. // do add an ellipsis prefix...
  2282. if (past.length > maxSize) {
  2283. past = '...' + past.substr(-maxSize);
  2284. }
  2285. return past;
  2286. },
  2287. /**
  2288. * return (part of the) upcoming input, i.e. for error messages.
  2289. *
  2290. * Limit the returned string length to `maxSize` (default: 20).
  2291. *
  2292. * Limit the returned string to the `maxLines` number of lines of input (default: 1).
  2293. *
  2294. * Negative limit values equal *unlimited*.
  2295. *
  2296. * > ### NOTE ###
  2297. * >
  2298. * > *"upcoming input"* is defined as the whole of the both
  2299. * > the *currently lexed* input, together with any remaining input
  2300. * > following that. *"currently lexed"* input is the input
  2301. * > already recognized by the lexer but not yet returned with
  2302. * > the lexer token. This happens when you are invoking this API
  2303. * > from inside any lexer rule action code block.
  2304. * >
  2305. *
  2306. * @public
  2307. * @this {RegExpLexer}
  2308. */
  2309. upcomingInput: function lexer_upcomingInput(maxSize, maxLines) {
  2310. var next = this.match;
  2311. if (maxSize < 0)
  2312. maxSize = next.length + this._input.length;
  2313. else if (!maxSize)
  2314. maxSize = 20;
  2315. if (maxLines < 0)
  2316. maxLines = maxSize; // can't ever have more input lines than this!
  2317. else if (!maxLines)
  2318. maxLines = 1;
  2319. // `substring` anticipation: treat \r\n as a single character and take a little
  2320. // more than necessary so that we can still properly check against maxSize
  2321. // after we've transformed and limited the newLines in here:
  2322. if (next.length < maxSize * 2 + 2) {
  2323. next += this._input.substring(0, maxSize * 2 + 2); // substring is faster on Chrome/V8
  2324. }
  2325. // now that we have a significantly reduced string to process, transform the newlines
  2326. // and chop them, then limit them:
  2327. var a = next.replace(/\r\n|\r/g, '\n').split('\n');
  2328. a = a.slice(0, maxLines);
  2329. next = a.join('\n');
  2330. // When, after limiting to maxLines, we still have too much to return,
  2331. // do add an ellipsis postfix...
  2332. if (next.length > maxSize) {
  2333. next = next.substring(0, maxSize) + '...';
  2334. }
  2335. return next;
  2336. },
  2337. /**
  2338. * return a string which displays the character position where the
  2339. * lexing error occurred, i.e. for error messages
  2340. *
  2341. * @public
  2342. * @this {RegExpLexer}
  2343. */
  2344. showPosition: function lexer_showPosition(maxPrefix, maxPostfix) {
  2345. var pre = this.pastInput(maxPrefix).replace(/\s/g, ' ');
  2346. var c = new Array(pre.length + 1).join('-');
  2347. return pre + this.upcomingInput(maxPostfix).replace(/\s/g, ' ') + '\n' + c + '^';
  2348. },
  2349. /**
  2350. * return an YYLLOC info object derived off the given context (actual, preceding, following, current).
  2351. * Use this method when the given `actual` location is not guaranteed to exist (i.e. when
  2352. * it MAY be NULL) and you MUST have a valid location info object anyway:
  2353. * then we take the given context of the `preceding` and `following` locations, IFF those are available,
  2354. * and reconstruct the `actual` location info from those.
  2355. * If this fails, the heuristic is to take the `current` location, IFF available.
  2356. * If this fails as well, we assume the sought location is at/around the current lexer position
  2357. * and then produce that one as a response. DO NOTE that these heuristic/derived location info
  2358. * values MAY be inaccurate!
  2359. *
  2360. * NOTE: `deriveLocationInfo()` ALWAYS produces a location info object *copy* of `actual`, not just
  2361. * a *reference* hence all input location objects can be assumed to be 'constant' (function has no side-effects).
  2362. *
  2363. * @public
  2364. * @this {RegExpLexer}
  2365. */
  2366. deriveLocationInfo: function lexer_deriveYYLLOC(actual, preceding, following, current) {
  2367. var loc = {
  2368. first_line: 1,
  2369. first_column: 0,
  2370. last_line: 1,
  2371. last_column: 0,
  2372. range: [0, 0]
  2373. };
  2374. if (actual) {
  2375. loc.first_line = actual.first_line | 0;
  2376. loc.last_line = actual.last_line | 0;
  2377. loc.first_column = actual.first_column | 0;
  2378. loc.last_column = actual.last_column | 0;
  2379. if (actual.range) {
  2380. loc.range[0] = actual.range[0] | 0;
  2381. loc.range[1] = actual.range[1] | 0;
  2382. }
  2383. }
  2384. if (loc.first_line <= 0 || loc.last_line < loc.first_line) {
  2385. // plan B: heuristic using preceding and following:
  2386. if (loc.first_line <= 0 && preceding) {
  2387. loc.first_line = preceding.last_line | 0;
  2388. loc.first_column = preceding.last_column | 0;
  2389. if (preceding.range) {
  2390. loc.range[0] = actual.range[1] | 0;
  2391. }
  2392. }
  2393. if ((loc.last_line <= 0 || loc.last_line < loc.first_line) && following) {
  2394. loc.last_line = following.first_line | 0;
  2395. loc.last_column = following.first_column | 0;
  2396. if (following.range) {
  2397. loc.range[1] = actual.range[0] | 0;
  2398. }
  2399. }
  2400. // plan C?: see if the 'current' location is useful/sane too:
  2401. if (loc.first_line <= 0 && current && (loc.last_line <= 0 || current.last_line <= loc.last_line)) {
  2402. loc.first_line = current.first_line | 0;
  2403. loc.first_column = current.first_column | 0;
  2404. if (current.range) {
  2405. loc.range[0] = current.range[0] | 0;
  2406. }
  2407. }
  2408. if (loc.last_line <= 0 && current && (loc.first_line <= 0 || current.first_line >= loc.first_line)) {
  2409. loc.last_line = current.last_line | 0;
  2410. loc.last_column = current.last_column | 0;
  2411. if (current.range) {
  2412. loc.range[1] = current.range[1] | 0;
  2413. }
  2414. }
  2415. }
  2416. // sanitize: fix last_line BEFORE we fix first_line as we use the 'raw' value of the latter
  2417. // or plan D heuristics to produce a 'sensible' last_line value:
  2418. if (loc.last_line <= 0) {
  2419. if (loc.first_line <= 0) {
  2420. loc.first_line = this.yylloc.first_line;
  2421. loc.last_line = this.yylloc.last_line;
  2422. loc.first_column = this.yylloc.first_column;
  2423. loc.last_column = this.yylloc.last_column;
  2424. loc.range[0] = this.yylloc.range[0];
  2425. loc.range[1] = this.yylloc.range[1];
  2426. } else {
  2427. loc.last_line = this.yylloc.last_line;
  2428. loc.last_column = this.yylloc.last_column;
  2429. loc.range[1] = this.yylloc.range[1];
  2430. }
  2431. }
  2432. if (loc.first_line <= 0) {
  2433. loc.first_line = loc.last_line;
  2434. loc.first_column = 0; // loc.last_column;
  2435. loc.range[1] = loc.range[0];
  2436. }
  2437. if (loc.first_column < 0) {
  2438. loc.first_column = 0;
  2439. }
  2440. if (loc.last_column < 0) {
  2441. loc.last_column = (loc.first_column > 0 ? loc.first_column : 80);
  2442. }
  2443. return loc;
  2444. },
  2445. /**
  2446. * return a string which displays the lines & columns of input which are referenced
  2447. * by the given location info range, plus a few lines of context.
  2448. *
  2449. * This function pretty-prints the indicated section of the input, with line numbers
  2450. * and everything!
  2451. *
  2452. * This function is very useful to provide highly readable error reports, while
  2453. * the location range may be specified in various flexible ways:
  2454. *
  2455. * - `loc` is the location info object which references the area which should be
  2456. * displayed and 'marked up': these lines & columns of text are marked up by `^`
  2457. * characters below each character in the entire input range.
  2458. *
  2459. * - `context_loc` is the *optional* location info object which instructs this
  2460. * pretty-printer how much *leading* context should be displayed alongside
  2461. * the area referenced by `loc`. This can help provide context for the displayed
  2462. * error, etc.
  2463. *
  2464. * When this location info is not provided, a default context of 3 lines is
  2465. * used.
  2466. *
  2467. * - `context_loc2` is another *optional* location info object, which serves
  2468. * a similar purpose to `context_loc`: it specifies the amount of *trailing*
  2469. * context lines to display in the pretty-print output.
  2470. *
  2471. * When this location info is not provided, a default context of 1 line only is
  2472. * used.
  2473. *
  2474. * Special Notes:
  2475. *
  2476. * - when the `loc`-indicated range is very large (about 5 lines or more), then
  2477. * only the first and last few lines of this block are printed while a
  2478. * `...continued...` message will be printed between them.
  2479. *
  2480. * This serves the purpose of not printing a huge amount of text when the `loc`
  2481. * range happens to be huge: this way a manageable & readable output results
  2482. * for arbitrary large ranges.
  2483. *
  2484. * - this function can display lines of input which whave not yet been lexed.
  2485. * `prettyPrintRange()` can access the entire input!
  2486. *
  2487. * @public
  2488. * @this {RegExpLexer}
  2489. */
  2490. prettyPrintRange: function lexer_prettyPrintRange(loc, context_loc, context_loc2) {
  2491. loc = this.deriveLocationInfo(loc, context_loc, context_loc2);
  2492. const CONTEXT = 3;
  2493. const CONTEXT_TAIL = 1;
  2494. const MINIMUM_VISIBLE_NONEMPTY_LINE_COUNT = 2;
  2495. var input = this.matched + this._input;
  2496. var lines = input.split('\n');
  2497. var l0 = Math.max(1, (context_loc ? context_loc.first_line : loc.first_line - CONTEXT));
  2498. var l1 = Math.max(1, (context_loc2 ? context_loc2.last_line : loc.last_line + CONTEXT_TAIL));
  2499. var lineno_display_width = 1 + Math.log10(l1 | 1) | 0;
  2500. var ws_prefix = new Array(lineno_display_width).join(' ');
  2501. var nonempty_line_indexes = [];
  2502. var rv = lines.slice(l0 - 1, l1 + 1).map(function injectLineNumber(line, index) {
  2503. var lno = index + l0;
  2504. var lno_pfx = (ws_prefix + lno).substr(-lineno_display_width);
  2505. var rv = lno_pfx + ': ' + line;
  2506. var errpfx = new Array(lineno_display_width + 1).join('^');
  2507. var offset = 2 + 1;
  2508. var len = 0;
  2509. if (lno === loc.first_line) {
  2510. offset += loc.first_column;
  2511. len = Math.max(
  2512. 2,
  2513. ((lno === loc.last_line ? loc.last_column : line.length)) - loc.first_column + 1
  2514. );
  2515. } else if (lno === loc.last_line) {
  2516. len = Math.max(2, loc.last_column + 1);
  2517. } else if (lno > loc.first_line && lno < loc.last_line) {
  2518. len = Math.max(2, line.length + 1);
  2519. }
  2520. if (len) {
  2521. var lead = new Array(offset).join('.');
  2522. var mark = new Array(len).join('^');
  2523. rv += '\n' + errpfx + lead + mark;
  2524. if (line.trim().length > 0) {
  2525. nonempty_line_indexes.push(index);
  2526. }
  2527. }
  2528. rv = rv.replace(/\t/g, ' ');
  2529. return rv;
  2530. });
  2531. // now make sure we don't print an overly large amount of error area: limit it
  2532. // to the top and bottom line count:
  2533. if (nonempty_line_indexes.length > 2 * MINIMUM_VISIBLE_NONEMPTY_LINE_COUNT) {
  2534. var clip_start = nonempty_line_indexes[MINIMUM_VISIBLE_NONEMPTY_LINE_COUNT - 1] + 1;
  2535. var clip_end = nonempty_line_indexes[nonempty_line_indexes.length - MINIMUM_VISIBLE_NONEMPTY_LINE_COUNT] - 1;
  2536. var intermediate_line = new Array(lineno_display_width + 1).join(' ') + ' (...continued...)';
  2537. intermediate_line += '\n' + new Array(lineno_display_width + 1).join('-') + ' (---------------)';
  2538. rv.splice(clip_start, clip_end - clip_start + 1, intermediate_line);
  2539. }
  2540. return rv.join('\n');
  2541. },
  2542. /**
  2543. * helper function, used to produce a human readable description as a string, given
  2544. * the input `yylloc` location object.
  2545. *
  2546. * Set `display_range_too` to TRUE to include the string character index position(s)
  2547. * in the description if the `yylloc.range` is available.
  2548. *
  2549. * @public
  2550. * @this {RegExpLexer}
  2551. */
  2552. describeYYLLOC: function lexer_describe_yylloc(yylloc, display_range_too) {
  2553. var l1 = yylloc.first_line;
  2554. var l2 = yylloc.last_line;
  2555. var c1 = yylloc.first_column;
  2556. var c2 = yylloc.last_column;
  2557. var dl = l2 - l1;
  2558. var dc = c2 - c1;
  2559. var rv;
  2560. if (dl === 0) {
  2561. rv = 'line ' + l1 + ', ';
  2562. if (dc <= 1) {
  2563. rv += 'column ' + c1;
  2564. } else {
  2565. rv += 'columns ' + c1 + ' .. ' + c2;
  2566. }
  2567. } else {
  2568. rv = 'lines ' + l1 + '(column ' + c1 + ') .. ' + l2 + '(column ' + c2 + ')';
  2569. }
  2570. if (yylloc.range && display_range_too) {
  2571. var r1 = yylloc.range[0];
  2572. var r2 = yylloc.range[1] - 1;
  2573. if (r2 <= r1) {
  2574. rv += ' {String Offset: ' + r1 + '}';
  2575. } else {
  2576. rv += ' {String Offset range: ' + r1 + ' .. ' + r2 + '}';
  2577. }
  2578. }
  2579. return rv;
  2580. },
  2581. /**
  2582. * test the lexed token: return FALSE when not a match, otherwise return token.
  2583. *
  2584. * `match` is supposed to be an array coming out of a regex match, i.e. `match[0]`
  2585. * contains the actually matched text string.
  2586. *
  2587. * Also move the input cursor forward and update the match collectors:
  2588. *
  2589. * - `yytext`
  2590. * - `yyleng`
  2591. * - `match`
  2592. * - `matches`
  2593. * - `yylloc`
  2594. * - `offset`
  2595. *
  2596. * @public
  2597. * @this {RegExpLexer}
  2598. */
  2599. test_match: function lexer_test_match(match, indexed_rule) {
  2600. var token, lines, backup, match_str, match_str_len;
  2601. if (this.options.backtrack_lexer) {
  2602. // save context
  2603. backup = {
  2604. yylineno: this.yylineno,
  2605. yylloc: {
  2606. first_line: this.yylloc.first_line,
  2607. last_line: this.yylloc.last_line,
  2608. first_column: this.yylloc.first_column,
  2609. last_column: this.yylloc.last_column,
  2610. range: this.yylloc.range.slice(0)
  2611. },
  2612. yytext: this.yytext,
  2613. match: this.match,
  2614. matches: this.matches,
  2615. matched: this.matched,
  2616. yyleng: this.yyleng,
  2617. offset: this.offset,
  2618. _more: this._more,
  2619. _input: this._input,
  2620. //_signaled_error_token: this._signaled_error_token,
  2621. yy: this.yy,
  2622. conditionStack: this.conditionStack.slice(0),
  2623. done: this.done
  2624. };
  2625. }
  2626. match_str = match[0];
  2627. match_str_len = match_str.length;
  2628. // if (match_str.indexOf('\n') !== -1 || match_str.indexOf('\r') !== -1) {
  2629. lines = match_str.split(/(?:\r\n?|\n)/g);
  2630. if (lines.length > 1) {
  2631. this.yylineno += lines.length - 1;
  2632. this.yylloc.last_line = this.yylineno + 1;
  2633. this.yylloc.last_column = lines[lines.length - 1].length;
  2634. } else {
  2635. this.yylloc.last_column += match_str_len;
  2636. }
  2637. // }
  2638. this.yytext += match_str;
  2639. this.match += match_str;
  2640. this.matched += match_str;
  2641. this.matches = match;
  2642. this.yyleng = this.yytext.length;
  2643. this.yylloc.range[1] += match_str_len;
  2644. // previous lex rules MAY have invoked the `more()` API rather than producing a token:
  2645. // those rules will already have moved this `offset` forward matching their match lengths,
  2646. // hence we must only add our own match length now:
  2647. this.offset += match_str_len;
  2648. this._more = false;
  2649. this._backtrack = false;
  2650. this._input = this._input.slice(match_str_len);
  2651. // calling this method:
  2652. //
  2653. // function lexer__performAction(yy, yyrulenumber, YY_START) {...}
  2654. token = this.performAction.call(
  2655. this,
  2656. this.yy,
  2657. indexed_rule,
  2658. this.conditionStack[this.conditionStack.length - 1] /* = YY_START */
  2659. );
  2660. // otherwise, when the action codes are all simple return token statements:
  2661. //token = this.simpleCaseActionClusters[indexed_rule];
  2662. if (this.done && this._input) {
  2663. this.done = false;
  2664. }
  2665. if (token) {
  2666. return token;
  2667. } else if (this._backtrack) {
  2668. // recover context
  2669. for (var k in backup) {
  2670. this[k] = backup[k];
  2671. }
  2672. this.__currentRuleSet__ = null;
  2673. return false; // rule action called reject() implying the next rule should be tested instead.
  2674. } else if (this._signaled_error_token) {
  2675. // produce one 'error' token as `.parseError()` in `reject()`
  2676. // did not guarantee a failure signal by throwing an exception!
  2677. token = this._signaled_error_token;
  2678. this._signaled_error_token = false;
  2679. return token;
  2680. }
  2681. return false;
  2682. },
  2683. /**
  2684. * return next match in input
  2685. *
  2686. * @public
  2687. * @this {RegExpLexer}
  2688. */
  2689. next: function lexer_next() {
  2690. if (this.done) {
  2691. this.clear();
  2692. return this.EOF;
  2693. }
  2694. if (!this._input) {
  2695. this.done = true;
  2696. }
  2697. var token, match, tempMatch, index;
  2698. if (!this._more) {
  2699. this.clear();
  2700. }
  2701. var spec = this.__currentRuleSet__;
  2702. if (!spec) {
  2703. // Update the ruleset cache as we apparently encountered a state change or just started lexing.
  2704. // The cache is set up for fast lookup -- we assume a lexer will switch states much less often than it will
  2705. // invoke the `lex()` token-producing API and related APIs, hence caching the set for direct access helps
  2706. // speed up those activities a tiny bit.
  2707. spec = this.__currentRuleSet__ = this._currentRules();
  2708. // Check whether a *sane* condition has been pushed before: this makes the lexer robust against
  2709. // user-programmer bugs such as https://github.com/zaach/jison-lex/issues/19
  2710. if (!spec || !spec.rules) {
  2711. var lineno_msg = '';
  2712. if (this.options.trackPosition) {
  2713. lineno_msg = ' on line ' + (this.yylineno + 1);
  2714. }
  2715. var p = this.constructLexErrorInfo(
  2716. '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!',
  2717. false
  2718. );
  2719. // produce one 'error' token until this situation has been resolved, most probably by parse termination!
  2720. return this.parseError(p.errStr, p, this.JisonLexerError) || this.ERROR;
  2721. }
  2722. }
  2723. var rule_ids = spec.rules;
  2724. var regexes = spec.__rule_regexes;
  2725. var len = spec.__rule_count;
  2726. // Note: the arrays are 1-based, while `len` itself is a valid index,
  2727. // hence the non-standard less-or-equal check in the next loop condition!
  2728. for (var i = 1; i <= len; i++) {
  2729. tempMatch = this._input.match(regexes[i]);
  2730. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  2731. match = tempMatch;
  2732. index = i;
  2733. if (this.options.backtrack_lexer) {
  2734. token = this.test_match(tempMatch, rule_ids[i]);
  2735. if (token !== false) {
  2736. return token;
  2737. } else if (this._backtrack) {
  2738. match = undefined;
  2739. continue; // rule action called reject() implying a rule MISmatch.
  2740. } else {
  2741. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  2742. return false;
  2743. }
  2744. } else if (!this.options.flex) {
  2745. break;
  2746. }
  2747. }
  2748. }
  2749. if (match) {
  2750. token = this.test_match(match, rule_ids[index]);
  2751. if (token !== false) {
  2752. return token;
  2753. }
  2754. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  2755. return false;
  2756. }
  2757. if (!this._input) {
  2758. this.done = true;
  2759. this.clear();
  2760. return this.EOF;
  2761. } else {
  2762. var lineno_msg = '';
  2763. if (this.options.trackPosition) {
  2764. lineno_msg = ' on line ' + (this.yylineno + 1);
  2765. }
  2766. var p = this.constructLexErrorInfo(
  2767. 'Lexical error' + lineno_msg + ': Unrecognized text.',
  2768. this.options.lexerErrorsAreRecoverable
  2769. );
  2770. var pendingInput = this._input;
  2771. var activeCondition = this.topState();
  2772. var conditionStackDepth = this.conditionStack.length;
  2773. token = this.parseError(p.errStr, p, this.JisonLexerError) || this.ERROR;
  2774. if (token === this.ERROR) {
  2775. // we can try to recover from a lexer error that `parseError()` did not 'recover' for us
  2776. // by moving forward at least one character at a time IFF the (user-specified?) `parseError()`
  2777. // has not consumed/modified any pending input or changed state in the error handler:
  2778. if (!this.matches && // and make sure the input has been modified/consumed ...
  2779. pendingInput === this._input && // ...or the lexer state has been modified significantly enough
  2780. // to merit a non-consuming error handling action right now.
  2781. activeCondition === this.topState() && conditionStackDepth === this.conditionStack.length) {
  2782. this.input();
  2783. }
  2784. }
  2785. return token;
  2786. }
  2787. },
  2788. /**
  2789. * return next match that has a token
  2790. *
  2791. * @public
  2792. * @this {RegExpLexer}
  2793. */
  2794. lex: function lexer_lex() {
  2795. var r;
  2796. // allow the PRE/POST handlers set/modify the return token for maximum flexibility of the generated lexer:
  2797. if (typeof this.pre_lex === 'function') {
  2798. r = this.pre_lex.call(this, 0);
  2799. }
  2800. if (typeof this.options.pre_lex === 'function') {
  2801. // (also account for a userdef function which does not return any value: keep the token as is)
  2802. r = this.options.pre_lex.call(this, r) || r;
  2803. }
  2804. if (this.yy && typeof this.yy.pre_lex === 'function') {
  2805. // (also account for a userdef function which does not return any value: keep the token as is)
  2806. r = this.yy.pre_lex.call(this, r) || r;
  2807. }
  2808. while (!r) {
  2809. r = this.next();
  2810. }
  2811. if (this.yy && typeof this.yy.post_lex === 'function') {
  2812. // (also account for a userdef function which does not return any value: keep the token as is)
  2813. r = this.yy.post_lex.call(this, r) || r;
  2814. }
  2815. if (typeof this.options.post_lex === 'function') {
  2816. // (also account for a userdef function which does not return any value: keep the token as is)
  2817. r = this.options.post_lex.call(this, r) || r;
  2818. }
  2819. if (typeof this.post_lex === 'function') {
  2820. // (also account for a userdef function which does not return any value: keep the token as is)
  2821. r = this.post_lex.call(this, r) || r;
  2822. }
  2823. return r;
  2824. },
  2825. /**
  2826. * return next match that has a token. Identical to the `lex()` API but does not invoke any of the
  2827. * `pre_lex()` nor any of the `post_lex()` callbacks.
  2828. *
  2829. * @public
  2830. * @this {RegExpLexer}
  2831. */
  2832. fastLex: function lexer_fastLex() {
  2833. var r;
  2834. while (!r) {
  2835. r = this.next();
  2836. }
  2837. return r;
  2838. },
  2839. /**
  2840. * return info about the lexer state that can help a parser or other lexer API user to use the
  2841. * most efficient means available. This API is provided to aid run-time performance for larger
  2842. * systems which employ this lexer.
  2843. *
  2844. * @public
  2845. * @this {RegExpLexer}
  2846. */
  2847. canIUse: function lexer_canIUse() {
  2848. var rv = {
  2849. 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'
  2850. };
  2851. return rv;
  2852. },
  2853. /**
  2854. * backwards compatible alias for `pushState()`;
  2855. * the latter is symmetrical with `popState()` and we advise to use
  2856. * those APIs in any modern lexer code, rather than `begin()`.
  2857. *
  2858. * @public
  2859. * @this {RegExpLexer}
  2860. */
  2861. begin: function lexer_begin(condition) {
  2862. return this.pushState(condition);
  2863. },
  2864. /**
  2865. * activates a new lexer condition state (pushes the new lexer
  2866. * condition state onto the condition stack)
  2867. *
  2868. * @public
  2869. * @this {RegExpLexer}
  2870. */
  2871. pushState: function lexer_pushState(condition) {
  2872. this.conditionStack.push(condition);
  2873. this.__currentRuleSet__ = null;
  2874. return this;
  2875. },
  2876. /**
  2877. * pop the previously active lexer condition state off the condition
  2878. * stack
  2879. *
  2880. * @public
  2881. * @this {RegExpLexer}
  2882. */
  2883. popState: function lexer_popState() {
  2884. var n = this.conditionStack.length - 1;
  2885. if (n > 0) {
  2886. this.__currentRuleSet__ = null;
  2887. return this.conditionStack.pop();
  2888. } else {
  2889. return this.conditionStack[0];
  2890. }
  2891. },
  2892. /**
  2893. * return the currently active lexer condition state; when an index
  2894. * argument is provided it produces the N-th previous condition state,
  2895. * if available
  2896. *
  2897. * @public
  2898. * @this {RegExpLexer}
  2899. */
  2900. topState: function lexer_topState(n) {
  2901. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  2902. if (n >= 0) {
  2903. return this.conditionStack[n];
  2904. } else {
  2905. return 'INITIAL';
  2906. }
  2907. },
  2908. /**
  2909. * (internal) determine the lexer rule set which is active for the
  2910. * currently active lexer condition state
  2911. *
  2912. * @public
  2913. * @this {RegExpLexer}
  2914. */
  2915. _currentRules: function lexer__currentRules() {
  2916. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  2917. return this.conditions[this.conditionStack[this.conditionStack.length - 1]];
  2918. } else {
  2919. return this.conditions['INITIAL'];
  2920. }
  2921. },
  2922. /**
  2923. * return the number of states currently on the stack
  2924. *
  2925. * @public
  2926. * @this {RegExpLexer}
  2927. */
  2928. stateStackSize: function lexer_stateStackSize() {
  2929. return this.conditionStack.length;
  2930. },
  2931. options: {
  2932. trackPosition: true,
  2933. caseInsensitive: true
  2934. },
  2935. JisonLexerError: JisonLexerError,
  2936. performAction: function lexer__performAction(yy, yyrulenumber, YY_START) {
  2937. var yy_ = this;
  2938. var YYSTATE = YY_START;
  2939. switch (yyrulenumber) {
  2940. case 0:
  2941. /*! Conditions:: INITIAL */
  2942. /*! Rule:: \s+ */
  2943. /* skip whitespace */
  2944. break;
  2945. default:
  2946. return this.simpleCaseActionClusters[yyrulenumber];
  2947. }
  2948. },
  2949. simpleCaseActionClusters: {
  2950. /*! Conditions:: INITIAL */
  2951. /*! Rule:: (-(webkit|moz)-)?calc\b */
  2952. 1: 3,
  2953. /*! Conditions:: INITIAL */
  2954. /*! Rule:: [a-z][a-z0-9-]*\s*\((?:(?:"(?:\\.|[^\"\\])*"|'(?:\\.|[^\'\\])*')|\([^)]*\)|[^\(\)]*)*\) */
  2955. 2: 10,
  2956. /*! Conditions:: INITIAL */
  2957. /*! Rule:: \* */
  2958. 3: 8,
  2959. /*! Conditions:: INITIAL */
  2960. /*! Rule:: \/ */
  2961. 4: 9,
  2962. /*! Conditions:: INITIAL */
  2963. /*! Rule:: \+ */
  2964. 5: 6,
  2965. /*! Conditions:: INITIAL */
  2966. /*! Rule:: - */
  2967. 6: 7,
  2968. /*! Conditions:: INITIAL */
  2969. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)em\b */
  2970. 7: 17,
  2971. /*! Conditions:: INITIAL */
  2972. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)ex\b */
  2973. 8: 18,
  2974. /*! Conditions:: INITIAL */
  2975. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)ch\b */
  2976. 9: 19,
  2977. /*! Conditions:: INITIAL */
  2978. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)rem\b */
  2979. 10: 20,
  2980. /*! Conditions:: INITIAL */
  2981. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)vw\b */
  2982. 11: 22,
  2983. /*! Conditions:: INITIAL */
  2984. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)vh\b */
  2985. 12: 21,
  2986. /*! Conditions:: INITIAL */
  2987. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)vmin\b */
  2988. 13: 23,
  2989. /*! Conditions:: INITIAL */
  2990. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)vmax\b */
  2991. 14: 24,
  2992. /*! Conditions:: INITIAL */
  2993. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)cm\b */
  2994. 15: 11,
  2995. /*! Conditions:: INITIAL */
  2996. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)mm\b */
  2997. 16: 11,
  2998. /*! Conditions:: INITIAL */
  2999. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)Q\b */
  3000. 17: 11,
  3001. /*! Conditions:: INITIAL */
  3002. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)in\b */
  3003. 18: 11,
  3004. /*! Conditions:: INITIAL */
  3005. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)pt\b */
  3006. 19: 11,
  3007. /*! Conditions:: INITIAL */
  3008. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)pc\b */
  3009. 20: 11,
  3010. /*! Conditions:: INITIAL */
  3011. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)px\b */
  3012. 21: 11,
  3013. /*! Conditions:: INITIAL */
  3014. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)deg\b */
  3015. 22: 12,
  3016. /*! Conditions:: INITIAL */
  3017. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)grad\b */
  3018. 23: 12,
  3019. /*! Conditions:: INITIAL */
  3020. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)rad\b */
  3021. 24: 12,
  3022. /*! Conditions:: INITIAL */
  3023. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)turn\b */
  3024. 25: 12,
  3025. /*! Conditions:: INITIAL */
  3026. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)s\b */
  3027. 26: 13,
  3028. /*! Conditions:: INITIAL */
  3029. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)ms\b */
  3030. 27: 13,
  3031. /*! Conditions:: INITIAL */
  3032. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)Hz\b */
  3033. 28: 14,
  3034. /*! Conditions:: INITIAL */
  3035. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)kHz\b */
  3036. 29: 14,
  3037. /*! Conditions:: INITIAL */
  3038. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)dpi\b */
  3039. 30: 15,
  3040. /*! Conditions:: INITIAL */
  3041. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)dpcm\b */
  3042. 31: 15,
  3043. /*! Conditions:: INITIAL */
  3044. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)dppx\b */
  3045. 32: 15,
  3046. /*! Conditions:: INITIAL */
  3047. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)% */
  3048. 33: 25,
  3049. /*! Conditions:: INITIAL */
  3050. /*! Rule:: (([0-9]+(\.[0-9]+)?|\.[0-9]+)(e(\+|-)[0-9]+)?)\b */
  3051. 34: 26,
  3052. /*! Conditions:: INITIAL */
  3053. /*! 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 */
  3054. 35: 16,
  3055. /*! Conditions:: INITIAL */
  3056. /*! Rule:: \( */
  3057. 36: 4,
  3058. /*! Conditions:: INITIAL */
  3059. /*! Rule:: \) */
  3060. 37: 5,
  3061. /*! Conditions:: INITIAL */
  3062. /*! Rule:: $ */
  3063. 38: 1
  3064. },
  3065. rules: [
  3066. /* 0: */ /^(?:\s+)/i,
  3067. /* 1: */ /^(?:(-(webkit|moz)-)?calc\b)/i,
  3068. /* 2: */ /^(?:[a-z][\d\-a-z]*\s*\((?:(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')|\([^)]*\)|[^()]*)*\))/i,
  3069. /* 3: */ /^(?:\*)/i,
  3070. /* 4: */ /^(?:\/)/i,
  3071. /* 5: */ /^(?:\+)/i,
  3072. /* 6: */ /^(?:-)/i,
  3073. /* 7: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)em\b)/i,
  3074. /* 8: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)ex\b)/i,
  3075. /* 9: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)ch\b)/i,
  3076. /* 10: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)rem\b)/i,
  3077. /* 11: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)vw\b)/i,
  3078. /* 12: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)vh\b)/i,
  3079. /* 13: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)vmin\b)/i,
  3080. /* 14: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)vmax\b)/i,
  3081. /* 15: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)cm\b)/i,
  3082. /* 16: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)mm\b)/i,
  3083. /* 17: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)Q\b)/i,
  3084. /* 18: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)in\b)/i,
  3085. /* 19: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)pt\b)/i,
  3086. /* 20: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)pc\b)/i,
  3087. /* 21: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)px\b)/i,
  3088. /* 22: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)deg\b)/i,
  3089. /* 23: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)grad\b)/i,
  3090. /* 24: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)rad\b)/i,
  3091. /* 25: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)turn\b)/i,
  3092. /* 26: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)s\b)/i,
  3093. /* 27: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)ms\b)/i,
  3094. /* 28: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)Hz\b)/i,
  3095. /* 29: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)kHz\b)/i,
  3096. /* 30: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)dpi\b)/i,
  3097. /* 31: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)dpcm\b)/i,
  3098. /* 32: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)dppx\b)/i,
  3099. /* 33: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)%)/i,
  3100. /* 34: */ /^(?:((\d+(\.\d+)?|\.\d+)(e(\+|-)\d+)?)\b)/i,
  3101. /* 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,
  3102. /* 36: */ /^(?:\()/i,
  3103. /* 37: */ /^(?:\))/i,
  3104. /* 38: */ /^(?:$)/i
  3105. ],
  3106. conditions: {
  3107. 'INITIAL': {
  3108. rules: [
  3109. 0,
  3110. 1,
  3111. 2,
  3112. 3,
  3113. 4,
  3114. 5,
  3115. 6,
  3116. 7,
  3117. 8,
  3118. 9,
  3119. 10,
  3120. 11,
  3121. 12,
  3122. 13,
  3123. 14,
  3124. 15,
  3125. 16,
  3126. 17,
  3127. 18,
  3128. 19,
  3129. 20,
  3130. 21,
  3131. 22,
  3132. 23,
  3133. 24,
  3134. 25,
  3135. 26,
  3136. 27,
  3137. 28,
  3138. 29,
  3139. 30,
  3140. 31,
  3141. 32,
  3142. 33,
  3143. 34,
  3144. 35,
  3145. 36,
  3146. 37,
  3147. 38
  3148. ],
  3149. inclusive: true
  3150. }
  3151. }
  3152. };
  3153. return lexer;
  3154. }();
  3155. parser.lexer = lexer;
  3156. function Parser() {
  3157. this.yy = {};
  3158. }
  3159. Parser.prototype = parser;
  3160. parser.Parser = Parser;
  3161. return new Parser();
  3162. })();
  3163. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  3164. exports.parser = parser;
  3165. exports.Parser = parser.Parser;
  3166. exports.parse = function () {
  3167. return parser.parse.apply(parser, arguments);
  3168. };
  3169. }