parser_tests.lua 207 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317
  1. local REMOVE_THIS = vim.NIL
  2. return function(itp, _check_parsing, hl, fmtn)
  3. local function check_parsing(...)
  4. return _check_parsing({ flags = { 0, 1, 2, 3 }, funcname = 'check_parsing' }, ...)
  5. end
  6. local function check_asgn_parsing(...)
  7. return _check_parsing({
  8. flags = { 4, 5, 6, 7 },
  9. funcname = 'check_asgn_parsing',
  10. }, ...)
  11. end
  12. itp('works with + and @a', function()
  13. check_parsing('@a', {
  14. ast = {
  15. 'Register(name=a):0:0:@a',
  16. },
  17. }, {
  18. hl('Register', '@a'),
  19. })
  20. check_parsing('+@a', {
  21. ast = {
  22. {
  23. 'UnaryPlus:0:0:+',
  24. children = {
  25. 'Register(name=a):0:1:@a',
  26. },
  27. },
  28. },
  29. }, {
  30. hl('UnaryPlus', '+'),
  31. hl('Register', '@a'),
  32. })
  33. check_parsing('@a+@b', {
  34. ast = {
  35. {
  36. 'BinaryPlus:0:2:+',
  37. children = {
  38. 'Register(name=a):0:0:@a',
  39. 'Register(name=b):0:3:@b',
  40. },
  41. },
  42. },
  43. }, {
  44. hl('Register', '@a'),
  45. hl('BinaryPlus', '+'),
  46. hl('Register', '@b'),
  47. })
  48. check_parsing('@a+@b+@c', {
  49. ast = {
  50. {
  51. 'BinaryPlus:0:5:+',
  52. children = {
  53. {
  54. 'BinaryPlus:0:2:+',
  55. children = {
  56. 'Register(name=a):0:0:@a',
  57. 'Register(name=b):0:3:@b',
  58. },
  59. },
  60. 'Register(name=c):0:6:@c',
  61. },
  62. },
  63. },
  64. }, {
  65. hl('Register', '@a'),
  66. hl('BinaryPlus', '+'),
  67. hl('Register', '@b'),
  68. hl('BinaryPlus', '+'),
  69. hl('Register', '@c'),
  70. })
  71. check_parsing('+@a+@b', {
  72. ast = {
  73. {
  74. 'BinaryPlus:0:3:+',
  75. children = {
  76. {
  77. 'UnaryPlus:0:0:+',
  78. children = {
  79. 'Register(name=a):0:1:@a',
  80. },
  81. },
  82. 'Register(name=b):0:4:@b',
  83. },
  84. },
  85. },
  86. }, {
  87. hl('UnaryPlus', '+'),
  88. hl('Register', '@a'),
  89. hl('BinaryPlus', '+'),
  90. hl('Register', '@b'),
  91. })
  92. check_parsing('+@a++@b', {
  93. ast = {
  94. {
  95. 'BinaryPlus:0:3:+',
  96. children = {
  97. {
  98. 'UnaryPlus:0:0:+',
  99. children = {
  100. 'Register(name=a):0:1:@a',
  101. },
  102. },
  103. {
  104. 'UnaryPlus:0:4:+',
  105. children = {
  106. 'Register(name=b):0:5:@b',
  107. },
  108. },
  109. },
  110. },
  111. },
  112. }, {
  113. hl('UnaryPlus', '+'),
  114. hl('Register', '@a'),
  115. hl('BinaryPlus', '+'),
  116. hl('UnaryPlus', '+'),
  117. hl('Register', '@b'),
  118. })
  119. check_parsing('@a@b', {
  120. ast = {
  121. {
  122. 'OpMissing:0:2:',
  123. children = {
  124. 'Register(name=a):0:0:@a',
  125. 'Register(name=b):0:2:@b',
  126. },
  127. },
  128. },
  129. err = {
  130. arg = '@b',
  131. msg = 'E15: Missing operator: %.*s',
  132. },
  133. }, {
  134. hl('Register', '@a'),
  135. hl('InvalidRegister', '@b'),
  136. }, {
  137. [1] = {
  138. ast = {
  139. len = 2,
  140. err = REMOVE_THIS,
  141. ast = {
  142. 'Register(name=a):0:0:@a',
  143. },
  144. },
  145. hl_fs = {
  146. [2] = REMOVE_THIS,
  147. },
  148. },
  149. })
  150. check_parsing(' @a \t @b', {
  151. ast = {
  152. {
  153. 'OpMissing:0:3:',
  154. children = {
  155. 'Register(name=a):0:0: @a',
  156. 'Register(name=b):0:3: \t @b',
  157. },
  158. },
  159. },
  160. err = {
  161. arg = '@b',
  162. msg = 'E15: Missing operator: %.*s',
  163. },
  164. }, {
  165. hl('Register', '@a', 1),
  166. hl('InvalidSpacing', ' \t '),
  167. hl('Register', '@b'),
  168. }, {
  169. [1] = {
  170. ast = {
  171. len = 6,
  172. err = REMOVE_THIS,
  173. ast = {
  174. 'Register(name=a):0:0: @a',
  175. },
  176. },
  177. hl_fs = {
  178. [2] = REMOVE_THIS,
  179. [3] = REMOVE_THIS,
  180. },
  181. },
  182. })
  183. check_parsing('+', {
  184. ast = {
  185. 'UnaryPlus:0:0:+',
  186. },
  187. err = {
  188. arg = '',
  189. msg = 'E15: Expected value, got EOC: %.*s',
  190. },
  191. }, {
  192. hl('UnaryPlus', '+'),
  193. })
  194. check_parsing(' +', {
  195. ast = {
  196. 'UnaryPlus:0:0: +',
  197. },
  198. err = {
  199. arg = '',
  200. msg = 'E15: Expected value, got EOC: %.*s',
  201. },
  202. }, {
  203. hl('UnaryPlus', '+', 1),
  204. })
  205. check_parsing('@a+ ', {
  206. ast = {
  207. {
  208. 'BinaryPlus:0:2:+',
  209. children = {
  210. 'Register(name=a):0:0:@a',
  211. },
  212. },
  213. },
  214. err = {
  215. arg = '',
  216. msg = 'E15: Expected value, got EOC: %.*s',
  217. },
  218. }, {
  219. hl('Register', '@a'),
  220. hl('BinaryPlus', '+'),
  221. })
  222. end)
  223. itp('works with @a, + and parenthesis', function()
  224. check_parsing('(@a)', {
  225. ast = {
  226. {
  227. 'Nested:0:0:(',
  228. children = {
  229. 'Register(name=a):0:1:@a',
  230. },
  231. },
  232. },
  233. }, {
  234. hl('NestingParenthesis', '('),
  235. hl('Register', '@a'),
  236. hl('NestingParenthesis', ')'),
  237. })
  238. check_parsing('()', {
  239. ast = {
  240. {
  241. 'Nested:0:0:(',
  242. children = {
  243. 'Missing:0:1:',
  244. },
  245. },
  246. },
  247. err = {
  248. arg = ')',
  249. msg = 'E15: Expected value, got parenthesis: %.*s',
  250. },
  251. }, {
  252. hl('NestingParenthesis', '('),
  253. hl('InvalidNestingParenthesis', ')'),
  254. })
  255. check_parsing(')', {
  256. ast = {
  257. {
  258. 'Nested:0:0:',
  259. children = {
  260. 'Missing:0:0:',
  261. },
  262. },
  263. },
  264. err = {
  265. arg = ')',
  266. msg = 'E15: Expected value, got parenthesis: %.*s',
  267. },
  268. }, {
  269. hl('InvalidNestingParenthesis', ')'),
  270. })
  271. check_parsing('+)', {
  272. ast = {
  273. {
  274. 'Nested:0:1:',
  275. children = {
  276. {
  277. 'UnaryPlus:0:0:+',
  278. children = {
  279. 'Missing:0:1:',
  280. },
  281. },
  282. },
  283. },
  284. },
  285. err = {
  286. arg = ')',
  287. msg = 'E15: Expected value, got parenthesis: %.*s',
  288. },
  289. }, {
  290. hl('UnaryPlus', '+'),
  291. hl('InvalidNestingParenthesis', ')'),
  292. })
  293. check_parsing('+@a(@b)', {
  294. ast = {
  295. {
  296. 'UnaryPlus:0:0:+',
  297. children = {
  298. {
  299. 'Call:0:3:(',
  300. children = {
  301. 'Register(name=a):0:1:@a',
  302. 'Register(name=b):0:4:@b',
  303. },
  304. },
  305. },
  306. },
  307. },
  308. }, {
  309. hl('UnaryPlus', '+'),
  310. hl('Register', '@a'),
  311. hl('CallingParenthesis', '('),
  312. hl('Register', '@b'),
  313. hl('CallingParenthesis', ')'),
  314. })
  315. check_parsing('@a+@b(@c)', {
  316. ast = {
  317. {
  318. 'BinaryPlus:0:2:+',
  319. children = {
  320. 'Register(name=a):0:0:@a',
  321. {
  322. 'Call:0:5:(',
  323. children = {
  324. 'Register(name=b):0:3:@b',
  325. 'Register(name=c):0:6:@c',
  326. },
  327. },
  328. },
  329. },
  330. },
  331. }, {
  332. hl('Register', '@a'),
  333. hl('BinaryPlus', '+'),
  334. hl('Register', '@b'),
  335. hl('CallingParenthesis', '('),
  336. hl('Register', '@c'),
  337. hl('CallingParenthesis', ')'),
  338. })
  339. check_parsing('@a()', {
  340. ast = {
  341. {
  342. 'Call:0:2:(',
  343. children = {
  344. 'Register(name=a):0:0:@a',
  345. },
  346. },
  347. },
  348. }, {
  349. hl('Register', '@a'),
  350. hl('CallingParenthesis', '('),
  351. hl('CallingParenthesis', ')'),
  352. })
  353. check_parsing('@a ()', {
  354. ast = {
  355. {
  356. 'OpMissing:0:2:',
  357. children = {
  358. 'Register(name=a):0:0:@a',
  359. {
  360. 'Nested:0:2: (',
  361. children = {
  362. 'Missing:0:4:',
  363. },
  364. },
  365. },
  366. },
  367. },
  368. err = {
  369. arg = '()',
  370. msg = 'E15: Missing operator: %.*s',
  371. },
  372. }, {
  373. hl('Register', '@a'),
  374. hl('InvalidSpacing', ' '),
  375. hl('NestingParenthesis', '('),
  376. hl('InvalidNestingParenthesis', ')'),
  377. }, {
  378. [1] = {
  379. ast = {
  380. len = 3,
  381. err = REMOVE_THIS,
  382. ast = {
  383. 'Register(name=a):0:0:@a',
  384. },
  385. },
  386. hl_fs = {
  387. [2] = REMOVE_THIS,
  388. [3] = REMOVE_THIS,
  389. [4] = REMOVE_THIS,
  390. },
  391. },
  392. })
  393. check_parsing('@a + (@b)', {
  394. ast = {
  395. {
  396. 'BinaryPlus:0:2: +',
  397. children = {
  398. 'Register(name=a):0:0:@a',
  399. {
  400. 'Nested:0:4: (',
  401. children = {
  402. 'Register(name=b):0:6:@b',
  403. },
  404. },
  405. },
  406. },
  407. },
  408. }, {
  409. hl('Register', '@a'),
  410. hl('BinaryPlus', '+', 1),
  411. hl('NestingParenthesis', '(', 1),
  412. hl('Register', '@b'),
  413. hl('NestingParenthesis', ')'),
  414. })
  415. check_parsing('@a + (+@b)', {
  416. ast = {
  417. {
  418. 'BinaryPlus:0:2: +',
  419. children = {
  420. 'Register(name=a):0:0:@a',
  421. {
  422. 'Nested:0:4: (',
  423. children = {
  424. {
  425. 'UnaryPlus:0:6:+',
  426. children = {
  427. 'Register(name=b):0:7:@b',
  428. },
  429. },
  430. },
  431. },
  432. },
  433. },
  434. },
  435. }, {
  436. hl('Register', '@a'),
  437. hl('BinaryPlus', '+', 1),
  438. hl('NestingParenthesis', '(', 1),
  439. hl('UnaryPlus', '+'),
  440. hl('Register', '@b'),
  441. hl('NestingParenthesis', ')'),
  442. })
  443. check_parsing('@a + (@b + @c)', {
  444. ast = {
  445. {
  446. 'BinaryPlus:0:2: +',
  447. children = {
  448. 'Register(name=a):0:0:@a',
  449. {
  450. 'Nested:0:4: (',
  451. children = {
  452. {
  453. 'BinaryPlus:0:8: +',
  454. children = {
  455. 'Register(name=b):0:6:@b',
  456. 'Register(name=c):0:10: @c',
  457. },
  458. },
  459. },
  460. },
  461. },
  462. },
  463. },
  464. }, {
  465. hl('Register', '@a'),
  466. hl('BinaryPlus', '+', 1),
  467. hl('NestingParenthesis', '(', 1),
  468. hl('Register', '@b'),
  469. hl('BinaryPlus', '+', 1),
  470. hl('Register', '@c', 1),
  471. hl('NestingParenthesis', ')'),
  472. })
  473. check_parsing('(@a)+@b', {
  474. ast = {
  475. {
  476. 'BinaryPlus:0:4:+',
  477. children = {
  478. {
  479. 'Nested:0:0:(',
  480. children = {
  481. 'Register(name=a):0:1:@a',
  482. },
  483. },
  484. 'Register(name=b):0:5:@b',
  485. },
  486. },
  487. },
  488. }, {
  489. hl('NestingParenthesis', '('),
  490. hl('Register', '@a'),
  491. hl('NestingParenthesis', ')'),
  492. hl('BinaryPlus', '+'),
  493. hl('Register', '@b'),
  494. })
  495. check_parsing('@a+(@b)(@c)', {
  496. -- 01234567890
  497. ast = {
  498. {
  499. 'BinaryPlus:0:2:+',
  500. children = {
  501. 'Register(name=a):0:0:@a',
  502. {
  503. 'Call:0:7:(',
  504. children = {
  505. {
  506. 'Nested:0:3:(',
  507. children = { 'Register(name=b):0:4:@b' },
  508. },
  509. 'Register(name=c):0:8:@c',
  510. },
  511. },
  512. },
  513. },
  514. },
  515. }, {
  516. hl('Register', '@a'),
  517. hl('BinaryPlus', '+'),
  518. hl('NestingParenthesis', '('),
  519. hl('Register', '@b'),
  520. hl('NestingParenthesis', ')'),
  521. hl('CallingParenthesis', '('),
  522. hl('Register', '@c'),
  523. hl('CallingParenthesis', ')'),
  524. })
  525. check_parsing('@a+((@b))(@c)', {
  526. -- 01234567890123456890123456789
  527. -- 0 1 2
  528. ast = {
  529. {
  530. 'BinaryPlus:0:2:+',
  531. children = {
  532. 'Register(name=a):0:0:@a',
  533. {
  534. 'Call:0:9:(',
  535. children = {
  536. {
  537. 'Nested:0:3:(',
  538. children = {
  539. {
  540. 'Nested:0:4:(',
  541. children = { 'Register(name=b):0:5:@b' },
  542. },
  543. },
  544. },
  545. 'Register(name=c):0:10:@c',
  546. },
  547. },
  548. },
  549. },
  550. },
  551. }, {
  552. hl('Register', '@a'),
  553. hl('BinaryPlus', '+'),
  554. hl('NestingParenthesis', '('),
  555. hl('NestingParenthesis', '('),
  556. hl('Register', '@b'),
  557. hl('NestingParenthesis', ')'),
  558. hl('NestingParenthesis', ')'),
  559. hl('CallingParenthesis', '('),
  560. hl('Register', '@c'),
  561. hl('CallingParenthesis', ')'),
  562. })
  563. check_parsing('@a+((@b))+@c', {
  564. -- 01234567890123456890123456789
  565. -- 0 1 2
  566. ast = {
  567. {
  568. 'BinaryPlus:0:9:+',
  569. children = {
  570. {
  571. 'BinaryPlus:0:2:+',
  572. children = {
  573. 'Register(name=a):0:0:@a',
  574. {
  575. 'Nested:0:3:(',
  576. children = {
  577. {
  578. 'Nested:0:4:(',
  579. children = { 'Register(name=b):0:5:@b' },
  580. },
  581. },
  582. },
  583. },
  584. },
  585. 'Register(name=c):0:10:@c',
  586. },
  587. },
  588. },
  589. }, {
  590. hl('Register', '@a'),
  591. hl('BinaryPlus', '+'),
  592. hl('NestingParenthesis', '('),
  593. hl('NestingParenthesis', '('),
  594. hl('Register', '@b'),
  595. hl('NestingParenthesis', ')'),
  596. hl('NestingParenthesis', ')'),
  597. hl('BinaryPlus', '+'),
  598. hl('Register', '@c'),
  599. })
  600. check_parsing('@a + (@b + @c) + @d(@e) + (+@f) + ((+@g(@h))(@j)(@k))(@l)', {--[[
  601. | | | | | | | | || | | || | | ||| || || || ||
  602. 000000000011111111112222222222333333333344444444445555555
  603. 012345678901234567890123456789012345678901234567890123456
  604. ]]
  605. ast = {
  606. {
  607. 'BinaryPlus:0:31: +',
  608. children = {
  609. {
  610. 'BinaryPlus:0:23: +',
  611. children = {
  612. {
  613. 'BinaryPlus:0:14: +',
  614. children = {
  615. {
  616. 'BinaryPlus:0:2: +',
  617. children = {
  618. 'Register(name=a):0:0:@a',
  619. {
  620. 'Nested:0:4: (',
  621. children = {
  622. {
  623. 'BinaryPlus:0:8: +',
  624. children = {
  625. 'Register(name=b):0:6:@b',
  626. 'Register(name=c):0:10: @c',
  627. },
  628. },
  629. },
  630. },
  631. },
  632. },
  633. {
  634. 'Call:0:19:(',
  635. children = {
  636. 'Register(name=d):0:16: @d',
  637. 'Register(name=e):0:20:@e',
  638. },
  639. },
  640. },
  641. },
  642. {
  643. 'Nested:0:25: (',
  644. children = {
  645. {
  646. 'UnaryPlus:0:27:+',
  647. children = {
  648. 'Register(name=f):0:28:@f',
  649. },
  650. },
  651. },
  652. },
  653. },
  654. },
  655. {
  656. 'Call:0:53:(',
  657. children = {
  658. {
  659. 'Nested:0:33: (',
  660. children = {
  661. {
  662. 'Call:0:48:(',
  663. children = {
  664. {
  665. 'Call:0:44:(',
  666. children = {
  667. {
  668. 'Nested:0:35:(',
  669. children = {
  670. {
  671. 'UnaryPlus:0:36:+',
  672. children = {
  673. {
  674. 'Call:0:39:(',
  675. children = {
  676. 'Register(name=g):0:37:@g',
  677. 'Register(name=h):0:40:@h',
  678. },
  679. },
  680. },
  681. },
  682. },
  683. },
  684. 'Register(name=j):0:45:@j',
  685. },
  686. },
  687. 'Register(name=k):0:49:@k',
  688. },
  689. },
  690. },
  691. },
  692. 'Register(name=l):0:54:@l',
  693. },
  694. },
  695. },
  696. },
  697. },
  698. }, {
  699. hl('Register', '@a'),
  700. hl('BinaryPlus', '+', 1),
  701. hl('NestingParenthesis', '(', 1),
  702. hl('Register', '@b'),
  703. hl('BinaryPlus', '+', 1),
  704. hl('Register', '@c', 1),
  705. hl('NestingParenthesis', ')'),
  706. hl('BinaryPlus', '+', 1),
  707. hl('Register', '@d', 1),
  708. hl('CallingParenthesis', '('),
  709. hl('Register', '@e'),
  710. hl('CallingParenthesis', ')'),
  711. hl('BinaryPlus', '+', 1),
  712. hl('NestingParenthesis', '(', 1),
  713. hl('UnaryPlus', '+'),
  714. hl('Register', '@f'),
  715. hl('NestingParenthesis', ')'),
  716. hl('BinaryPlus', '+', 1),
  717. hl('NestingParenthesis', '(', 1),
  718. hl('NestingParenthesis', '('),
  719. hl('UnaryPlus', '+'),
  720. hl('Register', '@g'),
  721. hl('CallingParenthesis', '('),
  722. hl('Register', '@h'),
  723. hl('CallingParenthesis', ')'),
  724. hl('NestingParenthesis', ')'),
  725. hl('CallingParenthesis', '('),
  726. hl('Register', '@j'),
  727. hl('CallingParenthesis', ')'),
  728. hl('CallingParenthesis', '('),
  729. hl('Register', '@k'),
  730. hl('CallingParenthesis', ')'),
  731. hl('NestingParenthesis', ')'),
  732. hl('CallingParenthesis', '('),
  733. hl('Register', '@l'),
  734. hl('CallingParenthesis', ')'),
  735. })
  736. check_parsing('@a)', {
  737. -- 012
  738. ast = {
  739. {
  740. 'Nested:0:2:',
  741. children = {
  742. 'Register(name=a):0:0:@a',
  743. },
  744. },
  745. },
  746. err = {
  747. arg = ')',
  748. msg = 'E15: Unexpected closing parenthesis: %.*s',
  749. },
  750. }, {
  751. hl('Register', '@a'),
  752. hl('InvalidNestingParenthesis', ')'),
  753. })
  754. check_parsing('(@a', {
  755. -- 012
  756. ast = {
  757. {
  758. 'Nested:0:0:(',
  759. children = {
  760. 'Register(name=a):0:1:@a',
  761. },
  762. },
  763. },
  764. err = {
  765. arg = '(@a',
  766. msg = 'E110: Missing closing parenthesis for nested expression: %.*s',
  767. },
  768. }, {
  769. hl('NestingParenthesis', '('),
  770. hl('Register', '@a'),
  771. })
  772. check_parsing('@a(@b', {
  773. -- 01234
  774. ast = {
  775. {
  776. 'Call:0:2:(',
  777. children = {
  778. 'Register(name=a):0:0:@a',
  779. 'Register(name=b):0:3:@b',
  780. },
  781. },
  782. },
  783. err = {
  784. arg = '(@b',
  785. msg = 'E116: Missing closing parenthesis for function call: %.*s',
  786. },
  787. }, {
  788. hl('Register', '@a'),
  789. hl('CallingParenthesis', '('),
  790. hl('Register', '@b'),
  791. })
  792. check_parsing('@a(@b, @c, @d, @e)', {
  793. -- 012345678901234567
  794. -- 0 1
  795. ast = {
  796. {
  797. 'Call:0:2:(',
  798. children = {
  799. 'Register(name=a):0:0:@a',
  800. {
  801. 'Comma:0:5:,',
  802. children = {
  803. 'Register(name=b):0:3:@b',
  804. {
  805. 'Comma:0:9:,',
  806. children = {
  807. 'Register(name=c):0:6: @c',
  808. {
  809. 'Comma:0:13:,',
  810. children = {
  811. 'Register(name=d):0:10: @d',
  812. 'Register(name=e):0:14: @e',
  813. },
  814. },
  815. },
  816. },
  817. },
  818. },
  819. },
  820. },
  821. },
  822. }, {
  823. hl('Register', '@a'),
  824. hl('CallingParenthesis', '('),
  825. hl('Register', '@b'),
  826. hl('Comma', ','),
  827. hl('Register', '@c', 1),
  828. hl('Comma', ','),
  829. hl('Register', '@d', 1),
  830. hl('Comma', ','),
  831. hl('Register', '@e', 1),
  832. hl('CallingParenthesis', ')'),
  833. })
  834. check_parsing('@a(@b(@c))', {
  835. -- 01234567890123456789012345678901234567
  836. -- 0 1 2 3
  837. ast = {
  838. {
  839. 'Call:0:2:(',
  840. children = {
  841. 'Register(name=a):0:0:@a',
  842. {
  843. 'Call:0:5:(',
  844. children = {
  845. 'Register(name=b):0:3:@b',
  846. 'Register(name=c):0:6:@c',
  847. },
  848. },
  849. },
  850. },
  851. },
  852. }, {
  853. hl('Register', '@a'),
  854. hl('CallingParenthesis', '('),
  855. hl('Register', '@b'),
  856. hl('CallingParenthesis', '('),
  857. hl('Register', '@c'),
  858. hl('CallingParenthesis', ')'),
  859. hl('CallingParenthesis', ')'),
  860. })
  861. check_parsing('@a(@b(@c(@d(@e), @f(@g(@h), @i(@j)))))', {
  862. -- 01234567890123456789012345678901234567
  863. -- 0 1 2 3
  864. ast = {
  865. {
  866. 'Call:0:2:(',
  867. children = {
  868. 'Register(name=a):0:0:@a',
  869. {
  870. 'Call:0:5:(',
  871. children = {
  872. 'Register(name=b):0:3:@b',
  873. {
  874. 'Call:0:8:(',
  875. children = {
  876. 'Register(name=c):0:6:@c',
  877. {
  878. 'Comma:0:15:,',
  879. children = {
  880. {
  881. 'Call:0:11:(',
  882. children = {
  883. 'Register(name=d):0:9:@d',
  884. 'Register(name=e):0:12:@e',
  885. },
  886. },
  887. {
  888. 'Call:0:19:(',
  889. children = {
  890. 'Register(name=f):0:16: @f',
  891. {
  892. 'Comma:0:26:,',
  893. children = {
  894. {
  895. 'Call:0:22:(',
  896. children = {
  897. 'Register(name=g):0:20:@g',
  898. 'Register(name=h):0:23:@h',
  899. },
  900. },
  901. {
  902. 'Call:0:30:(',
  903. children = {
  904. 'Register(name=i):0:27: @i',
  905. 'Register(name=j):0:31:@j',
  906. },
  907. },
  908. },
  909. },
  910. },
  911. },
  912. },
  913. },
  914. },
  915. },
  916. },
  917. },
  918. },
  919. },
  920. },
  921. }, {
  922. hl('Register', '@a'),
  923. hl('CallingParenthesis', '('),
  924. hl('Register', '@b'),
  925. hl('CallingParenthesis', '('),
  926. hl('Register', '@c'),
  927. hl('CallingParenthesis', '('),
  928. hl('Register', '@d'),
  929. hl('CallingParenthesis', '('),
  930. hl('Register', '@e'),
  931. hl('CallingParenthesis', ')'),
  932. hl('Comma', ','),
  933. hl('Register', '@f', 1),
  934. hl('CallingParenthesis', '('),
  935. hl('Register', '@g'),
  936. hl('CallingParenthesis', '('),
  937. hl('Register', '@h'),
  938. hl('CallingParenthesis', ')'),
  939. hl('Comma', ','),
  940. hl('Register', '@i', 1),
  941. hl('CallingParenthesis', '('),
  942. hl('Register', '@j'),
  943. hl('CallingParenthesis', ')'),
  944. hl('CallingParenthesis', ')'),
  945. hl('CallingParenthesis', ')'),
  946. hl('CallingParenthesis', ')'),
  947. hl('CallingParenthesis', ')'),
  948. })
  949. check_parsing('()()', {
  950. -- 0123
  951. ast = {
  952. {
  953. 'Call:0:2:(',
  954. children = {
  955. {
  956. 'Nested:0:0:(',
  957. children = {
  958. 'Missing:0:1:',
  959. },
  960. },
  961. },
  962. },
  963. },
  964. err = {
  965. arg = ')()',
  966. msg = 'E15: Expected value, got parenthesis: %.*s',
  967. },
  968. }, {
  969. hl('NestingParenthesis', '('),
  970. hl('InvalidNestingParenthesis', ')'),
  971. hl('CallingParenthesis', '('),
  972. hl('CallingParenthesis', ')'),
  973. })
  974. check_parsing('(@a)()', {
  975. -- 012345
  976. ast = {
  977. {
  978. 'Call:0:4:(',
  979. children = {
  980. {
  981. 'Nested:0:0:(',
  982. children = {
  983. 'Register(name=a):0:1:@a',
  984. },
  985. },
  986. },
  987. },
  988. },
  989. }, {
  990. hl('NestingParenthesis', '('),
  991. hl('Register', '@a'),
  992. hl('NestingParenthesis', ')'),
  993. hl('CallingParenthesis', '('),
  994. hl('CallingParenthesis', ')'),
  995. })
  996. check_parsing('(@a)(@b)', {
  997. -- 01234567
  998. ast = {
  999. {
  1000. 'Call:0:4:(',
  1001. children = {
  1002. {
  1003. 'Nested:0:0:(',
  1004. children = {
  1005. 'Register(name=a):0:1:@a',
  1006. },
  1007. },
  1008. 'Register(name=b):0:5:@b',
  1009. },
  1010. },
  1011. },
  1012. }, {
  1013. hl('NestingParenthesis', '('),
  1014. hl('Register', '@a'),
  1015. hl('NestingParenthesis', ')'),
  1016. hl('CallingParenthesis', '('),
  1017. hl('Register', '@b'),
  1018. hl('CallingParenthesis', ')'),
  1019. })
  1020. check_parsing('(@a) (@b)', {
  1021. -- 012345678
  1022. ast = {
  1023. {
  1024. 'OpMissing:0:4:',
  1025. children = {
  1026. {
  1027. 'Nested:0:0:(',
  1028. children = {
  1029. 'Register(name=a):0:1:@a',
  1030. },
  1031. },
  1032. {
  1033. 'Nested:0:4: (',
  1034. children = {
  1035. 'Register(name=b):0:6:@b',
  1036. },
  1037. },
  1038. },
  1039. },
  1040. },
  1041. err = {
  1042. arg = '(@b)',
  1043. msg = 'E15: Missing operator: %.*s',
  1044. },
  1045. }, {
  1046. hl('NestingParenthesis', '('),
  1047. hl('Register', '@a'),
  1048. hl('NestingParenthesis', ')'),
  1049. hl('InvalidSpacing', ' '),
  1050. hl('NestingParenthesis', '('),
  1051. hl('Register', '@b'),
  1052. hl('NestingParenthesis', ')'),
  1053. }, {
  1054. [1] = {
  1055. ast = {
  1056. len = 5,
  1057. ast = {
  1058. {
  1059. 'Nested:0:0:(',
  1060. children = {
  1061. 'Register(name=a):0:1:@a',
  1062. REMOVE_THIS,
  1063. },
  1064. },
  1065. },
  1066. err = REMOVE_THIS,
  1067. },
  1068. hl_fs = {
  1069. [4] = REMOVE_THIS,
  1070. [5] = REMOVE_THIS,
  1071. [6] = REMOVE_THIS,
  1072. [7] = REMOVE_THIS,
  1073. },
  1074. },
  1075. })
  1076. end)
  1077. itp('works with variable names, including curly braces ones', function()
  1078. check_parsing('var', {
  1079. ast = {
  1080. 'PlainIdentifier(scope=0,ident=var):0:0:var',
  1081. },
  1082. }, {
  1083. hl('IdentifierName', 'var'),
  1084. })
  1085. check_parsing('g:var', {
  1086. ast = {
  1087. 'PlainIdentifier(scope=g,ident=var):0:0:g:var',
  1088. },
  1089. }, {
  1090. hl('IdentifierScope', 'g'),
  1091. hl('IdentifierScopeDelimiter', ':'),
  1092. hl('IdentifierName', 'var'),
  1093. })
  1094. check_parsing('g:', {
  1095. ast = {
  1096. 'PlainIdentifier(scope=g,ident=):0:0:g:',
  1097. },
  1098. }, {
  1099. hl('IdentifierScope', 'g'),
  1100. hl('IdentifierScopeDelimiter', ':'),
  1101. })
  1102. check_parsing('{a}', {
  1103. -- 012
  1104. ast = {
  1105. {
  1106. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  1107. children = {
  1108. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  1109. },
  1110. },
  1111. },
  1112. }, {
  1113. hl('Curly', '{'),
  1114. hl('IdentifierName', 'a'),
  1115. hl('Curly', '}'),
  1116. })
  1117. check_parsing('{a:b}', {
  1118. -- 012
  1119. ast = {
  1120. {
  1121. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  1122. children = {
  1123. 'PlainIdentifier(scope=a,ident=b):0:1:a:b',
  1124. },
  1125. },
  1126. },
  1127. }, {
  1128. hl('Curly', '{'),
  1129. hl('IdentifierScope', 'a'),
  1130. hl('IdentifierScopeDelimiter', ':'),
  1131. hl('IdentifierName', 'b'),
  1132. hl('Curly', '}'),
  1133. })
  1134. check_parsing('{a:@b}', {
  1135. -- 012345
  1136. ast = {
  1137. {
  1138. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  1139. children = {
  1140. {
  1141. 'OpMissing:0:3:',
  1142. children = {
  1143. 'PlainIdentifier(scope=a,ident=):0:1:a:',
  1144. 'Register(name=b):0:3:@b',
  1145. },
  1146. },
  1147. },
  1148. },
  1149. },
  1150. err = {
  1151. arg = '@b}',
  1152. msg = 'E15: Missing operator: %.*s',
  1153. },
  1154. }, {
  1155. hl('Curly', '{'),
  1156. hl('IdentifierScope', 'a'),
  1157. hl('IdentifierScopeDelimiter', ':'),
  1158. hl('InvalidRegister', '@b'),
  1159. hl('Curly', '}'),
  1160. })
  1161. check_parsing('{@a}', {
  1162. ast = {
  1163. {
  1164. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  1165. children = {
  1166. 'Register(name=a):0:1:@a',
  1167. },
  1168. },
  1169. },
  1170. }, {
  1171. hl('Curly', '{'),
  1172. hl('Register', '@a'),
  1173. hl('Curly', '}'),
  1174. })
  1175. check_parsing('{@a}{@b}', {
  1176. -- 01234567
  1177. ast = {
  1178. {
  1179. 'ComplexIdentifier:0:4:',
  1180. children = {
  1181. {
  1182. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  1183. children = {
  1184. 'Register(name=a):0:1:@a',
  1185. },
  1186. },
  1187. {
  1188. fmtn('CurlyBracesIdentifier', '--i', ':0:4:{'),
  1189. children = {
  1190. 'Register(name=b):0:5:@b',
  1191. },
  1192. },
  1193. },
  1194. },
  1195. },
  1196. }, {
  1197. hl('Curly', '{'),
  1198. hl('Register', '@a'),
  1199. hl('Curly', '}'),
  1200. hl('Curly', '{'),
  1201. hl('Register', '@b'),
  1202. hl('Curly', '}'),
  1203. })
  1204. check_parsing('g:{@a}', {
  1205. -- 01234567
  1206. ast = {
  1207. {
  1208. 'ComplexIdentifier:0:2:',
  1209. children = {
  1210. 'PlainIdentifier(scope=g,ident=):0:0:g:',
  1211. {
  1212. fmtn('CurlyBracesIdentifier', '--i', ':0:2:{'),
  1213. children = {
  1214. 'Register(name=a):0:3:@a',
  1215. },
  1216. },
  1217. },
  1218. },
  1219. },
  1220. }, {
  1221. hl('IdentifierScope', 'g'),
  1222. hl('IdentifierScopeDelimiter', ':'),
  1223. hl('Curly', '{'),
  1224. hl('Register', '@a'),
  1225. hl('Curly', '}'),
  1226. })
  1227. check_parsing('{@a}_test', {
  1228. -- 012345678
  1229. ast = {
  1230. {
  1231. 'ComplexIdentifier:0:4:',
  1232. children = {
  1233. {
  1234. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  1235. children = {
  1236. 'Register(name=a):0:1:@a',
  1237. },
  1238. },
  1239. 'PlainIdentifier(scope=0,ident=_test):0:4:_test',
  1240. },
  1241. },
  1242. },
  1243. }, {
  1244. hl('Curly', '{'),
  1245. hl('Register', '@a'),
  1246. hl('Curly', '}'),
  1247. hl('IdentifierName', '_test'),
  1248. })
  1249. check_parsing('g:{@a}_test', {
  1250. -- 01234567890
  1251. ast = {
  1252. {
  1253. 'ComplexIdentifier:0:2:',
  1254. children = {
  1255. 'PlainIdentifier(scope=g,ident=):0:0:g:',
  1256. {
  1257. 'ComplexIdentifier:0:6:',
  1258. children = {
  1259. {
  1260. fmtn('CurlyBracesIdentifier', '--i', ':0:2:{'),
  1261. children = {
  1262. 'Register(name=a):0:3:@a',
  1263. },
  1264. },
  1265. 'PlainIdentifier(scope=0,ident=_test):0:6:_test',
  1266. },
  1267. },
  1268. },
  1269. },
  1270. },
  1271. }, {
  1272. hl('IdentifierScope', 'g'),
  1273. hl('IdentifierScopeDelimiter', ':'),
  1274. hl('Curly', '{'),
  1275. hl('Register', '@a'),
  1276. hl('Curly', '}'),
  1277. hl('IdentifierName', '_test'),
  1278. })
  1279. check_parsing('g:{@a}_test()', {
  1280. -- 0123456789012
  1281. ast = {
  1282. {
  1283. 'Call:0:11:(',
  1284. children = {
  1285. {
  1286. 'ComplexIdentifier:0:2:',
  1287. children = {
  1288. 'PlainIdentifier(scope=g,ident=):0:0:g:',
  1289. {
  1290. 'ComplexIdentifier:0:6:',
  1291. children = {
  1292. {
  1293. fmtn('CurlyBracesIdentifier', '--i', ':0:2:{'),
  1294. children = {
  1295. 'Register(name=a):0:3:@a',
  1296. },
  1297. },
  1298. 'PlainIdentifier(scope=0,ident=_test):0:6:_test',
  1299. },
  1300. },
  1301. },
  1302. },
  1303. },
  1304. },
  1305. },
  1306. }, {
  1307. hl('IdentifierScope', 'g'),
  1308. hl('IdentifierScopeDelimiter', ':'),
  1309. hl('Curly', '{'),
  1310. hl('Register', '@a'),
  1311. hl('Curly', '}'),
  1312. hl('IdentifierName', '_test'),
  1313. hl('CallingParenthesis', '('),
  1314. hl('CallingParenthesis', ')'),
  1315. })
  1316. check_parsing('{@a} ()', {
  1317. -- 0123456789012
  1318. ast = {
  1319. {
  1320. 'Call:0:4: (',
  1321. children = {
  1322. {
  1323. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  1324. children = {
  1325. 'Register(name=a):0:1:@a',
  1326. },
  1327. },
  1328. },
  1329. },
  1330. },
  1331. }, {
  1332. hl('Curly', '{'),
  1333. hl('Register', '@a'),
  1334. hl('Curly', '}'),
  1335. hl('CallingParenthesis', '(', 1),
  1336. hl('CallingParenthesis', ')'),
  1337. })
  1338. check_parsing('g:{@a} ()', {
  1339. -- 0123456789012
  1340. ast = {
  1341. {
  1342. 'Call:0:6: (',
  1343. children = {
  1344. {
  1345. 'ComplexIdentifier:0:2:',
  1346. children = {
  1347. 'PlainIdentifier(scope=g,ident=):0:0:g:',
  1348. {
  1349. fmtn('CurlyBracesIdentifier', '--i', ':0:2:{'),
  1350. children = {
  1351. 'Register(name=a):0:3:@a',
  1352. },
  1353. },
  1354. },
  1355. },
  1356. },
  1357. },
  1358. },
  1359. }, {
  1360. hl('IdentifierScope', 'g'),
  1361. hl('IdentifierScopeDelimiter', ':'),
  1362. hl('Curly', '{'),
  1363. hl('Register', '@a'),
  1364. hl('Curly', '}'),
  1365. hl('CallingParenthesis', '(', 1),
  1366. hl('CallingParenthesis', ')'),
  1367. })
  1368. check_parsing('{@a', {
  1369. -- 012
  1370. ast = {
  1371. {
  1372. fmtn('UnknownFigure', '-di', ':0:0:{'),
  1373. children = {
  1374. 'Register(name=a):0:1:@a',
  1375. },
  1376. },
  1377. },
  1378. err = {
  1379. arg = '{@a',
  1380. msg = 'E15: Missing closing figure brace: %.*s',
  1381. },
  1382. }, {
  1383. hl('FigureBrace', '{'),
  1384. hl('Register', '@a'),
  1385. })
  1386. check_parsing('a ()', {
  1387. -- 0123
  1388. ast = {
  1389. {
  1390. 'Call:0:1: (',
  1391. children = {
  1392. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  1393. },
  1394. },
  1395. },
  1396. }, {
  1397. hl('IdentifierName', 'a'),
  1398. hl('CallingParenthesis', '(', 1),
  1399. hl('CallingParenthesis', ')'),
  1400. })
  1401. end)
  1402. itp('works with lambdas and dictionaries', function()
  1403. check_parsing('{}', {
  1404. ast = {
  1405. fmtn('DictLiteral', '-di', ':0:0:{'),
  1406. },
  1407. }, {
  1408. hl('Dict', '{'),
  1409. hl('Dict', '}'),
  1410. })
  1411. check_parsing('{->@a}', {
  1412. ast = {
  1413. {
  1414. fmtn('Lambda', '\\di', ':0:0:{'),
  1415. children = {
  1416. {
  1417. 'Arrow:0:1:->',
  1418. children = {
  1419. 'Register(name=a):0:3:@a',
  1420. },
  1421. },
  1422. },
  1423. },
  1424. },
  1425. }, {
  1426. hl('Lambda', '{'),
  1427. hl('Arrow', '->'),
  1428. hl('Register', '@a'),
  1429. hl('Lambda', '}'),
  1430. })
  1431. check_parsing('{->@a+@b}', {
  1432. -- 012345678
  1433. ast = {
  1434. {
  1435. fmtn('Lambda', '\\di', ':0:0:{'),
  1436. children = {
  1437. {
  1438. 'Arrow:0:1:->',
  1439. children = {
  1440. {
  1441. 'BinaryPlus:0:5:+',
  1442. children = {
  1443. 'Register(name=a):0:3:@a',
  1444. 'Register(name=b):0:6:@b',
  1445. },
  1446. },
  1447. },
  1448. },
  1449. },
  1450. },
  1451. },
  1452. }, {
  1453. hl('Lambda', '{'),
  1454. hl('Arrow', '->'),
  1455. hl('Register', '@a'),
  1456. hl('BinaryPlus', '+'),
  1457. hl('Register', '@b'),
  1458. hl('Lambda', '}'),
  1459. })
  1460. check_parsing('{a->@a}', {
  1461. -- 012345678
  1462. ast = {
  1463. {
  1464. fmtn('Lambda', '\\di', ':0:0:{'),
  1465. children = {
  1466. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  1467. {
  1468. 'Arrow:0:2:->',
  1469. children = {
  1470. 'Register(name=a):0:4:@a',
  1471. },
  1472. },
  1473. },
  1474. },
  1475. },
  1476. }, {
  1477. hl('Lambda', '{'),
  1478. hl('IdentifierName', 'a'),
  1479. hl('Arrow', '->'),
  1480. hl('Register', '@a'),
  1481. hl('Lambda', '}'),
  1482. })
  1483. check_parsing('{a,b->@a}', {
  1484. -- 012345678
  1485. ast = {
  1486. {
  1487. fmtn('Lambda', '\\di', ':0:0:{'),
  1488. children = {
  1489. {
  1490. 'Comma:0:2:,',
  1491. children = {
  1492. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  1493. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  1494. },
  1495. },
  1496. {
  1497. 'Arrow:0:4:->',
  1498. children = {
  1499. 'Register(name=a):0:6:@a',
  1500. },
  1501. },
  1502. },
  1503. },
  1504. },
  1505. }, {
  1506. hl('Lambda', '{'),
  1507. hl('IdentifierName', 'a'),
  1508. hl('Comma', ','),
  1509. hl('IdentifierName', 'b'),
  1510. hl('Arrow', '->'),
  1511. hl('Register', '@a'),
  1512. hl('Lambda', '}'),
  1513. })
  1514. check_parsing('{a,b,c->@a}', {
  1515. -- 01234567890
  1516. ast = {
  1517. {
  1518. fmtn('Lambda', '\\di', ':0:0:{'),
  1519. children = {
  1520. {
  1521. 'Comma:0:2:,',
  1522. children = {
  1523. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  1524. {
  1525. 'Comma:0:4:,',
  1526. children = {
  1527. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  1528. 'PlainIdentifier(scope=0,ident=c):0:5:c',
  1529. },
  1530. },
  1531. },
  1532. },
  1533. {
  1534. 'Arrow:0:6:->',
  1535. children = {
  1536. 'Register(name=a):0:8:@a',
  1537. },
  1538. },
  1539. },
  1540. },
  1541. },
  1542. }, {
  1543. hl('Lambda', '{'),
  1544. hl('IdentifierName', 'a'),
  1545. hl('Comma', ','),
  1546. hl('IdentifierName', 'b'),
  1547. hl('Comma', ','),
  1548. hl('IdentifierName', 'c'),
  1549. hl('Arrow', '->'),
  1550. hl('Register', '@a'),
  1551. hl('Lambda', '}'),
  1552. })
  1553. check_parsing('{a,b,c,d->@a}', {
  1554. -- 0123456789012
  1555. ast = {
  1556. {
  1557. fmtn('Lambda', '\\di', ':0:0:{'),
  1558. children = {
  1559. {
  1560. 'Comma:0:2:,',
  1561. children = {
  1562. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  1563. {
  1564. 'Comma:0:4:,',
  1565. children = {
  1566. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  1567. {
  1568. 'Comma:0:6:,',
  1569. children = {
  1570. 'PlainIdentifier(scope=0,ident=c):0:5:c',
  1571. 'PlainIdentifier(scope=0,ident=d):0:7:d',
  1572. },
  1573. },
  1574. },
  1575. },
  1576. },
  1577. },
  1578. {
  1579. 'Arrow:0:8:->',
  1580. children = {
  1581. 'Register(name=a):0:10:@a',
  1582. },
  1583. },
  1584. },
  1585. },
  1586. },
  1587. }, {
  1588. hl('Lambda', '{'),
  1589. hl('IdentifierName', 'a'),
  1590. hl('Comma', ','),
  1591. hl('IdentifierName', 'b'),
  1592. hl('Comma', ','),
  1593. hl('IdentifierName', 'c'),
  1594. hl('Comma', ','),
  1595. hl('IdentifierName', 'd'),
  1596. hl('Arrow', '->'),
  1597. hl('Register', '@a'),
  1598. hl('Lambda', '}'),
  1599. })
  1600. check_parsing('{a,b,c,d,->@a}', {
  1601. -- 01234567890123
  1602. ast = {
  1603. {
  1604. fmtn('Lambda', '\\di', ':0:0:{'),
  1605. children = {
  1606. {
  1607. 'Comma:0:2:,',
  1608. children = {
  1609. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  1610. {
  1611. 'Comma:0:4:,',
  1612. children = {
  1613. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  1614. {
  1615. 'Comma:0:6:,',
  1616. children = {
  1617. 'PlainIdentifier(scope=0,ident=c):0:5:c',
  1618. {
  1619. 'Comma:0:8:,',
  1620. children = {
  1621. 'PlainIdentifier(scope=0,ident=d):0:7:d',
  1622. },
  1623. },
  1624. },
  1625. },
  1626. },
  1627. },
  1628. },
  1629. },
  1630. {
  1631. 'Arrow:0:9:->',
  1632. children = {
  1633. 'Register(name=a):0:11:@a',
  1634. },
  1635. },
  1636. },
  1637. },
  1638. },
  1639. }, {
  1640. hl('Lambda', '{'),
  1641. hl('IdentifierName', 'a'),
  1642. hl('Comma', ','),
  1643. hl('IdentifierName', 'b'),
  1644. hl('Comma', ','),
  1645. hl('IdentifierName', 'c'),
  1646. hl('Comma', ','),
  1647. hl('IdentifierName', 'd'),
  1648. hl('Comma', ','),
  1649. hl('Arrow', '->'),
  1650. hl('Register', '@a'),
  1651. hl('Lambda', '}'),
  1652. })
  1653. check_parsing('{a,b->{c,d->{e,f->@a}}}', {
  1654. -- 01234567890123456789012
  1655. -- 0 1 2
  1656. ast = {
  1657. {
  1658. fmtn('Lambda', '\\di', ':0:0:{'),
  1659. children = {
  1660. {
  1661. 'Comma:0:2:,',
  1662. children = {
  1663. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  1664. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  1665. },
  1666. },
  1667. {
  1668. 'Arrow:0:4:->',
  1669. children = {
  1670. {
  1671. fmtn('Lambda', '\\di', ':0:6:{'),
  1672. children = {
  1673. {
  1674. 'Comma:0:8:,',
  1675. children = {
  1676. 'PlainIdentifier(scope=0,ident=c):0:7:c',
  1677. 'PlainIdentifier(scope=0,ident=d):0:9:d',
  1678. },
  1679. },
  1680. {
  1681. 'Arrow:0:10:->',
  1682. children = {
  1683. {
  1684. fmtn('Lambda', '\\di', ':0:12:{'),
  1685. children = {
  1686. {
  1687. 'Comma:0:14:,',
  1688. children = {
  1689. 'PlainIdentifier(scope=0,ident=e):0:13:e',
  1690. 'PlainIdentifier(scope=0,ident=f):0:15:f',
  1691. },
  1692. },
  1693. {
  1694. 'Arrow:0:16:->',
  1695. children = {
  1696. 'Register(name=a):0:18:@a',
  1697. },
  1698. },
  1699. },
  1700. },
  1701. },
  1702. },
  1703. },
  1704. },
  1705. },
  1706. },
  1707. },
  1708. },
  1709. },
  1710. }, {
  1711. hl('Lambda', '{'),
  1712. hl('IdentifierName', 'a'),
  1713. hl('Comma', ','),
  1714. hl('IdentifierName', 'b'),
  1715. hl('Arrow', '->'),
  1716. hl('Lambda', '{'),
  1717. hl('IdentifierName', 'c'),
  1718. hl('Comma', ','),
  1719. hl('IdentifierName', 'd'),
  1720. hl('Arrow', '->'),
  1721. hl('Lambda', '{'),
  1722. hl('IdentifierName', 'e'),
  1723. hl('Comma', ','),
  1724. hl('IdentifierName', 'f'),
  1725. hl('Arrow', '->'),
  1726. hl('Register', '@a'),
  1727. hl('Lambda', '}'),
  1728. hl('Lambda', '}'),
  1729. hl('Lambda', '}'),
  1730. })
  1731. check_parsing('{a,b->c,d}', {
  1732. -- 0123456789
  1733. ast = {
  1734. {
  1735. fmtn('Lambda', '\\di', ':0:0:{'),
  1736. children = {
  1737. {
  1738. 'Comma:0:2:,',
  1739. children = {
  1740. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  1741. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  1742. },
  1743. },
  1744. {
  1745. 'Arrow:0:4:->',
  1746. children = {
  1747. {
  1748. 'Comma:0:7:,',
  1749. children = {
  1750. 'PlainIdentifier(scope=0,ident=c):0:6:c',
  1751. 'PlainIdentifier(scope=0,ident=d):0:8:d',
  1752. },
  1753. },
  1754. },
  1755. },
  1756. },
  1757. },
  1758. },
  1759. err = {
  1760. arg = ',d}',
  1761. msg = 'E15: Comma outside of call, lambda or literal: %.*s',
  1762. },
  1763. }, {
  1764. hl('Lambda', '{'),
  1765. hl('IdentifierName', 'a'),
  1766. hl('Comma', ','),
  1767. hl('IdentifierName', 'b'),
  1768. hl('Arrow', '->'),
  1769. hl('IdentifierName', 'c'),
  1770. hl('InvalidComma', ','),
  1771. hl('IdentifierName', 'd'),
  1772. hl('Lambda', '}'),
  1773. })
  1774. check_parsing('a,b,c,d', {
  1775. -- 0123456789
  1776. ast = {
  1777. {
  1778. 'Comma:0:1:,',
  1779. children = {
  1780. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  1781. {
  1782. 'Comma:0:3:,',
  1783. children = {
  1784. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  1785. {
  1786. 'Comma:0:5:,',
  1787. children = {
  1788. 'PlainIdentifier(scope=0,ident=c):0:4:c',
  1789. 'PlainIdentifier(scope=0,ident=d):0:6:d',
  1790. },
  1791. },
  1792. },
  1793. },
  1794. },
  1795. },
  1796. },
  1797. err = {
  1798. arg = ',b,c,d',
  1799. msg = 'E15: Comma outside of call, lambda or literal: %.*s',
  1800. },
  1801. }, {
  1802. hl('IdentifierName', 'a'),
  1803. hl('InvalidComma', ','),
  1804. hl('IdentifierName', 'b'),
  1805. hl('InvalidComma', ','),
  1806. hl('IdentifierName', 'c'),
  1807. hl('InvalidComma', ','),
  1808. hl('IdentifierName', 'd'),
  1809. })
  1810. check_parsing('a,b,c,d,', {
  1811. -- 0123456789
  1812. ast = {
  1813. {
  1814. 'Comma:0:1:,',
  1815. children = {
  1816. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  1817. {
  1818. 'Comma:0:3:,',
  1819. children = {
  1820. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  1821. {
  1822. 'Comma:0:5:,',
  1823. children = {
  1824. 'PlainIdentifier(scope=0,ident=c):0:4:c',
  1825. {
  1826. 'Comma:0:7:,',
  1827. children = {
  1828. 'PlainIdentifier(scope=0,ident=d):0:6:d',
  1829. },
  1830. },
  1831. },
  1832. },
  1833. },
  1834. },
  1835. },
  1836. },
  1837. },
  1838. err = {
  1839. arg = ',b,c,d,',
  1840. msg = 'E15: Comma outside of call, lambda or literal: %.*s',
  1841. },
  1842. }, {
  1843. hl('IdentifierName', 'a'),
  1844. hl('InvalidComma', ','),
  1845. hl('IdentifierName', 'b'),
  1846. hl('InvalidComma', ','),
  1847. hl('IdentifierName', 'c'),
  1848. hl('InvalidComma', ','),
  1849. hl('IdentifierName', 'd'),
  1850. hl('InvalidComma', ','),
  1851. })
  1852. check_parsing(',', {
  1853. -- 0123456789
  1854. ast = {
  1855. {
  1856. 'Comma:0:0:,',
  1857. children = {
  1858. 'Missing:0:0:',
  1859. },
  1860. },
  1861. },
  1862. err = {
  1863. arg = ',',
  1864. msg = 'E15: Expected value, got comma: %.*s',
  1865. },
  1866. }, {
  1867. hl('InvalidComma', ','),
  1868. })
  1869. check_parsing('{,a->@a}', {
  1870. -- 0123456789
  1871. ast = {
  1872. {
  1873. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  1874. children = {
  1875. {
  1876. 'Arrow:0:3:->',
  1877. children = {
  1878. {
  1879. 'Comma:0:1:,',
  1880. children = {
  1881. 'Missing:0:1:',
  1882. 'PlainIdentifier(scope=0,ident=a):0:2:a',
  1883. },
  1884. },
  1885. 'Register(name=a):0:5:@a',
  1886. },
  1887. },
  1888. },
  1889. },
  1890. },
  1891. err = {
  1892. arg = ',a->@a}',
  1893. msg = 'E15: Expected value, got comma: %.*s',
  1894. },
  1895. }, {
  1896. hl('Curly', '{'),
  1897. hl('InvalidComma', ','),
  1898. hl('IdentifierName', 'a'),
  1899. hl('InvalidArrow', '->'),
  1900. hl('Register', '@a'),
  1901. hl('Curly', '}'),
  1902. })
  1903. check_parsing('}', {
  1904. -- 0123456789
  1905. ast = {
  1906. fmtn('UnknownFigure', '---', ':0:0:'),
  1907. },
  1908. err = {
  1909. arg = '}',
  1910. msg = 'E15: Unexpected closing figure brace: %.*s',
  1911. },
  1912. }, {
  1913. hl('InvalidFigureBrace', '}'),
  1914. })
  1915. check_parsing('{->}', {
  1916. -- 0123456789
  1917. ast = {
  1918. {
  1919. fmtn('Lambda', '\\di', ':0:0:{'),
  1920. children = {
  1921. 'Arrow:0:1:->',
  1922. },
  1923. },
  1924. },
  1925. err = {
  1926. arg = '}',
  1927. msg = 'E15: Expected value, got closing figure brace: %.*s',
  1928. },
  1929. }, {
  1930. hl('Lambda', '{'),
  1931. hl('Arrow', '->'),
  1932. hl('InvalidLambda', '}'),
  1933. })
  1934. check_parsing('{a,b}', {
  1935. -- 0123456789
  1936. ast = {
  1937. {
  1938. fmtn('Lambda', '-di', ':0:0:{'),
  1939. children = {
  1940. {
  1941. 'Comma:0:2:,',
  1942. children = {
  1943. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  1944. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  1945. },
  1946. },
  1947. },
  1948. },
  1949. },
  1950. err = {
  1951. arg = '}',
  1952. msg = 'E15: Expected lambda arguments list or arrow: %.*s',
  1953. },
  1954. }, {
  1955. hl('Lambda', '{'),
  1956. hl('IdentifierName', 'a'),
  1957. hl('Comma', ','),
  1958. hl('IdentifierName', 'b'),
  1959. hl('InvalidLambda', '}'),
  1960. })
  1961. check_parsing('{a,}', {
  1962. -- 0123456789
  1963. ast = {
  1964. {
  1965. fmtn('Lambda', '-di', ':0:0:{'),
  1966. children = {
  1967. {
  1968. 'Comma:0:2:,',
  1969. children = {
  1970. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  1971. },
  1972. },
  1973. },
  1974. },
  1975. },
  1976. err = {
  1977. arg = '}',
  1978. msg = 'E15: Expected lambda arguments list or arrow: %.*s',
  1979. },
  1980. }, {
  1981. hl('Lambda', '{'),
  1982. hl('IdentifierName', 'a'),
  1983. hl('Comma', ','),
  1984. hl('InvalidLambda', '}'),
  1985. })
  1986. check_parsing('{@a:@b}', {
  1987. -- 0123456789
  1988. ast = {
  1989. {
  1990. fmtn('DictLiteral', '-di', ':0:0:{'),
  1991. children = {
  1992. {
  1993. 'Colon:0:3::',
  1994. children = {
  1995. 'Register(name=a):0:1:@a',
  1996. 'Register(name=b):0:4:@b',
  1997. },
  1998. },
  1999. },
  2000. },
  2001. },
  2002. }, {
  2003. hl('Dict', '{'),
  2004. hl('Register', '@a'),
  2005. hl('Colon', ':'),
  2006. hl('Register', '@b'),
  2007. hl('Dict', '}'),
  2008. })
  2009. check_parsing('{@a:@b,@c:@d}', {
  2010. -- 0123456789012
  2011. -- 0 1
  2012. ast = {
  2013. {
  2014. fmtn('DictLiteral', '-di', ':0:0:{'),
  2015. children = {
  2016. {
  2017. 'Comma:0:6:,',
  2018. children = {
  2019. {
  2020. 'Colon:0:3::',
  2021. children = {
  2022. 'Register(name=a):0:1:@a',
  2023. 'Register(name=b):0:4:@b',
  2024. },
  2025. },
  2026. {
  2027. 'Colon:0:9::',
  2028. children = {
  2029. 'Register(name=c):0:7:@c',
  2030. 'Register(name=d):0:10:@d',
  2031. },
  2032. },
  2033. },
  2034. },
  2035. },
  2036. },
  2037. },
  2038. }, {
  2039. hl('Dict', '{'),
  2040. hl('Register', '@a'),
  2041. hl('Colon', ':'),
  2042. hl('Register', '@b'),
  2043. hl('Comma', ','),
  2044. hl('Register', '@c'),
  2045. hl('Colon', ':'),
  2046. hl('Register', '@d'),
  2047. hl('Dict', '}'),
  2048. })
  2049. check_parsing('{@a:@b,@c:@d,@e:@f,}', {
  2050. -- 01234567890123456789
  2051. -- 0 1
  2052. ast = {
  2053. {
  2054. fmtn('DictLiteral', '-di', ':0:0:{'),
  2055. children = {
  2056. {
  2057. 'Comma:0:6:,',
  2058. children = {
  2059. {
  2060. 'Colon:0:3::',
  2061. children = {
  2062. 'Register(name=a):0:1:@a',
  2063. 'Register(name=b):0:4:@b',
  2064. },
  2065. },
  2066. {
  2067. 'Comma:0:12:,',
  2068. children = {
  2069. {
  2070. 'Colon:0:9::',
  2071. children = {
  2072. 'Register(name=c):0:7:@c',
  2073. 'Register(name=d):0:10:@d',
  2074. },
  2075. },
  2076. {
  2077. 'Comma:0:18:,',
  2078. children = {
  2079. {
  2080. 'Colon:0:15::',
  2081. children = {
  2082. 'Register(name=e):0:13:@e',
  2083. 'Register(name=f):0:16:@f',
  2084. },
  2085. },
  2086. },
  2087. },
  2088. },
  2089. },
  2090. },
  2091. },
  2092. },
  2093. },
  2094. },
  2095. }, {
  2096. hl('Dict', '{'),
  2097. hl('Register', '@a'),
  2098. hl('Colon', ':'),
  2099. hl('Register', '@b'),
  2100. hl('Comma', ','),
  2101. hl('Register', '@c'),
  2102. hl('Colon', ':'),
  2103. hl('Register', '@d'),
  2104. hl('Comma', ','),
  2105. hl('Register', '@e'),
  2106. hl('Colon', ':'),
  2107. hl('Register', '@f'),
  2108. hl('Comma', ','),
  2109. hl('Dict', '}'),
  2110. })
  2111. check_parsing('{@a:@b,@c:@d,@e:@f,@g:}', {
  2112. -- 01234567890123456789012
  2113. -- 0 1 2
  2114. ast = {
  2115. {
  2116. fmtn('DictLiteral', '-di', ':0:0:{'),
  2117. children = {
  2118. {
  2119. 'Comma:0:6:,',
  2120. children = {
  2121. {
  2122. 'Colon:0:3::',
  2123. children = {
  2124. 'Register(name=a):0:1:@a',
  2125. 'Register(name=b):0:4:@b',
  2126. },
  2127. },
  2128. {
  2129. 'Comma:0:12:,',
  2130. children = {
  2131. {
  2132. 'Colon:0:9::',
  2133. children = {
  2134. 'Register(name=c):0:7:@c',
  2135. 'Register(name=d):0:10:@d',
  2136. },
  2137. },
  2138. {
  2139. 'Comma:0:18:,',
  2140. children = {
  2141. {
  2142. 'Colon:0:15::',
  2143. children = {
  2144. 'Register(name=e):0:13:@e',
  2145. 'Register(name=f):0:16:@f',
  2146. },
  2147. },
  2148. {
  2149. 'Colon:0:21::',
  2150. children = {
  2151. 'Register(name=g):0:19:@g',
  2152. },
  2153. },
  2154. },
  2155. },
  2156. },
  2157. },
  2158. },
  2159. },
  2160. },
  2161. },
  2162. },
  2163. err = {
  2164. arg = '}',
  2165. msg = 'E15: Expected value, got closing figure brace: %.*s',
  2166. },
  2167. }, {
  2168. hl('Dict', '{'),
  2169. hl('Register', '@a'),
  2170. hl('Colon', ':'),
  2171. hl('Register', '@b'),
  2172. hl('Comma', ','),
  2173. hl('Register', '@c'),
  2174. hl('Colon', ':'),
  2175. hl('Register', '@d'),
  2176. hl('Comma', ','),
  2177. hl('Register', '@e'),
  2178. hl('Colon', ':'),
  2179. hl('Register', '@f'),
  2180. hl('Comma', ','),
  2181. hl('Register', '@g'),
  2182. hl('Colon', ':'),
  2183. hl('InvalidDict', '}'),
  2184. })
  2185. check_parsing('{@a:@b,}', {
  2186. -- 01234567890123
  2187. -- 0 1
  2188. ast = {
  2189. {
  2190. fmtn('DictLiteral', '-di', ':0:0:{'),
  2191. children = {
  2192. {
  2193. 'Comma:0:6:,',
  2194. children = {
  2195. {
  2196. 'Colon:0:3::',
  2197. children = {
  2198. 'Register(name=a):0:1:@a',
  2199. 'Register(name=b):0:4:@b',
  2200. },
  2201. },
  2202. },
  2203. },
  2204. },
  2205. },
  2206. },
  2207. }, {
  2208. hl('Dict', '{'),
  2209. hl('Register', '@a'),
  2210. hl('Colon', ':'),
  2211. hl('Register', '@b'),
  2212. hl('Comma', ','),
  2213. hl('Dict', '}'),
  2214. })
  2215. check_parsing('{({f -> g})(@h)(@i)}', {
  2216. -- 01234567890123456789
  2217. -- 0 1
  2218. ast = {
  2219. {
  2220. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  2221. children = {
  2222. {
  2223. 'Call:0:15:(',
  2224. children = {
  2225. {
  2226. 'Call:0:11:(',
  2227. children = {
  2228. {
  2229. 'Nested:0:1:(',
  2230. children = {
  2231. {
  2232. fmtn('Lambda', '\\di', ':0:2:{'),
  2233. children = {
  2234. 'PlainIdentifier(scope=0,ident=f):0:3:f',
  2235. {
  2236. 'Arrow:0:4: ->',
  2237. children = {
  2238. 'PlainIdentifier(scope=0,ident=g):0:7: g',
  2239. },
  2240. },
  2241. },
  2242. },
  2243. },
  2244. },
  2245. 'Register(name=h):0:12:@h',
  2246. },
  2247. },
  2248. 'Register(name=i):0:16:@i',
  2249. },
  2250. },
  2251. },
  2252. },
  2253. },
  2254. }, {
  2255. hl('Curly', '{'),
  2256. hl('NestingParenthesis', '('),
  2257. hl('Lambda', '{'),
  2258. hl('IdentifierName', 'f'),
  2259. hl('Arrow', '->', 1),
  2260. hl('IdentifierName', 'g', 1),
  2261. hl('Lambda', '}'),
  2262. hl('NestingParenthesis', ')'),
  2263. hl('CallingParenthesis', '('),
  2264. hl('Register', '@h'),
  2265. hl('CallingParenthesis', ')'),
  2266. hl('CallingParenthesis', '('),
  2267. hl('Register', '@i'),
  2268. hl('CallingParenthesis', ')'),
  2269. hl('Curly', '}'),
  2270. })
  2271. check_parsing('a:{b()}c', {
  2272. -- 01234567
  2273. ast = {
  2274. {
  2275. 'ComplexIdentifier:0:2:',
  2276. children = {
  2277. 'PlainIdentifier(scope=a,ident=):0:0:a:',
  2278. {
  2279. 'ComplexIdentifier:0:7:',
  2280. children = {
  2281. {
  2282. fmtn('CurlyBracesIdentifier', '--i', ':0:2:{'),
  2283. children = {
  2284. {
  2285. 'Call:0:4:(',
  2286. children = {
  2287. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  2288. },
  2289. },
  2290. },
  2291. },
  2292. 'PlainIdentifier(scope=0,ident=c):0:7:c',
  2293. },
  2294. },
  2295. },
  2296. },
  2297. },
  2298. }, {
  2299. hl('IdentifierScope', 'a'),
  2300. hl('IdentifierScopeDelimiter', ':'),
  2301. hl('Curly', '{'),
  2302. hl('IdentifierName', 'b'),
  2303. hl('CallingParenthesis', '('),
  2304. hl('CallingParenthesis', ')'),
  2305. hl('Curly', '}'),
  2306. hl('IdentifierName', 'c'),
  2307. })
  2308. check_parsing('a:{{b, c -> @d + @e + ({f -> g})(@h)}(@i)}j', {
  2309. -- 01234567890123456789012345678901234567890123456
  2310. -- 0 1 2 3 4
  2311. ast = {
  2312. {
  2313. 'ComplexIdentifier:0:2:',
  2314. children = {
  2315. 'PlainIdentifier(scope=a,ident=):0:0:a:',
  2316. {
  2317. 'ComplexIdentifier:0:42:',
  2318. children = {
  2319. {
  2320. fmtn('CurlyBracesIdentifier', '--i', ':0:2:{'),
  2321. children = {
  2322. {
  2323. 'Call:0:37:(',
  2324. children = {
  2325. {
  2326. fmtn('Lambda', '\\di', ':0:3:{'),
  2327. children = {
  2328. {
  2329. 'Comma:0:5:,',
  2330. children = {
  2331. 'PlainIdentifier(scope=0,ident=b):0:4:b',
  2332. 'PlainIdentifier(scope=0,ident=c):0:6: c',
  2333. },
  2334. },
  2335. {
  2336. 'Arrow:0:8: ->',
  2337. children = {
  2338. {
  2339. 'BinaryPlus:0:19: +',
  2340. children = {
  2341. {
  2342. 'BinaryPlus:0:14: +',
  2343. children = {
  2344. 'Register(name=d):0:11: @d',
  2345. 'Register(name=e):0:16: @e',
  2346. },
  2347. },
  2348. {
  2349. 'Call:0:32:(',
  2350. children = {
  2351. {
  2352. 'Nested:0:21: (',
  2353. children = {
  2354. {
  2355. fmtn('Lambda', '\\di', ':0:23:{'),
  2356. children = {
  2357. 'PlainIdentifier(scope=0,ident=f):0:24:f',
  2358. {
  2359. 'Arrow:0:25: ->',
  2360. children = {
  2361. 'PlainIdentifier(scope=0,ident=g):0:28: g',
  2362. },
  2363. },
  2364. },
  2365. },
  2366. },
  2367. },
  2368. 'Register(name=h):0:33:@h',
  2369. },
  2370. },
  2371. },
  2372. },
  2373. },
  2374. },
  2375. },
  2376. },
  2377. 'Register(name=i):0:38:@i',
  2378. },
  2379. },
  2380. },
  2381. },
  2382. 'PlainIdentifier(scope=0,ident=j):0:42:j',
  2383. },
  2384. },
  2385. },
  2386. },
  2387. },
  2388. }, {
  2389. hl('IdentifierScope', 'a'),
  2390. hl('IdentifierScopeDelimiter', ':'),
  2391. hl('Curly', '{'),
  2392. hl('Lambda', '{'),
  2393. hl('IdentifierName', 'b'),
  2394. hl('Comma', ','),
  2395. hl('IdentifierName', 'c', 1),
  2396. hl('Arrow', '->', 1),
  2397. hl('Register', '@d', 1),
  2398. hl('BinaryPlus', '+', 1),
  2399. hl('Register', '@e', 1),
  2400. hl('BinaryPlus', '+', 1),
  2401. hl('NestingParenthesis', '(', 1),
  2402. hl('Lambda', '{'),
  2403. hl('IdentifierName', 'f'),
  2404. hl('Arrow', '->', 1),
  2405. hl('IdentifierName', 'g', 1),
  2406. hl('Lambda', '}'),
  2407. hl('NestingParenthesis', ')'),
  2408. hl('CallingParenthesis', '('),
  2409. hl('Register', '@h'),
  2410. hl('CallingParenthesis', ')'),
  2411. hl('Lambda', '}'),
  2412. hl('CallingParenthesis', '('),
  2413. hl('Register', '@i'),
  2414. hl('CallingParenthesis', ')'),
  2415. hl('Curly', '}'),
  2416. hl('IdentifierName', 'j'),
  2417. })
  2418. check_parsing('{@a + @b : @c + @d, @e + @f : @g + @i}', {
  2419. -- 01234567890123456789012345678901234567
  2420. -- 0 1 2 3
  2421. ast = {
  2422. {
  2423. fmtn('DictLiteral', '-di', ':0:0:{'),
  2424. children = {
  2425. {
  2426. 'Comma:0:18:,',
  2427. children = {
  2428. {
  2429. 'Colon:0:8: :',
  2430. children = {
  2431. {
  2432. 'BinaryPlus:0:3: +',
  2433. children = {
  2434. 'Register(name=a):0:1:@a',
  2435. 'Register(name=b):0:5: @b',
  2436. },
  2437. },
  2438. {
  2439. 'BinaryPlus:0:13: +',
  2440. children = {
  2441. 'Register(name=c):0:10: @c',
  2442. 'Register(name=d):0:15: @d',
  2443. },
  2444. },
  2445. },
  2446. },
  2447. {
  2448. 'Colon:0:27: :',
  2449. children = {
  2450. {
  2451. 'BinaryPlus:0:22: +',
  2452. children = {
  2453. 'Register(name=e):0:19: @e',
  2454. 'Register(name=f):0:24: @f',
  2455. },
  2456. },
  2457. {
  2458. 'BinaryPlus:0:32: +',
  2459. children = {
  2460. 'Register(name=g):0:29: @g',
  2461. 'Register(name=i):0:34: @i',
  2462. },
  2463. },
  2464. },
  2465. },
  2466. },
  2467. },
  2468. },
  2469. },
  2470. },
  2471. }, {
  2472. hl('Dict', '{'),
  2473. hl('Register', '@a'),
  2474. hl('BinaryPlus', '+', 1),
  2475. hl('Register', '@b', 1),
  2476. hl('Colon', ':', 1),
  2477. hl('Register', '@c', 1),
  2478. hl('BinaryPlus', '+', 1),
  2479. hl('Register', '@d', 1),
  2480. hl('Comma', ','),
  2481. hl('Register', '@e', 1),
  2482. hl('BinaryPlus', '+', 1),
  2483. hl('Register', '@f', 1),
  2484. hl('Colon', ':', 1),
  2485. hl('Register', '@g', 1),
  2486. hl('BinaryPlus', '+', 1),
  2487. hl('Register', '@i', 1),
  2488. hl('Dict', '}'),
  2489. })
  2490. check_parsing('-> -> ->', {
  2491. -- 01234567
  2492. ast = {
  2493. {
  2494. 'Arrow:0:0:->',
  2495. children = {
  2496. 'Missing:0:0:',
  2497. {
  2498. 'Arrow:0:2: ->',
  2499. children = {
  2500. 'Missing:0:2:',
  2501. {
  2502. 'Arrow:0:5: ->',
  2503. children = {
  2504. 'Missing:0:5:',
  2505. },
  2506. },
  2507. },
  2508. },
  2509. },
  2510. },
  2511. },
  2512. err = {
  2513. arg = '-> -> ->',
  2514. msg = 'E15: Unexpected arrow: %.*s',
  2515. },
  2516. }, {
  2517. hl('InvalidArrow', '->'),
  2518. hl('InvalidArrow', '->', 1),
  2519. hl('InvalidArrow', '->', 1),
  2520. })
  2521. check_parsing('a -> b -> c -> d', {
  2522. -- 0123456789012345
  2523. -- 0 1
  2524. ast = {
  2525. {
  2526. 'Arrow:0:1: ->',
  2527. children = {
  2528. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  2529. {
  2530. 'Arrow:0:6: ->',
  2531. children = {
  2532. 'PlainIdentifier(scope=0,ident=b):0:4: b',
  2533. {
  2534. 'Arrow:0:11: ->',
  2535. children = {
  2536. 'PlainIdentifier(scope=0,ident=c):0:9: c',
  2537. 'PlainIdentifier(scope=0,ident=d):0:14: d',
  2538. },
  2539. },
  2540. },
  2541. },
  2542. },
  2543. },
  2544. },
  2545. err = {
  2546. arg = '-> b -> c -> d',
  2547. msg = 'E15: Arrow outside of lambda: %.*s',
  2548. },
  2549. }, {
  2550. hl('IdentifierName', 'a'),
  2551. hl('InvalidArrow', '->', 1),
  2552. hl('IdentifierName', 'b', 1),
  2553. hl('InvalidArrow', '->', 1),
  2554. hl('IdentifierName', 'c', 1),
  2555. hl('InvalidArrow', '->', 1),
  2556. hl('IdentifierName', 'd', 1),
  2557. })
  2558. check_parsing('{a -> b -> c}', {
  2559. -- 0123456789012
  2560. -- 0 1
  2561. ast = {
  2562. {
  2563. fmtn('Lambda', '\\di', ':0:0:{'),
  2564. children = {
  2565. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  2566. {
  2567. 'Arrow:0:2: ->',
  2568. children = {
  2569. {
  2570. 'Arrow:0:7: ->',
  2571. children = {
  2572. 'PlainIdentifier(scope=0,ident=b):0:5: b',
  2573. 'PlainIdentifier(scope=0,ident=c):0:10: c',
  2574. },
  2575. },
  2576. },
  2577. },
  2578. },
  2579. },
  2580. },
  2581. err = {
  2582. arg = '-> c}',
  2583. msg = 'E15: Arrow outside of lambda: %.*s',
  2584. },
  2585. }, {
  2586. hl('Lambda', '{'),
  2587. hl('IdentifierName', 'a'),
  2588. hl('Arrow', '->', 1),
  2589. hl('IdentifierName', 'b', 1),
  2590. hl('InvalidArrow', '->', 1),
  2591. hl('IdentifierName', 'c', 1),
  2592. hl('Lambda', '}'),
  2593. })
  2594. check_parsing('{a: -> b}', {
  2595. -- 012345678
  2596. ast = {
  2597. {
  2598. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  2599. children = {
  2600. {
  2601. 'Arrow:0:3: ->',
  2602. children = {
  2603. 'PlainIdentifier(scope=a,ident=):0:1:a:',
  2604. 'PlainIdentifier(scope=0,ident=b):0:6: b',
  2605. },
  2606. },
  2607. },
  2608. },
  2609. },
  2610. err = {
  2611. arg = '-> b}',
  2612. msg = 'E15: Arrow outside of lambda: %.*s',
  2613. },
  2614. }, {
  2615. hl('Curly', '{'),
  2616. hl('IdentifierScope', 'a'),
  2617. hl('IdentifierScopeDelimiter', ':'),
  2618. hl('InvalidArrow', '->', 1),
  2619. hl('IdentifierName', 'b', 1),
  2620. hl('Curly', '}'),
  2621. })
  2622. check_parsing('{a:b -> b}', {
  2623. -- 0123456789
  2624. ast = {
  2625. {
  2626. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  2627. children = {
  2628. {
  2629. 'Arrow:0:4: ->',
  2630. children = {
  2631. 'PlainIdentifier(scope=a,ident=b):0:1:a:b',
  2632. 'PlainIdentifier(scope=0,ident=b):0:7: b',
  2633. },
  2634. },
  2635. },
  2636. },
  2637. },
  2638. err = {
  2639. arg = '-> b}',
  2640. msg = 'E15: Arrow outside of lambda: %.*s',
  2641. },
  2642. }, {
  2643. hl('Curly', '{'),
  2644. hl('IdentifierScope', 'a'),
  2645. hl('IdentifierScopeDelimiter', ':'),
  2646. hl('IdentifierName', 'b'),
  2647. hl('InvalidArrow', '->', 1),
  2648. hl('IdentifierName', 'b', 1),
  2649. hl('Curly', '}'),
  2650. })
  2651. check_parsing('{a#b -> b}', {
  2652. -- 0123456789
  2653. ast = {
  2654. {
  2655. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  2656. children = {
  2657. {
  2658. 'Arrow:0:4: ->',
  2659. children = {
  2660. 'PlainIdentifier(scope=0,ident=a#b):0:1:a#b',
  2661. 'PlainIdentifier(scope=0,ident=b):0:7: b',
  2662. },
  2663. },
  2664. },
  2665. },
  2666. },
  2667. err = {
  2668. arg = '-> b}',
  2669. msg = 'E15: Arrow outside of lambda: %.*s',
  2670. },
  2671. }, {
  2672. hl('Curly', '{'),
  2673. hl('IdentifierName', 'a#b'),
  2674. hl('InvalidArrow', '->', 1),
  2675. hl('IdentifierName', 'b', 1),
  2676. hl('Curly', '}'),
  2677. })
  2678. check_parsing('{a : b : c}', {
  2679. -- 01234567890
  2680. -- 0 1
  2681. ast = {
  2682. {
  2683. fmtn('DictLiteral', '-di', ':0:0:{'),
  2684. children = {
  2685. {
  2686. 'Colon:0:2: :',
  2687. children = {
  2688. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  2689. {
  2690. 'Colon:0:6: :',
  2691. children = {
  2692. 'PlainIdentifier(scope=0,ident=b):0:4: b',
  2693. 'PlainIdentifier(scope=0,ident=c):0:8: c',
  2694. },
  2695. },
  2696. },
  2697. },
  2698. },
  2699. },
  2700. },
  2701. err = {
  2702. arg = ': c}',
  2703. msg = 'E15: Colon outside of dictionary or ternary operator: %.*s',
  2704. },
  2705. }, {
  2706. hl('Dict', '{'),
  2707. hl('IdentifierName', 'a'),
  2708. hl('Colon', ':', 1),
  2709. hl('IdentifierName', 'b', 1),
  2710. hl('InvalidColon', ':', 1),
  2711. hl('IdentifierName', 'c', 1),
  2712. hl('Dict', '}'),
  2713. })
  2714. check_parsing('{', {
  2715. -- 0
  2716. ast = {
  2717. fmtn('UnknownFigure', '\\di', ':0:0:{'),
  2718. },
  2719. err = {
  2720. arg = '{',
  2721. msg = 'E15: Missing closing figure brace: %.*s',
  2722. },
  2723. }, {
  2724. hl('FigureBrace', '{'),
  2725. })
  2726. check_parsing('{a', {
  2727. -- 01
  2728. ast = {
  2729. {
  2730. fmtn('UnknownFigure', '\\di', ':0:0:{'),
  2731. children = {
  2732. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  2733. },
  2734. },
  2735. },
  2736. err = {
  2737. arg = '{a',
  2738. msg = 'E15: Missing closing figure brace: %.*s',
  2739. },
  2740. }, {
  2741. hl('FigureBrace', '{'),
  2742. hl('IdentifierName', 'a'),
  2743. })
  2744. check_parsing('{a,b', {
  2745. -- 0123
  2746. ast = {
  2747. {
  2748. fmtn('Lambda', '\\di', ':0:0:{'),
  2749. children = {
  2750. {
  2751. 'Comma:0:2:,',
  2752. children = {
  2753. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  2754. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  2755. },
  2756. },
  2757. },
  2758. },
  2759. },
  2760. err = {
  2761. arg = '{a,b',
  2762. msg = 'E15: Missing closing figure brace for lambda: %.*s',
  2763. },
  2764. }, {
  2765. hl('Lambda', '{'),
  2766. hl('IdentifierName', 'a'),
  2767. hl('Comma', ','),
  2768. hl('IdentifierName', 'b'),
  2769. })
  2770. check_parsing('{a,b->', {
  2771. -- 012345
  2772. ast = {
  2773. {
  2774. fmtn('Lambda', '\\di', ':0:0:{'),
  2775. children = {
  2776. {
  2777. 'Comma:0:2:,',
  2778. children = {
  2779. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  2780. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  2781. },
  2782. },
  2783. 'Arrow:0:4:->',
  2784. },
  2785. },
  2786. },
  2787. err = {
  2788. arg = '',
  2789. msg = 'E15: Expected value, got EOC: %.*s',
  2790. },
  2791. }, {
  2792. hl('Lambda', '{'),
  2793. hl('IdentifierName', 'a'),
  2794. hl('Comma', ','),
  2795. hl('IdentifierName', 'b'),
  2796. hl('Arrow', '->'),
  2797. })
  2798. check_parsing('{a,b->c', {
  2799. -- 0123456
  2800. ast = {
  2801. {
  2802. fmtn('Lambda', '\\di', ':0:0:{'),
  2803. children = {
  2804. {
  2805. 'Comma:0:2:,',
  2806. children = {
  2807. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  2808. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  2809. },
  2810. },
  2811. {
  2812. 'Arrow:0:4:->',
  2813. children = {
  2814. 'PlainIdentifier(scope=0,ident=c):0:6:c',
  2815. },
  2816. },
  2817. },
  2818. },
  2819. },
  2820. err = {
  2821. arg = '{a,b->c',
  2822. msg = 'E15: Missing closing figure brace for lambda: %.*s',
  2823. },
  2824. }, {
  2825. hl('Lambda', '{'),
  2826. hl('IdentifierName', 'a'),
  2827. hl('Comma', ','),
  2828. hl('IdentifierName', 'b'),
  2829. hl('Arrow', '->'),
  2830. hl('IdentifierName', 'c'),
  2831. })
  2832. check_parsing('{a : b', {
  2833. -- 012345
  2834. ast = {
  2835. {
  2836. fmtn('DictLiteral', '-di', ':0:0:{'),
  2837. children = {
  2838. {
  2839. 'Colon:0:2: :',
  2840. children = {
  2841. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  2842. 'PlainIdentifier(scope=0,ident=b):0:4: b',
  2843. },
  2844. },
  2845. },
  2846. },
  2847. },
  2848. err = {
  2849. arg = '{a : b',
  2850. msg = "E723: Missing end of Dictionary '}': %.*s",
  2851. },
  2852. }, {
  2853. hl('Dict', '{'),
  2854. hl('IdentifierName', 'a'),
  2855. hl('Colon', ':', 1),
  2856. hl('IdentifierName', 'b', 1),
  2857. })
  2858. check_parsing('{a : b,', {
  2859. -- 0123456
  2860. ast = {
  2861. {
  2862. fmtn('DictLiteral', '-di', ':0:0:{'),
  2863. children = {
  2864. {
  2865. 'Comma:0:6:,',
  2866. children = {
  2867. {
  2868. 'Colon:0:2: :',
  2869. children = {
  2870. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  2871. 'PlainIdentifier(scope=0,ident=b):0:4: b',
  2872. },
  2873. },
  2874. },
  2875. },
  2876. },
  2877. },
  2878. },
  2879. err = {
  2880. arg = '',
  2881. msg = 'E15: Expected value, got EOC: %.*s',
  2882. },
  2883. }, {
  2884. hl('Dict', '{'),
  2885. hl('IdentifierName', 'a'),
  2886. hl('Colon', ':', 1),
  2887. hl('IdentifierName', 'b', 1),
  2888. hl('Comma', ','),
  2889. })
  2890. end)
  2891. itp('works with ternary operator', function()
  2892. check_parsing('a ? b : c', {
  2893. -- 012345678
  2894. ast = {
  2895. {
  2896. 'Ternary:0:1: ?',
  2897. children = {
  2898. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  2899. {
  2900. 'TernaryValue:0:5: :',
  2901. children = {
  2902. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  2903. 'PlainIdentifier(scope=0,ident=c):0:7: c',
  2904. },
  2905. },
  2906. },
  2907. },
  2908. },
  2909. }, {
  2910. hl('IdentifierName', 'a'),
  2911. hl('Ternary', '?', 1),
  2912. hl('IdentifierName', 'b', 1),
  2913. hl('TernaryColon', ':', 1),
  2914. hl('IdentifierName', 'c', 1),
  2915. })
  2916. check_parsing('@a?@b?@c:@d:@e', {
  2917. -- 01234567890123
  2918. -- 0 1
  2919. ast = {
  2920. {
  2921. 'Ternary:0:2:?',
  2922. children = {
  2923. 'Register(name=a):0:0:@a',
  2924. {
  2925. 'TernaryValue:0:11::',
  2926. children = {
  2927. {
  2928. 'Ternary:0:5:?',
  2929. children = {
  2930. 'Register(name=b):0:3:@b',
  2931. {
  2932. 'TernaryValue:0:8::',
  2933. children = {
  2934. 'Register(name=c):0:6:@c',
  2935. 'Register(name=d):0:9:@d',
  2936. },
  2937. },
  2938. },
  2939. },
  2940. 'Register(name=e):0:12:@e',
  2941. },
  2942. },
  2943. },
  2944. },
  2945. },
  2946. }, {
  2947. hl('Register', '@a'),
  2948. hl('Ternary', '?'),
  2949. hl('Register', '@b'),
  2950. hl('Ternary', '?'),
  2951. hl('Register', '@c'),
  2952. hl('TernaryColon', ':'),
  2953. hl('Register', '@d'),
  2954. hl('TernaryColon', ':'),
  2955. hl('Register', '@e'),
  2956. })
  2957. check_parsing('@a?@b:@c?@d:@e', {
  2958. -- 01234567890123
  2959. -- 0 1
  2960. ast = {
  2961. {
  2962. 'Ternary:0:2:?',
  2963. children = {
  2964. 'Register(name=a):0:0:@a',
  2965. {
  2966. 'TernaryValue:0:5::',
  2967. children = {
  2968. 'Register(name=b):0:3:@b',
  2969. {
  2970. 'Ternary:0:8:?',
  2971. children = {
  2972. 'Register(name=c):0:6:@c',
  2973. {
  2974. 'TernaryValue:0:11::',
  2975. children = {
  2976. 'Register(name=d):0:9:@d',
  2977. 'Register(name=e):0:12:@e',
  2978. },
  2979. },
  2980. },
  2981. },
  2982. },
  2983. },
  2984. },
  2985. },
  2986. },
  2987. }, {
  2988. hl('Register', '@a'),
  2989. hl('Ternary', '?'),
  2990. hl('Register', '@b'),
  2991. hl('TernaryColon', ':'),
  2992. hl('Register', '@c'),
  2993. hl('Ternary', '?'),
  2994. hl('Register', '@d'),
  2995. hl('TernaryColon', ':'),
  2996. hl('Register', '@e'),
  2997. })
  2998. check_parsing('@a?@b?@c?@d:@e?@f:@g:@h?@i:@j:@k', {
  2999. -- 01234567890123456789012345678901
  3000. -- 0 1 2 3
  3001. ast = {
  3002. {
  3003. 'Ternary:0:2:?',
  3004. children = {
  3005. 'Register(name=a):0:0:@a',
  3006. {
  3007. 'TernaryValue:0:29::',
  3008. children = {
  3009. {
  3010. 'Ternary:0:5:?',
  3011. children = {
  3012. 'Register(name=b):0:3:@b',
  3013. {
  3014. 'TernaryValue:0:20::',
  3015. children = {
  3016. {
  3017. 'Ternary:0:8:?',
  3018. children = {
  3019. 'Register(name=c):0:6:@c',
  3020. {
  3021. 'TernaryValue:0:11::',
  3022. children = {
  3023. 'Register(name=d):0:9:@d',
  3024. {
  3025. 'Ternary:0:14:?',
  3026. children = {
  3027. 'Register(name=e):0:12:@e',
  3028. {
  3029. 'TernaryValue:0:17::',
  3030. children = {
  3031. 'Register(name=f):0:15:@f',
  3032. 'Register(name=g):0:18:@g',
  3033. },
  3034. },
  3035. },
  3036. },
  3037. },
  3038. },
  3039. },
  3040. },
  3041. {
  3042. 'Ternary:0:23:?',
  3043. children = {
  3044. 'Register(name=h):0:21:@h',
  3045. {
  3046. 'TernaryValue:0:26::',
  3047. children = {
  3048. 'Register(name=i):0:24:@i',
  3049. 'Register(name=j):0:27:@j',
  3050. },
  3051. },
  3052. },
  3053. },
  3054. },
  3055. },
  3056. },
  3057. },
  3058. 'Register(name=k):0:30:@k',
  3059. },
  3060. },
  3061. },
  3062. },
  3063. },
  3064. }, {
  3065. hl('Register', '@a'),
  3066. hl('Ternary', '?'),
  3067. hl('Register', '@b'),
  3068. hl('Ternary', '?'),
  3069. hl('Register', '@c'),
  3070. hl('Ternary', '?'),
  3071. hl('Register', '@d'),
  3072. hl('TernaryColon', ':'),
  3073. hl('Register', '@e'),
  3074. hl('Ternary', '?'),
  3075. hl('Register', '@f'),
  3076. hl('TernaryColon', ':'),
  3077. hl('Register', '@g'),
  3078. hl('TernaryColon', ':'),
  3079. hl('Register', '@h'),
  3080. hl('Ternary', '?'),
  3081. hl('Register', '@i'),
  3082. hl('TernaryColon', ':'),
  3083. hl('Register', '@j'),
  3084. hl('TernaryColon', ':'),
  3085. hl('Register', '@k'),
  3086. })
  3087. check_parsing('?', {
  3088. -- 0
  3089. ast = {
  3090. {
  3091. 'Ternary:0:0:?',
  3092. children = {
  3093. 'Missing:0:0:',
  3094. 'TernaryValue:0:0:?',
  3095. },
  3096. },
  3097. },
  3098. err = {
  3099. arg = '?',
  3100. msg = 'E15: Expected value, got question mark: %.*s',
  3101. },
  3102. }, {
  3103. hl('InvalidTernary', '?'),
  3104. })
  3105. check_parsing('?:', {
  3106. -- 01
  3107. ast = {
  3108. {
  3109. 'Ternary:0:0:?',
  3110. children = {
  3111. 'Missing:0:0:',
  3112. {
  3113. 'TernaryValue:0:1::',
  3114. children = {
  3115. 'Missing:0:1:',
  3116. },
  3117. },
  3118. },
  3119. },
  3120. },
  3121. err = {
  3122. arg = '?:',
  3123. msg = 'E15: Expected value, got question mark: %.*s',
  3124. },
  3125. }, {
  3126. hl('InvalidTernary', '?'),
  3127. hl('InvalidTernaryColon', ':'),
  3128. })
  3129. check_parsing('?::', {
  3130. -- 012
  3131. ast = {
  3132. {
  3133. 'Colon:0:2::',
  3134. children = {
  3135. {
  3136. 'Ternary:0:0:?',
  3137. children = {
  3138. 'Missing:0:0:',
  3139. {
  3140. 'TernaryValue:0:1::',
  3141. children = {
  3142. 'Missing:0:1:',
  3143. 'Missing:0:2:',
  3144. },
  3145. },
  3146. },
  3147. },
  3148. },
  3149. },
  3150. },
  3151. err = {
  3152. arg = '?::',
  3153. msg = 'E15: Expected value, got question mark: %.*s',
  3154. },
  3155. }, {
  3156. hl('InvalidTernary', '?'),
  3157. hl('InvalidTernaryColon', ':'),
  3158. hl('InvalidColon', ':'),
  3159. })
  3160. check_parsing('a?b', {
  3161. -- 012
  3162. ast = {
  3163. {
  3164. 'Ternary:0:1:?',
  3165. children = {
  3166. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3167. {
  3168. 'TernaryValue:0:1:?',
  3169. children = {
  3170. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  3171. },
  3172. },
  3173. },
  3174. },
  3175. },
  3176. err = {
  3177. arg = '?b',
  3178. msg = "E109: Missing ':' after '?': %.*s",
  3179. },
  3180. }, {
  3181. hl('IdentifierName', 'a'),
  3182. hl('Ternary', '?'),
  3183. hl('IdentifierName', 'b'),
  3184. })
  3185. check_parsing('a?b:', {
  3186. -- 0123
  3187. ast = {
  3188. {
  3189. 'Ternary:0:1:?',
  3190. children = {
  3191. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3192. {
  3193. 'TernaryValue:0:1:?',
  3194. children = {
  3195. 'PlainIdentifier(scope=b,ident=):0:2:b:',
  3196. },
  3197. },
  3198. },
  3199. },
  3200. },
  3201. err = {
  3202. arg = '?b:',
  3203. msg = "E109: Missing ':' after '?': %.*s",
  3204. },
  3205. }, {
  3206. hl('IdentifierName', 'a'),
  3207. hl('Ternary', '?'),
  3208. hl('IdentifierScope', 'b'),
  3209. hl('IdentifierScopeDelimiter', ':'),
  3210. })
  3211. check_parsing('a?b::c', {
  3212. -- 012345
  3213. ast = {
  3214. {
  3215. 'Ternary:0:1:?',
  3216. children = {
  3217. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3218. {
  3219. 'TernaryValue:0:4::',
  3220. children = {
  3221. 'PlainIdentifier(scope=b,ident=):0:2:b:',
  3222. 'PlainIdentifier(scope=0,ident=c):0:5:c',
  3223. },
  3224. },
  3225. },
  3226. },
  3227. },
  3228. }, {
  3229. hl('IdentifierName', 'a'),
  3230. hl('Ternary', '?'),
  3231. hl('IdentifierScope', 'b'),
  3232. hl('IdentifierScopeDelimiter', ':'),
  3233. hl('TernaryColon', ':'),
  3234. hl('IdentifierName', 'c'),
  3235. })
  3236. check_parsing('a?b :', {
  3237. -- 01234
  3238. ast = {
  3239. {
  3240. 'Ternary:0:1:?',
  3241. children = {
  3242. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3243. {
  3244. 'TernaryValue:0:3: :',
  3245. children = {
  3246. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  3247. },
  3248. },
  3249. },
  3250. },
  3251. },
  3252. err = {
  3253. arg = '',
  3254. msg = 'E15: Expected value, got EOC: %.*s',
  3255. },
  3256. }, {
  3257. hl('IdentifierName', 'a'),
  3258. hl('Ternary', '?'),
  3259. hl('IdentifierName', 'b'),
  3260. hl('TernaryColon', ':', 1),
  3261. })
  3262. check_parsing('(@a?@b:@c)?@d:@e', {
  3263. -- 0123456789012345
  3264. -- 0 1
  3265. ast = {
  3266. {
  3267. 'Ternary:0:10:?',
  3268. children = {
  3269. {
  3270. 'Nested:0:0:(',
  3271. children = {
  3272. {
  3273. 'Ternary:0:3:?',
  3274. children = {
  3275. 'Register(name=a):0:1:@a',
  3276. {
  3277. 'TernaryValue:0:6::',
  3278. children = {
  3279. 'Register(name=b):0:4:@b',
  3280. 'Register(name=c):0:7:@c',
  3281. },
  3282. },
  3283. },
  3284. },
  3285. },
  3286. },
  3287. {
  3288. 'TernaryValue:0:13::',
  3289. children = {
  3290. 'Register(name=d):0:11:@d',
  3291. 'Register(name=e):0:14:@e',
  3292. },
  3293. },
  3294. },
  3295. },
  3296. },
  3297. }, {
  3298. hl('NestingParenthesis', '('),
  3299. hl('Register', '@a'),
  3300. hl('Ternary', '?'),
  3301. hl('Register', '@b'),
  3302. hl('TernaryColon', ':'),
  3303. hl('Register', '@c'),
  3304. hl('NestingParenthesis', ')'),
  3305. hl('Ternary', '?'),
  3306. hl('Register', '@d'),
  3307. hl('TernaryColon', ':'),
  3308. hl('Register', '@e'),
  3309. })
  3310. check_parsing('(@a?@b:@c)?(@d?@e:@f):(@g?@h:@i)', {
  3311. -- 01234567890123456789012345678901
  3312. -- 0 1 2 3
  3313. ast = {
  3314. {
  3315. 'Ternary:0:10:?',
  3316. children = {
  3317. {
  3318. 'Nested:0:0:(',
  3319. children = {
  3320. {
  3321. 'Ternary:0:3:?',
  3322. children = {
  3323. 'Register(name=a):0:1:@a',
  3324. {
  3325. 'TernaryValue:0:6::',
  3326. children = {
  3327. 'Register(name=b):0:4:@b',
  3328. 'Register(name=c):0:7:@c',
  3329. },
  3330. },
  3331. },
  3332. },
  3333. },
  3334. },
  3335. {
  3336. 'TernaryValue:0:21::',
  3337. children = {
  3338. {
  3339. 'Nested:0:11:(',
  3340. children = {
  3341. {
  3342. 'Ternary:0:14:?',
  3343. children = {
  3344. 'Register(name=d):0:12:@d',
  3345. {
  3346. 'TernaryValue:0:17::',
  3347. children = {
  3348. 'Register(name=e):0:15:@e',
  3349. 'Register(name=f):0:18:@f',
  3350. },
  3351. },
  3352. },
  3353. },
  3354. },
  3355. },
  3356. {
  3357. 'Nested:0:22:(',
  3358. children = {
  3359. {
  3360. 'Ternary:0:25:?',
  3361. children = {
  3362. 'Register(name=g):0:23:@g',
  3363. {
  3364. 'TernaryValue:0:28::',
  3365. children = {
  3366. 'Register(name=h):0:26:@h',
  3367. 'Register(name=i):0:29:@i',
  3368. },
  3369. },
  3370. },
  3371. },
  3372. },
  3373. },
  3374. },
  3375. },
  3376. },
  3377. },
  3378. },
  3379. }, {
  3380. hl('NestingParenthesis', '('),
  3381. hl('Register', '@a'),
  3382. hl('Ternary', '?'),
  3383. hl('Register', '@b'),
  3384. hl('TernaryColon', ':'),
  3385. hl('Register', '@c'),
  3386. hl('NestingParenthesis', ')'),
  3387. hl('Ternary', '?'),
  3388. hl('NestingParenthesis', '('),
  3389. hl('Register', '@d'),
  3390. hl('Ternary', '?'),
  3391. hl('Register', '@e'),
  3392. hl('TernaryColon', ':'),
  3393. hl('Register', '@f'),
  3394. hl('NestingParenthesis', ')'),
  3395. hl('TernaryColon', ':'),
  3396. hl('NestingParenthesis', '('),
  3397. hl('Register', '@g'),
  3398. hl('Ternary', '?'),
  3399. hl('Register', '@h'),
  3400. hl('TernaryColon', ':'),
  3401. hl('Register', '@i'),
  3402. hl('NestingParenthesis', ')'),
  3403. })
  3404. check_parsing('(@a?@b:@c)?@d?@e:@f:@g?@h:@i', {
  3405. -- 0123456789012345678901234567
  3406. -- 0 1 2
  3407. ast = {
  3408. {
  3409. 'Ternary:0:10:?',
  3410. children = {
  3411. {
  3412. 'Nested:0:0:(',
  3413. children = {
  3414. {
  3415. 'Ternary:0:3:?',
  3416. children = {
  3417. 'Register(name=a):0:1:@a',
  3418. {
  3419. 'TernaryValue:0:6::',
  3420. children = {
  3421. 'Register(name=b):0:4:@b',
  3422. 'Register(name=c):0:7:@c',
  3423. },
  3424. },
  3425. },
  3426. },
  3427. },
  3428. },
  3429. {
  3430. 'TernaryValue:0:19::',
  3431. children = {
  3432. {
  3433. 'Ternary:0:13:?',
  3434. children = {
  3435. 'Register(name=d):0:11:@d',
  3436. {
  3437. 'TernaryValue:0:16::',
  3438. children = {
  3439. 'Register(name=e):0:14:@e',
  3440. 'Register(name=f):0:17:@f',
  3441. },
  3442. },
  3443. },
  3444. },
  3445. {
  3446. 'Ternary:0:22:?',
  3447. children = {
  3448. 'Register(name=g):0:20:@g',
  3449. {
  3450. 'TernaryValue:0:25::',
  3451. children = {
  3452. 'Register(name=h):0:23:@h',
  3453. 'Register(name=i):0:26:@i',
  3454. },
  3455. },
  3456. },
  3457. },
  3458. },
  3459. },
  3460. },
  3461. },
  3462. },
  3463. }, {
  3464. hl('NestingParenthesis', '('),
  3465. hl('Register', '@a'),
  3466. hl('Ternary', '?'),
  3467. hl('Register', '@b'),
  3468. hl('TernaryColon', ':'),
  3469. hl('Register', '@c'),
  3470. hl('NestingParenthesis', ')'),
  3471. hl('Ternary', '?'),
  3472. hl('Register', '@d'),
  3473. hl('Ternary', '?'),
  3474. hl('Register', '@e'),
  3475. hl('TernaryColon', ':'),
  3476. hl('Register', '@f'),
  3477. hl('TernaryColon', ':'),
  3478. hl('Register', '@g'),
  3479. hl('Ternary', '?'),
  3480. hl('Register', '@h'),
  3481. hl('TernaryColon', ':'),
  3482. hl('Register', '@i'),
  3483. })
  3484. check_parsing('a?b{cdef}g:h', {
  3485. -- 012345678901
  3486. -- 0 1
  3487. ast = {
  3488. {
  3489. 'Ternary:0:1:?',
  3490. children = {
  3491. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3492. {
  3493. 'TernaryValue:0:10::',
  3494. children = {
  3495. {
  3496. 'ComplexIdentifier:0:3:',
  3497. children = {
  3498. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  3499. {
  3500. 'ComplexIdentifier:0:9:',
  3501. children = {
  3502. {
  3503. fmtn('CurlyBracesIdentifier', '--i', ':0:3:{'),
  3504. children = {
  3505. 'PlainIdentifier(scope=0,ident=cdef):0:4:cdef',
  3506. },
  3507. },
  3508. 'PlainIdentifier(scope=0,ident=g):0:9:g',
  3509. },
  3510. },
  3511. },
  3512. },
  3513. 'PlainIdentifier(scope=0,ident=h):0:11:h',
  3514. },
  3515. },
  3516. },
  3517. },
  3518. },
  3519. }, {
  3520. hl('IdentifierName', 'a'),
  3521. hl('Ternary', '?'),
  3522. hl('IdentifierName', 'b'),
  3523. hl('Curly', '{'),
  3524. hl('IdentifierName', 'cdef'),
  3525. hl('Curly', '}'),
  3526. hl('IdentifierName', 'g'),
  3527. hl('TernaryColon', ':'),
  3528. hl('IdentifierName', 'h'),
  3529. })
  3530. check_parsing('a ? b : c : d', {
  3531. -- 0123456789012
  3532. -- 0 1
  3533. ast = {
  3534. {
  3535. 'Colon:0:9: :',
  3536. children = {
  3537. {
  3538. 'Ternary:0:1: ?',
  3539. children = {
  3540. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3541. {
  3542. 'TernaryValue:0:5: :',
  3543. children = {
  3544. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  3545. 'PlainIdentifier(scope=0,ident=c):0:7: c',
  3546. },
  3547. },
  3548. },
  3549. },
  3550. 'PlainIdentifier(scope=0,ident=d):0:11: d',
  3551. },
  3552. },
  3553. },
  3554. err = {
  3555. arg = ': d',
  3556. msg = 'E15: Colon outside of dictionary or ternary operator: %.*s',
  3557. },
  3558. }, {
  3559. hl('IdentifierName', 'a'),
  3560. hl('Ternary', '?', 1),
  3561. hl('IdentifierName', 'b', 1),
  3562. hl('TernaryColon', ':', 1),
  3563. hl('IdentifierName', 'c', 1),
  3564. hl('InvalidColon', ':', 1),
  3565. hl('IdentifierName', 'd', 1),
  3566. })
  3567. end)
  3568. itp('works with comparison operators', function()
  3569. check_parsing('a == b', {
  3570. -- 012345
  3571. ast = {
  3572. {
  3573. 'Comparison(type=Equal,inv=0,ccs=UseOption):0:1: ==',
  3574. children = {
  3575. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3576. 'PlainIdentifier(scope=0,ident=b):0:4: b',
  3577. },
  3578. },
  3579. },
  3580. }, {
  3581. hl('IdentifierName', 'a'),
  3582. hl('Comparison', '==', 1),
  3583. hl('IdentifierName', 'b', 1),
  3584. })
  3585. check_parsing('a ==? b', {
  3586. -- 0123456
  3587. ast = {
  3588. {
  3589. 'Comparison(type=Equal,inv=0,ccs=IgnoreCase):0:1: ==?',
  3590. children = {
  3591. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3592. 'PlainIdentifier(scope=0,ident=b):0:5: b',
  3593. },
  3594. },
  3595. },
  3596. }, {
  3597. hl('IdentifierName', 'a'),
  3598. hl('Comparison', '==', 1),
  3599. hl('ComparisonModifier', '?'),
  3600. hl('IdentifierName', 'b', 1),
  3601. })
  3602. check_parsing('a ==# b', {
  3603. -- 0123456
  3604. ast = {
  3605. {
  3606. 'Comparison(type=Equal,inv=0,ccs=MatchCase):0:1: ==#',
  3607. children = {
  3608. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3609. 'PlainIdentifier(scope=0,ident=b):0:5: b',
  3610. },
  3611. },
  3612. },
  3613. }, {
  3614. hl('IdentifierName', 'a'),
  3615. hl('Comparison', '==', 1),
  3616. hl('ComparisonModifier', '#'),
  3617. hl('IdentifierName', 'b', 1),
  3618. })
  3619. check_parsing('a !=# b', {
  3620. -- 0123456
  3621. ast = {
  3622. {
  3623. 'Comparison(type=Equal,inv=1,ccs=MatchCase):0:1: !=#',
  3624. children = {
  3625. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3626. 'PlainIdentifier(scope=0,ident=b):0:5: b',
  3627. },
  3628. },
  3629. },
  3630. }, {
  3631. hl('IdentifierName', 'a'),
  3632. hl('Comparison', '!=', 1),
  3633. hl('ComparisonModifier', '#'),
  3634. hl('IdentifierName', 'b', 1),
  3635. })
  3636. check_parsing('a <=# b', {
  3637. -- 0123456
  3638. ast = {
  3639. {
  3640. 'Comparison(type=Greater,inv=1,ccs=MatchCase):0:1: <=#',
  3641. children = {
  3642. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3643. 'PlainIdentifier(scope=0,ident=b):0:5: b',
  3644. },
  3645. },
  3646. },
  3647. }, {
  3648. hl('IdentifierName', 'a'),
  3649. hl('Comparison', '<=', 1),
  3650. hl('ComparisonModifier', '#'),
  3651. hl('IdentifierName', 'b', 1),
  3652. })
  3653. check_parsing('a >=# b', {
  3654. -- 0123456
  3655. ast = {
  3656. {
  3657. 'Comparison(type=GreaterOrEqual,inv=0,ccs=MatchCase):0:1: >=#',
  3658. children = {
  3659. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3660. 'PlainIdentifier(scope=0,ident=b):0:5: b',
  3661. },
  3662. },
  3663. },
  3664. }, {
  3665. hl('IdentifierName', 'a'),
  3666. hl('Comparison', '>=', 1),
  3667. hl('ComparisonModifier', '#'),
  3668. hl('IdentifierName', 'b', 1),
  3669. })
  3670. check_parsing('a ># b', {
  3671. -- 012345
  3672. ast = {
  3673. {
  3674. 'Comparison(type=Greater,inv=0,ccs=MatchCase):0:1: >#',
  3675. children = {
  3676. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3677. 'PlainIdentifier(scope=0,ident=b):0:4: b',
  3678. },
  3679. },
  3680. },
  3681. }, {
  3682. hl('IdentifierName', 'a'),
  3683. hl('Comparison', '>', 1),
  3684. hl('ComparisonModifier', '#'),
  3685. hl('IdentifierName', 'b', 1),
  3686. })
  3687. check_parsing('a <# b', {
  3688. -- 012345
  3689. ast = {
  3690. {
  3691. 'Comparison(type=GreaterOrEqual,inv=1,ccs=MatchCase):0:1: <#',
  3692. children = {
  3693. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3694. 'PlainIdentifier(scope=0,ident=b):0:4: b',
  3695. },
  3696. },
  3697. },
  3698. }, {
  3699. hl('IdentifierName', 'a'),
  3700. hl('Comparison', '<', 1),
  3701. hl('ComparisonModifier', '#'),
  3702. hl('IdentifierName', 'b', 1),
  3703. })
  3704. check_parsing('a is#b', {
  3705. -- 012345
  3706. ast = {
  3707. {
  3708. 'Comparison(type=Identical,inv=0,ccs=MatchCase):0:1: is#',
  3709. children = {
  3710. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3711. 'PlainIdentifier(scope=0,ident=b):0:5:b',
  3712. },
  3713. },
  3714. },
  3715. }, {
  3716. hl('IdentifierName', 'a'),
  3717. hl('Comparison', 'is', 1),
  3718. hl('ComparisonModifier', '#'),
  3719. hl('IdentifierName', 'b'),
  3720. })
  3721. check_parsing('a is?b', {
  3722. -- 012345
  3723. ast = {
  3724. {
  3725. 'Comparison(type=Identical,inv=0,ccs=IgnoreCase):0:1: is?',
  3726. children = {
  3727. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3728. 'PlainIdentifier(scope=0,ident=b):0:5:b',
  3729. },
  3730. },
  3731. },
  3732. }, {
  3733. hl('IdentifierName', 'a'),
  3734. hl('Comparison', 'is', 1),
  3735. hl('ComparisonModifier', '?'),
  3736. hl('IdentifierName', 'b'),
  3737. })
  3738. check_parsing('a isnot b', {
  3739. -- 012345678
  3740. ast = {
  3741. {
  3742. 'Comparison(type=Identical,inv=1,ccs=UseOption):0:1: isnot',
  3743. children = {
  3744. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3745. 'PlainIdentifier(scope=0,ident=b):0:7: b',
  3746. },
  3747. },
  3748. },
  3749. }, {
  3750. hl('IdentifierName', 'a'),
  3751. hl('Comparison', 'isnot', 1),
  3752. hl('IdentifierName', 'b', 1),
  3753. })
  3754. check_parsing('a < b < c', {
  3755. -- 012345678
  3756. ast = {
  3757. {
  3758. 'Comparison(type=GreaterOrEqual,inv=1,ccs=UseOption):0:1: <',
  3759. children = {
  3760. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3761. {
  3762. 'Comparison(type=GreaterOrEqual,inv=1,ccs=UseOption):0:5: <',
  3763. children = {
  3764. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  3765. 'PlainIdentifier(scope=0,ident=c):0:7: c',
  3766. },
  3767. },
  3768. },
  3769. },
  3770. },
  3771. err = {
  3772. arg = ' < c',
  3773. msg = 'E15: Operator is not associative: %.*s',
  3774. },
  3775. }, {
  3776. hl('IdentifierName', 'a'),
  3777. hl('Comparison', '<', 1),
  3778. hl('IdentifierName', 'b', 1),
  3779. hl('InvalidComparison', '<', 1),
  3780. hl('IdentifierName', 'c', 1),
  3781. })
  3782. check_parsing('a < b <# c', {
  3783. -- 012345678
  3784. ast = {
  3785. {
  3786. 'Comparison(type=GreaterOrEqual,inv=1,ccs=UseOption):0:1: <',
  3787. children = {
  3788. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3789. {
  3790. 'Comparison(type=GreaterOrEqual,inv=1,ccs=MatchCase):0:5: <#',
  3791. children = {
  3792. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  3793. 'PlainIdentifier(scope=0,ident=c):0:8: c',
  3794. },
  3795. },
  3796. },
  3797. },
  3798. },
  3799. err = {
  3800. arg = ' <# c',
  3801. msg = 'E15: Operator is not associative: %.*s',
  3802. },
  3803. }, {
  3804. hl('IdentifierName', 'a'),
  3805. hl('Comparison', '<', 1),
  3806. hl('IdentifierName', 'b', 1),
  3807. hl('InvalidComparison', '<', 1),
  3808. hl('InvalidComparisonModifier', '#'),
  3809. hl('IdentifierName', 'c', 1),
  3810. })
  3811. check_parsing('a += b', {
  3812. -- 012345
  3813. ast = {
  3814. {
  3815. 'Assignment(Add):0:1: +=',
  3816. children = {
  3817. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3818. 'PlainIdentifier(scope=0,ident=b):0:4: b',
  3819. },
  3820. },
  3821. },
  3822. err = {
  3823. arg = '+= b',
  3824. msg = 'E15: Misplaced assignment: %.*s',
  3825. },
  3826. }, {
  3827. hl('IdentifierName', 'a'),
  3828. hl('InvalidAssignmentWithAddition', '+=', 1),
  3829. hl('IdentifierName', 'b', 1),
  3830. })
  3831. check_parsing('a + b == c + d', {
  3832. -- 01234567890123
  3833. -- 0 1
  3834. ast = {
  3835. {
  3836. 'Comparison(type=Equal,inv=0,ccs=UseOption):0:5: ==',
  3837. children = {
  3838. {
  3839. 'BinaryPlus:0:1: +',
  3840. children = {
  3841. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3842. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  3843. },
  3844. },
  3845. {
  3846. 'BinaryPlus:0:10: +',
  3847. children = {
  3848. 'PlainIdentifier(scope=0,ident=c):0:8: c',
  3849. 'PlainIdentifier(scope=0,ident=d):0:12: d',
  3850. },
  3851. },
  3852. },
  3853. },
  3854. },
  3855. }, {
  3856. hl('IdentifierName', 'a'),
  3857. hl('BinaryPlus', '+', 1),
  3858. hl('IdentifierName', 'b', 1),
  3859. hl('Comparison', '==', 1),
  3860. hl('IdentifierName', 'c', 1),
  3861. hl('BinaryPlus', '+', 1),
  3862. hl('IdentifierName', 'd', 1),
  3863. })
  3864. check_parsing('+ a == + b', {
  3865. -- 0123456789
  3866. ast = {
  3867. {
  3868. 'Comparison(type=Equal,inv=0,ccs=UseOption):0:3: ==',
  3869. children = {
  3870. {
  3871. 'UnaryPlus:0:0:+',
  3872. children = {
  3873. 'PlainIdentifier(scope=0,ident=a):0:1: a',
  3874. },
  3875. },
  3876. {
  3877. 'UnaryPlus:0:6: +',
  3878. children = {
  3879. 'PlainIdentifier(scope=0,ident=b):0:8: b',
  3880. },
  3881. },
  3882. },
  3883. },
  3884. },
  3885. }, {
  3886. hl('UnaryPlus', '+'),
  3887. hl('IdentifierName', 'a', 1),
  3888. hl('Comparison', '==', 1),
  3889. hl('UnaryPlus', '+', 1),
  3890. hl('IdentifierName', 'b', 1),
  3891. })
  3892. end)
  3893. itp('works with concat/subscript', function()
  3894. check_parsing('.', {
  3895. -- 0
  3896. ast = {
  3897. {
  3898. 'ConcatOrSubscript:0:0:.',
  3899. children = {
  3900. 'Missing:0:0:',
  3901. },
  3902. },
  3903. },
  3904. err = {
  3905. arg = '.',
  3906. msg = 'E15: Unexpected dot: %.*s',
  3907. },
  3908. }, {
  3909. hl('InvalidConcatOrSubscript', '.'),
  3910. })
  3911. check_parsing('a.', {
  3912. -- 01
  3913. ast = {
  3914. {
  3915. 'ConcatOrSubscript:0:1:.',
  3916. children = {
  3917. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3918. },
  3919. },
  3920. },
  3921. err = {
  3922. arg = '',
  3923. msg = 'E15: Expected value, got EOC: %.*s',
  3924. },
  3925. }, {
  3926. hl('IdentifierName', 'a'),
  3927. hl('ConcatOrSubscript', '.'),
  3928. })
  3929. check_parsing('a.b', {
  3930. -- 012
  3931. ast = {
  3932. {
  3933. 'ConcatOrSubscript:0:1:.',
  3934. children = {
  3935. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3936. 'PlainKey(key=b):0:2:b',
  3937. },
  3938. },
  3939. },
  3940. }, {
  3941. hl('IdentifierName', 'a'),
  3942. hl('ConcatOrSubscript', '.'),
  3943. hl('IdentifierKey', 'b'),
  3944. })
  3945. check_parsing('1.2', {
  3946. -- 012
  3947. ast = {
  3948. 'Float(val=1.200000e+00):0:0:1.2',
  3949. },
  3950. }, {
  3951. hl('Float', '1.2'),
  3952. })
  3953. check_parsing('1.2 + 1.3e-5', {
  3954. -- 012345678901
  3955. -- 0 1
  3956. ast = {
  3957. {
  3958. 'BinaryPlus:0:3: +',
  3959. children = {
  3960. 'Float(val=1.200000e+00):0:0:1.2',
  3961. 'Float(val=1.300000e-05):0:5: 1.3e-5',
  3962. },
  3963. },
  3964. },
  3965. }, {
  3966. hl('Float', '1.2'),
  3967. hl('BinaryPlus', '+', 1),
  3968. hl('Float', '1.3e-5', 1),
  3969. })
  3970. check_parsing('a . 1.2 + 1.3e-5', {
  3971. -- 0123456789012345
  3972. -- 0 1
  3973. ast = {
  3974. {
  3975. 'BinaryPlus:0:7: +',
  3976. children = {
  3977. {
  3978. 'Concat:0:1: .',
  3979. children = {
  3980. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  3981. {
  3982. 'ConcatOrSubscript:0:5:.',
  3983. children = {
  3984. 'Integer(val=1):0:3: 1',
  3985. 'PlainKey(key=2):0:6:2',
  3986. },
  3987. },
  3988. },
  3989. },
  3990. 'Float(val=1.300000e-05):0:9: 1.3e-5',
  3991. },
  3992. },
  3993. },
  3994. }, {
  3995. hl('IdentifierName', 'a'),
  3996. hl('Concat', '.', 1),
  3997. hl('Number', '1', 1),
  3998. hl('ConcatOrSubscript', '.'),
  3999. hl('IdentifierKey', '2'),
  4000. hl('BinaryPlus', '+', 1),
  4001. hl('Float', '1.3e-5', 1),
  4002. })
  4003. check_parsing('1.3e-5 + 1.2 . a', {
  4004. -- 0123456789012345
  4005. -- 0 1
  4006. ast = {
  4007. {
  4008. 'Concat:0:12: .',
  4009. children = {
  4010. {
  4011. 'BinaryPlus:0:6: +',
  4012. children = {
  4013. 'Float(val=1.300000e-05):0:0:1.3e-5',
  4014. 'Float(val=1.200000e+00):0:8: 1.2',
  4015. },
  4016. },
  4017. 'PlainIdentifier(scope=0,ident=a):0:14: a',
  4018. },
  4019. },
  4020. },
  4021. }, {
  4022. hl('Float', '1.3e-5'),
  4023. hl('BinaryPlus', '+', 1),
  4024. hl('Float', '1.2', 1),
  4025. hl('Concat', '.', 1),
  4026. hl('IdentifierName', 'a', 1),
  4027. })
  4028. check_parsing('1.3e-5 + a . 1.2', {
  4029. -- 0123456789012345
  4030. -- 0 1
  4031. ast = {
  4032. {
  4033. 'Concat:0:10: .',
  4034. children = {
  4035. {
  4036. 'BinaryPlus:0:6: +',
  4037. children = {
  4038. 'Float(val=1.300000e-05):0:0:1.3e-5',
  4039. 'PlainIdentifier(scope=0,ident=a):0:8: a',
  4040. },
  4041. },
  4042. {
  4043. 'ConcatOrSubscript:0:14:.',
  4044. children = {
  4045. 'Integer(val=1):0:12: 1',
  4046. 'PlainKey(key=2):0:15:2',
  4047. },
  4048. },
  4049. },
  4050. },
  4051. },
  4052. }, {
  4053. hl('Float', '1.3e-5'),
  4054. hl('BinaryPlus', '+', 1),
  4055. hl('IdentifierName', 'a', 1),
  4056. hl('Concat', '.', 1),
  4057. hl('Number', '1', 1),
  4058. hl('ConcatOrSubscript', '.'),
  4059. hl('IdentifierKey', '2'),
  4060. })
  4061. check_parsing('1.2.3', {
  4062. -- 01234
  4063. ast = {
  4064. {
  4065. 'ConcatOrSubscript:0:3:.',
  4066. children = {
  4067. {
  4068. 'ConcatOrSubscript:0:1:.',
  4069. children = {
  4070. 'Integer(val=1):0:0:1',
  4071. 'PlainKey(key=2):0:2:2',
  4072. },
  4073. },
  4074. 'PlainKey(key=3):0:4:3',
  4075. },
  4076. },
  4077. },
  4078. }, {
  4079. hl('Number', '1'),
  4080. hl('ConcatOrSubscript', '.'),
  4081. hl('IdentifierKey', '2'),
  4082. hl('ConcatOrSubscript', '.'),
  4083. hl('IdentifierKey', '3'),
  4084. })
  4085. check_parsing('a.1.2', {
  4086. -- 01234
  4087. ast = {
  4088. {
  4089. 'ConcatOrSubscript:0:3:.',
  4090. children = {
  4091. {
  4092. 'ConcatOrSubscript:0:1:.',
  4093. children = {
  4094. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4095. 'PlainKey(key=1):0:2:1',
  4096. },
  4097. },
  4098. 'PlainKey(key=2):0:4:2',
  4099. },
  4100. },
  4101. },
  4102. }, {
  4103. hl('IdentifierName', 'a'),
  4104. hl('ConcatOrSubscript', '.'),
  4105. hl('IdentifierKey', '1'),
  4106. hl('ConcatOrSubscript', '.'),
  4107. hl('IdentifierKey', '2'),
  4108. })
  4109. check_parsing('a . 1.2', {
  4110. -- 0123456
  4111. ast = {
  4112. {
  4113. 'Concat:0:1: .',
  4114. children = {
  4115. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4116. {
  4117. 'ConcatOrSubscript:0:5:.',
  4118. children = {
  4119. 'Integer(val=1):0:3: 1',
  4120. 'PlainKey(key=2):0:6:2',
  4121. },
  4122. },
  4123. },
  4124. },
  4125. },
  4126. }, {
  4127. hl('IdentifierName', 'a'),
  4128. hl('Concat', '.', 1),
  4129. hl('Number', '1', 1),
  4130. hl('ConcatOrSubscript', '.'),
  4131. hl('IdentifierKey', '2'),
  4132. })
  4133. check_parsing('+a . +b', {
  4134. -- 0123456
  4135. ast = {
  4136. {
  4137. 'Concat:0:2: .',
  4138. children = {
  4139. {
  4140. 'UnaryPlus:0:0:+',
  4141. children = {
  4142. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  4143. },
  4144. },
  4145. {
  4146. 'UnaryPlus:0:4: +',
  4147. children = {
  4148. 'PlainIdentifier(scope=0,ident=b):0:6:b',
  4149. },
  4150. },
  4151. },
  4152. },
  4153. },
  4154. }, {
  4155. hl('UnaryPlus', '+'),
  4156. hl('IdentifierName', 'a'),
  4157. hl('Concat', '.', 1),
  4158. hl('UnaryPlus', '+', 1),
  4159. hl('IdentifierName', 'b'),
  4160. })
  4161. check_parsing('a. b', {
  4162. -- 0123
  4163. ast = {
  4164. {
  4165. 'Concat:0:1:.',
  4166. children = {
  4167. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4168. 'PlainIdentifier(scope=0,ident=b):0:2: b',
  4169. },
  4170. },
  4171. },
  4172. }, {
  4173. hl('IdentifierName', 'a'),
  4174. hl('ConcatOrSubscript', '.'),
  4175. hl('IdentifierName', 'b', 1),
  4176. })
  4177. check_parsing('a. 1', {
  4178. -- 0123
  4179. ast = {
  4180. {
  4181. 'Concat:0:1:.',
  4182. children = {
  4183. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4184. 'Integer(val=1):0:2: 1',
  4185. },
  4186. },
  4187. },
  4188. }, {
  4189. hl('IdentifierName', 'a'),
  4190. hl('ConcatOrSubscript', '.'),
  4191. hl('Number', '1', 1),
  4192. })
  4193. check_parsing('a[1][2][3[4', {
  4194. -- 01234567890
  4195. -- 0 1
  4196. ast = {
  4197. {
  4198. 'Subscript:0:7:[',
  4199. children = {
  4200. {
  4201. 'Subscript:0:4:[',
  4202. children = {
  4203. {
  4204. 'Subscript:0:1:[',
  4205. children = {
  4206. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4207. 'Integer(val=1):0:2:1',
  4208. },
  4209. },
  4210. 'Integer(val=2):0:5:2',
  4211. },
  4212. },
  4213. {
  4214. 'Subscript:0:9:[',
  4215. children = {
  4216. 'Integer(val=3):0:8:3',
  4217. 'Integer(val=4):0:10:4',
  4218. },
  4219. },
  4220. },
  4221. },
  4222. },
  4223. }, {
  4224. hl('IdentifierName', 'a'),
  4225. hl('SubscriptBracket', '['),
  4226. hl('Number', '1'),
  4227. hl('SubscriptBracket', ']'),
  4228. hl('SubscriptBracket', '['),
  4229. hl('Number', '2'),
  4230. hl('SubscriptBracket', ']'),
  4231. hl('SubscriptBracket', '['),
  4232. hl('Number', '3'),
  4233. hl('SubscriptBracket', '['),
  4234. hl('Number', '4'),
  4235. })
  4236. end)
  4237. itp('works with bracket subscripts', function()
  4238. check_parsing(':', {
  4239. -- 0
  4240. ast = {
  4241. {
  4242. 'Colon:0:0::',
  4243. children = {
  4244. 'Missing:0:0:',
  4245. },
  4246. },
  4247. },
  4248. err = {
  4249. arg = ':',
  4250. msg = 'E15: Colon outside of dictionary or ternary operator: %.*s',
  4251. },
  4252. }, {
  4253. hl('InvalidColon', ':'),
  4254. })
  4255. check_parsing('a[]', {
  4256. -- 012
  4257. ast = {
  4258. {
  4259. 'Subscript:0:1:[',
  4260. children = {
  4261. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4262. },
  4263. },
  4264. },
  4265. err = {
  4266. arg = ']',
  4267. msg = 'E15: Expected value, got closing bracket: %.*s',
  4268. },
  4269. }, {
  4270. hl('IdentifierName', 'a'),
  4271. hl('SubscriptBracket', '['),
  4272. hl('InvalidSubscriptBracket', ']'),
  4273. })
  4274. check_parsing('a[b:]', {
  4275. -- 01234
  4276. ast = {
  4277. {
  4278. 'Subscript:0:1:[',
  4279. children = {
  4280. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4281. 'PlainIdentifier(scope=b,ident=):0:2:b:',
  4282. },
  4283. },
  4284. },
  4285. }, {
  4286. hl('IdentifierName', 'a'),
  4287. hl('SubscriptBracket', '['),
  4288. hl('IdentifierScope', 'b'),
  4289. hl('IdentifierScopeDelimiter', ':'),
  4290. hl('SubscriptBracket', ']'),
  4291. })
  4292. check_parsing('a[b:c]', {
  4293. -- 012345
  4294. ast = {
  4295. {
  4296. 'Subscript:0:1:[',
  4297. children = {
  4298. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4299. 'PlainIdentifier(scope=b,ident=c):0:2:b:c',
  4300. },
  4301. },
  4302. },
  4303. }, {
  4304. hl('IdentifierName', 'a'),
  4305. hl('SubscriptBracket', '['),
  4306. hl('IdentifierScope', 'b'),
  4307. hl('IdentifierScopeDelimiter', ':'),
  4308. hl('IdentifierName', 'c'),
  4309. hl('SubscriptBracket', ']'),
  4310. })
  4311. check_parsing('a[b : c]', {
  4312. -- 01234567
  4313. ast = {
  4314. {
  4315. 'Subscript:0:1:[',
  4316. children = {
  4317. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4318. {
  4319. 'Colon:0:3: :',
  4320. children = {
  4321. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  4322. 'PlainIdentifier(scope=0,ident=c):0:5: c',
  4323. },
  4324. },
  4325. },
  4326. },
  4327. },
  4328. }, {
  4329. hl('IdentifierName', 'a'),
  4330. hl('SubscriptBracket', '['),
  4331. hl('IdentifierName', 'b'),
  4332. hl('SubscriptColon', ':', 1),
  4333. hl('IdentifierName', 'c', 1),
  4334. hl('SubscriptBracket', ']'),
  4335. })
  4336. check_parsing('a[: b]', {
  4337. -- 012345
  4338. ast = {
  4339. {
  4340. 'Subscript:0:1:[',
  4341. children = {
  4342. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4343. {
  4344. 'Colon:0:2::',
  4345. children = {
  4346. 'Missing:0:2:',
  4347. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  4348. },
  4349. },
  4350. },
  4351. },
  4352. },
  4353. }, {
  4354. hl('IdentifierName', 'a'),
  4355. hl('SubscriptBracket', '['),
  4356. hl('SubscriptColon', ':'),
  4357. hl('IdentifierName', 'b', 1),
  4358. hl('SubscriptBracket', ']'),
  4359. })
  4360. check_parsing('a[b :]', {
  4361. -- 012345
  4362. ast = {
  4363. {
  4364. 'Subscript:0:1:[',
  4365. children = {
  4366. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4367. {
  4368. 'Colon:0:3: :',
  4369. children = {
  4370. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  4371. },
  4372. },
  4373. },
  4374. },
  4375. },
  4376. }, {
  4377. hl('IdentifierName', 'a'),
  4378. hl('SubscriptBracket', '['),
  4379. hl('IdentifierName', 'b'),
  4380. hl('SubscriptColon', ':', 1),
  4381. hl('SubscriptBracket', ']'),
  4382. })
  4383. check_parsing('a[b][c][d](e)(f)(g)', {
  4384. -- 0123456789012345678
  4385. -- 0 1
  4386. ast = {
  4387. {
  4388. 'Call:0:16:(',
  4389. children = {
  4390. {
  4391. 'Call:0:13:(',
  4392. children = {
  4393. {
  4394. 'Call:0:10:(',
  4395. children = {
  4396. {
  4397. 'Subscript:0:7:[',
  4398. children = {
  4399. {
  4400. 'Subscript:0:4:[',
  4401. children = {
  4402. {
  4403. 'Subscript:0:1:[',
  4404. children = {
  4405. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4406. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  4407. },
  4408. },
  4409. 'PlainIdentifier(scope=0,ident=c):0:5:c',
  4410. },
  4411. },
  4412. 'PlainIdentifier(scope=0,ident=d):0:8:d',
  4413. },
  4414. },
  4415. 'PlainIdentifier(scope=0,ident=e):0:11:e',
  4416. },
  4417. },
  4418. 'PlainIdentifier(scope=0,ident=f):0:14:f',
  4419. },
  4420. },
  4421. 'PlainIdentifier(scope=0,ident=g):0:17:g',
  4422. },
  4423. },
  4424. },
  4425. }, {
  4426. hl('IdentifierName', 'a'),
  4427. hl('SubscriptBracket', '['),
  4428. hl('IdentifierName', 'b'),
  4429. hl('SubscriptBracket', ']'),
  4430. hl('SubscriptBracket', '['),
  4431. hl('IdentifierName', 'c'),
  4432. hl('SubscriptBracket', ']'),
  4433. hl('SubscriptBracket', '['),
  4434. hl('IdentifierName', 'd'),
  4435. hl('SubscriptBracket', ']'),
  4436. hl('CallingParenthesis', '('),
  4437. hl('IdentifierName', 'e'),
  4438. hl('CallingParenthesis', ')'),
  4439. hl('CallingParenthesis', '('),
  4440. hl('IdentifierName', 'f'),
  4441. hl('CallingParenthesis', ')'),
  4442. hl('CallingParenthesis', '('),
  4443. hl('IdentifierName', 'g'),
  4444. hl('CallingParenthesis', ')'),
  4445. })
  4446. check_parsing('{a}{b}{c}[d][e][f]', {
  4447. -- 012345678901234567
  4448. -- 0 1
  4449. ast = {
  4450. {
  4451. 'Subscript:0:15:[',
  4452. children = {
  4453. {
  4454. 'Subscript:0:12:[',
  4455. children = {
  4456. {
  4457. 'Subscript:0:9:[',
  4458. children = {
  4459. {
  4460. 'ComplexIdentifier:0:3:',
  4461. children = {
  4462. {
  4463. fmtn('CurlyBracesIdentifier', '-di', ':0:0:{'),
  4464. children = {
  4465. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  4466. },
  4467. },
  4468. {
  4469. 'ComplexIdentifier:0:6:',
  4470. children = {
  4471. {
  4472. fmtn('CurlyBracesIdentifier', '--i', ':0:3:{'),
  4473. children = {
  4474. 'PlainIdentifier(scope=0,ident=b):0:4:b',
  4475. },
  4476. },
  4477. {
  4478. fmtn('CurlyBracesIdentifier', '--i', ':0:6:{'),
  4479. children = {
  4480. 'PlainIdentifier(scope=0,ident=c):0:7:c',
  4481. },
  4482. },
  4483. },
  4484. },
  4485. },
  4486. },
  4487. 'PlainIdentifier(scope=0,ident=d):0:10:d',
  4488. },
  4489. },
  4490. 'PlainIdentifier(scope=0,ident=e):0:13:e',
  4491. },
  4492. },
  4493. 'PlainIdentifier(scope=0,ident=f):0:16:f',
  4494. },
  4495. },
  4496. },
  4497. }, {
  4498. hl('Curly', '{'),
  4499. hl('IdentifierName', 'a'),
  4500. hl('Curly', '}'),
  4501. hl('Curly', '{'),
  4502. hl('IdentifierName', 'b'),
  4503. hl('Curly', '}'),
  4504. hl('Curly', '{'),
  4505. hl('IdentifierName', 'c'),
  4506. hl('Curly', '}'),
  4507. hl('SubscriptBracket', '['),
  4508. hl('IdentifierName', 'd'),
  4509. hl('SubscriptBracket', ']'),
  4510. hl('SubscriptBracket', '['),
  4511. hl('IdentifierName', 'e'),
  4512. hl('SubscriptBracket', ']'),
  4513. hl('SubscriptBracket', '['),
  4514. hl('IdentifierName', 'f'),
  4515. hl('SubscriptBracket', ']'),
  4516. })
  4517. end)
  4518. itp('supports list literals', function()
  4519. check_parsing('[]', {
  4520. -- 01
  4521. ast = {
  4522. 'ListLiteral:0:0:[',
  4523. },
  4524. }, {
  4525. hl('List', '['),
  4526. hl('List', ']'),
  4527. })
  4528. check_parsing('[a]', {
  4529. -- 012
  4530. ast = {
  4531. {
  4532. 'ListLiteral:0:0:[',
  4533. children = {
  4534. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  4535. },
  4536. },
  4537. },
  4538. }, {
  4539. hl('List', '['),
  4540. hl('IdentifierName', 'a'),
  4541. hl('List', ']'),
  4542. })
  4543. check_parsing('[a, b]', {
  4544. -- 012345
  4545. ast = {
  4546. {
  4547. 'ListLiteral:0:0:[',
  4548. children = {
  4549. {
  4550. 'Comma:0:2:,',
  4551. children = {
  4552. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  4553. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  4554. },
  4555. },
  4556. },
  4557. },
  4558. },
  4559. }, {
  4560. hl('List', '['),
  4561. hl('IdentifierName', 'a'),
  4562. hl('Comma', ','),
  4563. hl('IdentifierName', 'b', 1),
  4564. hl('List', ']'),
  4565. })
  4566. check_parsing('[a, b, c]', {
  4567. -- 012345678
  4568. ast = {
  4569. {
  4570. 'ListLiteral:0:0:[',
  4571. children = {
  4572. {
  4573. 'Comma:0:2:,',
  4574. children = {
  4575. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  4576. {
  4577. 'Comma:0:5:,',
  4578. children = {
  4579. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  4580. 'PlainIdentifier(scope=0,ident=c):0:6: c',
  4581. },
  4582. },
  4583. },
  4584. },
  4585. },
  4586. },
  4587. },
  4588. }, {
  4589. hl('List', '['),
  4590. hl('IdentifierName', 'a'),
  4591. hl('Comma', ','),
  4592. hl('IdentifierName', 'b', 1),
  4593. hl('Comma', ','),
  4594. hl('IdentifierName', 'c', 1),
  4595. hl('List', ']'),
  4596. })
  4597. check_parsing('[a, b, c, ]', {
  4598. -- 01234567890
  4599. -- 0 1
  4600. ast = {
  4601. {
  4602. 'ListLiteral:0:0:[',
  4603. children = {
  4604. {
  4605. 'Comma:0:2:,',
  4606. children = {
  4607. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  4608. {
  4609. 'Comma:0:5:,',
  4610. children = {
  4611. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  4612. {
  4613. 'Comma:0:8:,',
  4614. children = {
  4615. 'PlainIdentifier(scope=0,ident=c):0:6: c',
  4616. },
  4617. },
  4618. },
  4619. },
  4620. },
  4621. },
  4622. },
  4623. },
  4624. },
  4625. }, {
  4626. hl('List', '['),
  4627. hl('IdentifierName', 'a'),
  4628. hl('Comma', ','),
  4629. hl('IdentifierName', 'b', 1),
  4630. hl('Comma', ','),
  4631. hl('IdentifierName', 'c', 1),
  4632. hl('Comma', ','),
  4633. hl('List', ']', 1),
  4634. })
  4635. check_parsing('[a : b, c : d]', {
  4636. -- 01234567890123
  4637. -- 0 1
  4638. ast = {
  4639. {
  4640. 'ListLiteral:0:0:[',
  4641. children = {
  4642. {
  4643. 'Comma:0:6:,',
  4644. children = {
  4645. {
  4646. 'Colon:0:2: :',
  4647. children = {
  4648. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  4649. 'PlainIdentifier(scope=0,ident=b):0:4: b',
  4650. },
  4651. },
  4652. {
  4653. 'Colon:0:9: :',
  4654. children = {
  4655. 'PlainIdentifier(scope=0,ident=c):0:7: c',
  4656. 'PlainIdentifier(scope=0,ident=d):0:11: d',
  4657. },
  4658. },
  4659. },
  4660. },
  4661. },
  4662. },
  4663. },
  4664. err = {
  4665. arg = ': b, c : d]',
  4666. msg = 'E15: Colon outside of dictionary or ternary operator: %.*s',
  4667. },
  4668. }, {
  4669. hl('List', '['),
  4670. hl('IdentifierName', 'a'),
  4671. hl('InvalidColon', ':', 1),
  4672. hl('IdentifierName', 'b', 1),
  4673. hl('Comma', ','),
  4674. hl('IdentifierName', 'c', 1),
  4675. hl('InvalidColon', ':', 1),
  4676. hl('IdentifierName', 'd', 1),
  4677. hl('List', ']'),
  4678. })
  4679. check_parsing(']', {
  4680. -- 0
  4681. ast = {
  4682. 'ListLiteral:0:0:',
  4683. },
  4684. err = {
  4685. arg = ']',
  4686. msg = 'E15: Unexpected closing figure brace: %.*s',
  4687. },
  4688. }, {
  4689. hl('InvalidList', ']'),
  4690. })
  4691. check_parsing('a]', {
  4692. -- 01
  4693. ast = {
  4694. {
  4695. 'ListLiteral:0:1:',
  4696. children = {
  4697. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  4698. },
  4699. },
  4700. },
  4701. err = {
  4702. arg = ']',
  4703. msg = 'E15: Unexpected closing figure brace: %.*s',
  4704. },
  4705. }, {
  4706. hl('IdentifierName', 'a'),
  4707. hl('InvalidList', ']'),
  4708. })
  4709. check_parsing('[] []', {
  4710. -- 01234
  4711. ast = {
  4712. {
  4713. 'OpMissing:0:2:',
  4714. children = {
  4715. 'ListLiteral:0:0:[',
  4716. 'ListLiteral:0:2: [',
  4717. },
  4718. },
  4719. },
  4720. err = {
  4721. arg = '[]',
  4722. msg = 'E15: Missing operator: %.*s',
  4723. },
  4724. }, {
  4725. hl('List', '['),
  4726. hl('List', ']'),
  4727. hl('InvalidSpacing', ' '),
  4728. hl('List', '['),
  4729. hl('List', ']'),
  4730. }, {
  4731. [1] = {
  4732. ast = {
  4733. len = 3,
  4734. err = REMOVE_THIS,
  4735. ast = {
  4736. 'ListLiteral:0:0:[',
  4737. },
  4738. },
  4739. hl_fs = {
  4740. [3] = REMOVE_THIS,
  4741. [4] = REMOVE_THIS,
  4742. [5] = REMOVE_THIS,
  4743. },
  4744. },
  4745. })
  4746. check_parsing('[][]', {
  4747. -- 0123
  4748. ast = {
  4749. {
  4750. 'Subscript:0:2:[',
  4751. children = {
  4752. 'ListLiteral:0:0:[',
  4753. },
  4754. },
  4755. },
  4756. err = {
  4757. arg = ']',
  4758. msg = 'E15: Expected value, got closing bracket: %.*s',
  4759. },
  4760. }, {
  4761. hl('List', '['),
  4762. hl('List', ']'),
  4763. hl('SubscriptBracket', '['),
  4764. hl('InvalidSubscriptBracket', ']'),
  4765. })
  4766. check_parsing('[', {
  4767. -- 0
  4768. ast = {
  4769. 'ListLiteral:0:0:[',
  4770. },
  4771. err = {
  4772. arg = '',
  4773. msg = 'E15: Expected value, got EOC: %.*s',
  4774. },
  4775. }, {
  4776. hl('List', '['),
  4777. })
  4778. check_parsing('[1', {
  4779. -- 01
  4780. ast = {
  4781. {
  4782. 'ListLiteral:0:0:[',
  4783. children = {
  4784. 'Integer(val=1):0:1:1',
  4785. },
  4786. },
  4787. },
  4788. err = {
  4789. arg = '[1',
  4790. msg = "E697: Missing end of List ']': %.*s",
  4791. },
  4792. }, {
  4793. hl('List', '['),
  4794. hl('Number', '1'),
  4795. })
  4796. end)
  4797. itp('works with strings', function()
  4798. check_parsing("'abc'", {
  4799. -- 01234
  4800. ast = {
  4801. fmtn('SingleQuotedString', 'val="abc"', ":0:0:'abc'"),
  4802. },
  4803. }, {
  4804. hl('SingleQuote', "'"),
  4805. hl('SingleQuotedBody', 'abc'),
  4806. hl('SingleQuote', "'"),
  4807. })
  4808. check_parsing('"abc"', {
  4809. -- 01234
  4810. ast = {
  4811. fmtn('DoubleQuotedString', 'val="abc"', ':0:0:"abc"'),
  4812. },
  4813. }, {
  4814. hl('DoubleQuote', '"'),
  4815. hl('DoubleQuotedBody', 'abc'),
  4816. hl('DoubleQuote', '"'),
  4817. })
  4818. check_parsing("''", {
  4819. -- 01
  4820. ast = {
  4821. fmtn('SingleQuotedString', 'val=NULL', ":0:0:''"),
  4822. },
  4823. }, {
  4824. hl('SingleQuote', "'"),
  4825. hl('SingleQuote', "'"),
  4826. })
  4827. check_parsing('""', {
  4828. -- 01
  4829. ast = {
  4830. fmtn('DoubleQuotedString', 'val=NULL', ':0:0:""'),
  4831. },
  4832. }, {
  4833. hl('DoubleQuote', '"'),
  4834. hl('DoubleQuote', '"'),
  4835. })
  4836. check_parsing('"', {
  4837. -- 0
  4838. ast = {
  4839. fmtn('DoubleQuotedString', 'val=NULL', ':0:0:"'),
  4840. },
  4841. err = {
  4842. arg = '"',
  4843. msg = 'E114: Missing double quote: %.*s',
  4844. },
  4845. }, {
  4846. hl('InvalidDoubleQuote', '"'),
  4847. })
  4848. check_parsing("'", {
  4849. -- 0
  4850. ast = {
  4851. fmtn('SingleQuotedString', 'val=NULL', ":0:0:'"),
  4852. },
  4853. err = {
  4854. arg = "'",
  4855. msg = 'E115: Missing single quote: %.*s',
  4856. },
  4857. }, {
  4858. hl('InvalidSingleQuote', "'"),
  4859. })
  4860. check_parsing('"a', {
  4861. -- 01
  4862. ast = {
  4863. fmtn('DoubleQuotedString', 'val="a"', ':0:0:"a'),
  4864. },
  4865. err = {
  4866. arg = '"a',
  4867. msg = 'E114: Missing double quote: %.*s',
  4868. },
  4869. }, {
  4870. hl('InvalidDoubleQuote', '"'),
  4871. hl('InvalidDoubleQuotedBody', 'a'),
  4872. })
  4873. check_parsing("'a", {
  4874. -- 01
  4875. ast = {
  4876. fmtn('SingleQuotedString', 'val="a"', ":0:0:'a"),
  4877. },
  4878. err = {
  4879. arg = "'a",
  4880. msg = 'E115: Missing single quote: %.*s',
  4881. },
  4882. }, {
  4883. hl('InvalidSingleQuote', "'"),
  4884. hl('InvalidSingleQuotedBody', 'a'),
  4885. })
  4886. check_parsing("'abc''def'", {
  4887. -- 0123456789
  4888. ast = {
  4889. fmtn('SingleQuotedString', 'val="abc\'def"', ":0:0:'abc''def'"),
  4890. },
  4891. }, {
  4892. hl('SingleQuote', "'"),
  4893. hl('SingleQuotedBody', 'abc'),
  4894. hl('SingleQuotedQuote', "''"),
  4895. hl('SingleQuotedBody', 'def'),
  4896. hl('SingleQuote', "'"),
  4897. })
  4898. check_parsing("'abc''", {
  4899. -- 012345
  4900. ast = {
  4901. fmtn('SingleQuotedString', 'val="abc\'"', ":0:0:'abc''"),
  4902. },
  4903. err = {
  4904. arg = "'abc''",
  4905. msg = 'E115: Missing single quote: %.*s',
  4906. },
  4907. }, {
  4908. hl('InvalidSingleQuote', "'"),
  4909. hl('InvalidSingleQuotedBody', 'abc'),
  4910. hl('InvalidSingleQuotedQuote', "''"),
  4911. })
  4912. check_parsing("''''''''", {
  4913. -- 01234567
  4914. ast = {
  4915. fmtn('SingleQuotedString', "val=\"'''\"", ":0:0:''''''''"),
  4916. },
  4917. }, {
  4918. hl('SingleQuote', "'"),
  4919. hl('SingleQuotedQuote', "''"),
  4920. hl('SingleQuotedQuote', "''"),
  4921. hl('SingleQuotedQuote', "''"),
  4922. hl('SingleQuote', "'"),
  4923. })
  4924. check_parsing("'''a''''bc'", {
  4925. -- 01234567890
  4926. -- 0 1
  4927. ast = {
  4928. fmtn('SingleQuotedString', "val=\"'a''bc\"", ":0:0:'''a''''bc'"),
  4929. },
  4930. }, {
  4931. hl('SingleQuote', "'"),
  4932. hl('SingleQuotedQuote', "''"),
  4933. hl('SingleQuotedBody', 'a'),
  4934. hl('SingleQuotedQuote', "''"),
  4935. hl('SingleQuotedQuote', "''"),
  4936. hl('SingleQuotedBody', 'bc'),
  4937. hl('SingleQuote', "'"),
  4938. })
  4939. check_parsing('"\\"\\"\\"\\""', {
  4940. -- 0123456789
  4941. ast = {
  4942. fmtn('DoubleQuotedString', 'val="\\"\\"\\"\\""', ':0:0:"\\"\\"\\"\\""'),
  4943. },
  4944. }, {
  4945. hl('DoubleQuote', '"'),
  4946. hl('DoubleQuotedEscape', '\\"'),
  4947. hl('DoubleQuotedEscape', '\\"'),
  4948. hl('DoubleQuotedEscape', '\\"'),
  4949. hl('DoubleQuotedEscape', '\\"'),
  4950. hl('DoubleQuote', '"'),
  4951. })
  4952. check_parsing('"abc\\"def\\"ghi\\"jkl\\"mno"', {
  4953. -- 0123456789012345678901234
  4954. -- 0 1 2
  4955. ast = {
  4956. fmtn(
  4957. 'DoubleQuotedString',
  4958. 'val="abc\\"def\\"ghi\\"jkl\\"mno"',
  4959. ':0:0:"abc\\"def\\"ghi\\"jkl\\"mno"'
  4960. ),
  4961. },
  4962. }, {
  4963. hl('DoubleQuote', '"'),
  4964. hl('DoubleQuotedBody', 'abc'),
  4965. hl('DoubleQuotedEscape', '\\"'),
  4966. hl('DoubleQuotedBody', 'def'),
  4967. hl('DoubleQuotedEscape', '\\"'),
  4968. hl('DoubleQuotedBody', 'ghi'),
  4969. hl('DoubleQuotedEscape', '\\"'),
  4970. hl('DoubleQuotedBody', 'jkl'),
  4971. hl('DoubleQuotedEscape', '\\"'),
  4972. hl('DoubleQuotedBody', 'mno'),
  4973. hl('DoubleQuote', '"'),
  4974. })
  4975. check_parsing('"\\b\\e\\f\\r\\t\\\\"', {
  4976. -- 0123456789012345
  4977. -- 0 1
  4978. ast = {
  4979. [[DoubleQuotedString(val="\008\027\012\r\t\\"):0:0:"\b\e\f\r\t\\"]],
  4980. },
  4981. }, {
  4982. hl('DoubleQuote', '"'),
  4983. hl('DoubleQuotedEscape', '\\b'),
  4984. hl('DoubleQuotedEscape', '\\e'),
  4985. hl('DoubleQuotedEscape', '\\f'),
  4986. hl('DoubleQuotedEscape', '\\r'),
  4987. hl('DoubleQuotedEscape', '\\t'),
  4988. hl('DoubleQuotedEscape', '\\\\'),
  4989. hl('DoubleQuote', '"'),
  4990. })
  4991. check_parsing('"\\n\n"', {
  4992. -- 01234
  4993. ast = {
  4994. fmtn('DoubleQuotedString', 'val="\\n\\n"', ':0:0:"\\n\n"'),
  4995. },
  4996. }, {
  4997. hl('DoubleQuote', '"'),
  4998. hl('DoubleQuotedEscape', '\\n'),
  4999. hl('DoubleQuotedBody', '\n'),
  5000. hl('DoubleQuote', '"'),
  5001. })
  5002. check_parsing('"\\x00"', {
  5003. -- 012345
  5004. ast = {
  5005. fmtn('DoubleQuotedString', 'val="\\000"', ':0:0:"\\x00"'),
  5006. },
  5007. }, {
  5008. hl('DoubleQuote', '"'),
  5009. hl('DoubleQuotedEscape', '\\x00'),
  5010. hl('DoubleQuote', '"'),
  5011. })
  5012. check_parsing('"\\xFF"', {
  5013. -- 012345
  5014. ast = {
  5015. fmtn('DoubleQuotedString', 'val="\255"', ':0:0:"\\xFF"'),
  5016. },
  5017. }, {
  5018. hl('DoubleQuote', '"'),
  5019. hl('DoubleQuotedEscape', '\\xFF'),
  5020. hl('DoubleQuote', '"'),
  5021. })
  5022. check_parsing('"\\xF"', {
  5023. -- 012345
  5024. ast = {
  5025. fmtn('DoubleQuotedString', 'val="\\015"', ':0:0:"\\xF"'),
  5026. },
  5027. }, {
  5028. hl('DoubleQuote', '"'),
  5029. hl('DoubleQuotedEscape', '\\xF'),
  5030. hl('DoubleQuote', '"'),
  5031. })
  5032. check_parsing('"\\u00AB"', {
  5033. -- 01234567
  5034. ast = {
  5035. fmtn('DoubleQuotedString', 'val="«"', ':0:0:"\\u00AB"'),
  5036. },
  5037. }, {
  5038. hl('DoubleQuote', '"'),
  5039. hl('DoubleQuotedEscape', '\\u00AB'),
  5040. hl('DoubleQuote', '"'),
  5041. })
  5042. check_parsing('"\\U000000AB"', {
  5043. -- 01234567
  5044. ast = {
  5045. fmtn('DoubleQuotedString', 'val="«"', ':0:0:"\\U000000AB"'),
  5046. },
  5047. }, {
  5048. hl('DoubleQuote', '"'),
  5049. hl('DoubleQuotedEscape', '\\U000000AB'),
  5050. hl('DoubleQuote', '"'),
  5051. })
  5052. check_parsing('"\\x"', {
  5053. -- 0123
  5054. ast = {
  5055. fmtn('DoubleQuotedString', 'val="x"', ':0:0:"\\x"'),
  5056. },
  5057. }, {
  5058. hl('DoubleQuote', '"'),
  5059. hl('DoubleQuotedUnknownEscape', '\\x'),
  5060. hl('DoubleQuote', '"'),
  5061. })
  5062. check_parsing('"\\x', {
  5063. -- 012
  5064. ast = {
  5065. fmtn('DoubleQuotedString', 'val="x"', ':0:0:"\\x'),
  5066. },
  5067. err = {
  5068. arg = '"\\x',
  5069. msg = 'E114: Missing double quote: %.*s',
  5070. },
  5071. }, {
  5072. hl('InvalidDoubleQuote', '"'),
  5073. hl('InvalidDoubleQuotedUnknownEscape', '\\x'),
  5074. })
  5075. check_parsing('"\\xF', {
  5076. -- 0123
  5077. ast = {
  5078. fmtn('DoubleQuotedString', 'val="\\015"', ':0:0:"\\xF'),
  5079. },
  5080. err = {
  5081. arg = '"\\xF',
  5082. msg = 'E114: Missing double quote: %.*s',
  5083. },
  5084. }, {
  5085. hl('InvalidDoubleQuote', '"'),
  5086. hl('InvalidDoubleQuotedEscape', '\\xF'),
  5087. })
  5088. check_parsing('"\\u"', {
  5089. -- 0123
  5090. ast = {
  5091. fmtn('DoubleQuotedString', 'val="u"', ':0:0:"\\u"'),
  5092. },
  5093. }, {
  5094. hl('DoubleQuote', '"'),
  5095. hl('DoubleQuotedUnknownEscape', '\\u'),
  5096. hl('DoubleQuote', '"'),
  5097. })
  5098. check_parsing('"\\u', {
  5099. -- 012
  5100. ast = {
  5101. fmtn('DoubleQuotedString', 'val="u"', ':0:0:"\\u'),
  5102. },
  5103. err = {
  5104. arg = '"\\u',
  5105. msg = 'E114: Missing double quote: %.*s',
  5106. },
  5107. }, {
  5108. hl('InvalidDoubleQuote', '"'),
  5109. hl('InvalidDoubleQuotedUnknownEscape', '\\u'),
  5110. })
  5111. check_parsing('"\\U', {
  5112. -- 012
  5113. ast = {
  5114. fmtn('DoubleQuotedString', 'val="U"', ':0:0:"\\U'),
  5115. },
  5116. err = {
  5117. arg = '"\\U',
  5118. msg = 'E114: Missing double quote: %.*s',
  5119. },
  5120. }, {
  5121. hl('InvalidDoubleQuote', '"'),
  5122. hl('InvalidDoubleQuotedUnknownEscape', '\\U'),
  5123. })
  5124. check_parsing('"\\U"', {
  5125. -- 0123
  5126. ast = {
  5127. fmtn('DoubleQuotedString', 'val="U"', ':0:0:"\\U"'),
  5128. },
  5129. }, {
  5130. hl('DoubleQuote', '"'),
  5131. hl('DoubleQuotedUnknownEscape', '\\U'),
  5132. hl('DoubleQuote', '"'),
  5133. })
  5134. check_parsing('"\\xFX"', {
  5135. -- 012345
  5136. ast = {
  5137. fmtn('DoubleQuotedString', 'val="\\015X"', ':0:0:"\\xFX"'),
  5138. },
  5139. }, {
  5140. hl('DoubleQuote', '"'),
  5141. hl('DoubleQuotedEscape', '\\xF'),
  5142. hl('DoubleQuotedBody', 'X'),
  5143. hl('DoubleQuote', '"'),
  5144. })
  5145. check_parsing('"\\XFX"', {
  5146. -- 012345
  5147. ast = {
  5148. fmtn('DoubleQuotedString', 'val="\\015X"', ':0:0:"\\XFX"'),
  5149. },
  5150. }, {
  5151. hl('DoubleQuote', '"'),
  5152. hl('DoubleQuotedEscape', '\\XF'),
  5153. hl('DoubleQuotedBody', 'X'),
  5154. hl('DoubleQuote', '"'),
  5155. })
  5156. check_parsing('"\\xX"', {
  5157. -- 01234
  5158. ast = {
  5159. fmtn('DoubleQuotedString', 'val="xX"', ':0:0:"\\xX"'),
  5160. },
  5161. }, {
  5162. hl('DoubleQuote', '"'),
  5163. hl('DoubleQuotedUnknownEscape', '\\x'),
  5164. hl('DoubleQuotedBody', 'X'),
  5165. hl('DoubleQuote', '"'),
  5166. })
  5167. check_parsing('"\\XX"', {
  5168. -- 01234
  5169. ast = {
  5170. fmtn('DoubleQuotedString', 'val="XX"', ':0:0:"\\XX"'),
  5171. },
  5172. }, {
  5173. hl('DoubleQuote', '"'),
  5174. hl('DoubleQuotedUnknownEscape', '\\X'),
  5175. hl('DoubleQuotedBody', 'X'),
  5176. hl('DoubleQuote', '"'),
  5177. })
  5178. check_parsing('"\\uX"', {
  5179. -- 01234
  5180. ast = {
  5181. fmtn('DoubleQuotedString', 'val="uX"', ':0:0:"\\uX"'),
  5182. },
  5183. }, {
  5184. hl('DoubleQuote', '"'),
  5185. hl('DoubleQuotedUnknownEscape', '\\u'),
  5186. hl('DoubleQuotedBody', 'X'),
  5187. hl('DoubleQuote', '"'),
  5188. })
  5189. check_parsing('"\\UX"', {
  5190. -- 01234
  5191. ast = {
  5192. fmtn('DoubleQuotedString', 'val="UX"', ':0:0:"\\UX"'),
  5193. },
  5194. }, {
  5195. hl('DoubleQuote', '"'),
  5196. hl('DoubleQuotedUnknownEscape', '\\U'),
  5197. hl('DoubleQuotedBody', 'X'),
  5198. hl('DoubleQuote', '"'),
  5199. })
  5200. check_parsing('"\\x0X"', {
  5201. -- 012345
  5202. ast = {
  5203. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\x0X"'),
  5204. },
  5205. }, {
  5206. hl('DoubleQuote', '"'),
  5207. hl('DoubleQuotedEscape', '\\x0'),
  5208. hl('DoubleQuotedBody', 'X'),
  5209. hl('DoubleQuote', '"'),
  5210. })
  5211. check_parsing('"\\X0X"', {
  5212. -- 012345
  5213. ast = {
  5214. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\X0X"'),
  5215. },
  5216. }, {
  5217. hl('DoubleQuote', '"'),
  5218. hl('DoubleQuotedEscape', '\\X0'),
  5219. hl('DoubleQuotedBody', 'X'),
  5220. hl('DoubleQuote', '"'),
  5221. })
  5222. check_parsing('"\\u0X"', {
  5223. -- 012345
  5224. ast = {
  5225. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\u0X"'),
  5226. },
  5227. }, {
  5228. hl('DoubleQuote', '"'),
  5229. hl('DoubleQuotedEscape', '\\u0'),
  5230. hl('DoubleQuotedBody', 'X'),
  5231. hl('DoubleQuote', '"'),
  5232. })
  5233. check_parsing('"\\U0X"', {
  5234. -- 012345
  5235. ast = {
  5236. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\U0X"'),
  5237. },
  5238. }, {
  5239. hl('DoubleQuote', '"'),
  5240. hl('DoubleQuotedEscape', '\\U0'),
  5241. hl('DoubleQuotedBody', 'X'),
  5242. hl('DoubleQuote', '"'),
  5243. })
  5244. check_parsing('"\\x00X"', {
  5245. -- 0123456
  5246. ast = {
  5247. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\x00X"'),
  5248. },
  5249. }, {
  5250. hl('DoubleQuote', '"'),
  5251. hl('DoubleQuotedEscape', '\\x00'),
  5252. hl('DoubleQuotedBody', 'X'),
  5253. hl('DoubleQuote', '"'),
  5254. })
  5255. check_parsing('"\\X00X"', {
  5256. -- 0123456
  5257. ast = {
  5258. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\X00X"'),
  5259. },
  5260. }, {
  5261. hl('DoubleQuote', '"'),
  5262. hl('DoubleQuotedEscape', '\\X00'),
  5263. hl('DoubleQuotedBody', 'X'),
  5264. hl('DoubleQuote', '"'),
  5265. })
  5266. check_parsing('"\\u00X"', {
  5267. -- 0123456
  5268. ast = {
  5269. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\u00X"'),
  5270. },
  5271. }, {
  5272. hl('DoubleQuote', '"'),
  5273. hl('DoubleQuotedEscape', '\\u00'),
  5274. hl('DoubleQuotedBody', 'X'),
  5275. hl('DoubleQuote', '"'),
  5276. })
  5277. check_parsing('"\\U00X"', {
  5278. -- 0123456
  5279. ast = {
  5280. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\U00X"'),
  5281. },
  5282. }, {
  5283. hl('DoubleQuote', '"'),
  5284. hl('DoubleQuotedEscape', '\\U00'),
  5285. hl('DoubleQuotedBody', 'X'),
  5286. hl('DoubleQuote', '"'),
  5287. })
  5288. check_parsing('"\\u000X"', {
  5289. -- 01234567
  5290. ast = {
  5291. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\u000X"'),
  5292. },
  5293. }, {
  5294. hl('DoubleQuote', '"'),
  5295. hl('DoubleQuotedEscape', '\\u000'),
  5296. hl('DoubleQuotedBody', 'X'),
  5297. hl('DoubleQuote', '"'),
  5298. })
  5299. check_parsing('"\\U000X"', {
  5300. -- 01234567
  5301. ast = {
  5302. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\U000X"'),
  5303. },
  5304. }, {
  5305. hl('DoubleQuote', '"'),
  5306. hl('DoubleQuotedEscape', '\\U000'),
  5307. hl('DoubleQuotedBody', 'X'),
  5308. hl('DoubleQuote', '"'),
  5309. })
  5310. check_parsing('"\\u0000X"', {
  5311. -- 012345678
  5312. ast = {
  5313. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\u0000X"'),
  5314. },
  5315. }, {
  5316. hl('DoubleQuote', '"'),
  5317. hl('DoubleQuotedEscape', '\\u0000'),
  5318. hl('DoubleQuotedBody', 'X'),
  5319. hl('DoubleQuote', '"'),
  5320. })
  5321. check_parsing('"\\U0000X"', {
  5322. -- 012345678
  5323. ast = {
  5324. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\U0000X"'),
  5325. },
  5326. }, {
  5327. hl('DoubleQuote', '"'),
  5328. hl('DoubleQuotedEscape', '\\U0000'),
  5329. hl('DoubleQuotedBody', 'X'),
  5330. hl('DoubleQuote', '"'),
  5331. })
  5332. check_parsing('"\\U00000X"', {
  5333. -- 0123456789
  5334. ast = {
  5335. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\U00000X"'),
  5336. },
  5337. }, {
  5338. hl('DoubleQuote', '"'),
  5339. hl('DoubleQuotedEscape', '\\U00000'),
  5340. hl('DoubleQuotedBody', 'X'),
  5341. hl('DoubleQuote', '"'),
  5342. })
  5343. check_parsing('"\\U000000X"', {
  5344. -- 01234567890
  5345. -- 0 1
  5346. ast = {
  5347. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\U000000X"'),
  5348. },
  5349. }, {
  5350. hl('DoubleQuote', '"'),
  5351. hl('DoubleQuotedEscape', '\\U000000'),
  5352. hl('DoubleQuotedBody', 'X'),
  5353. hl('DoubleQuote', '"'),
  5354. })
  5355. check_parsing('"\\U0000000X"', {
  5356. -- 012345678901
  5357. -- 0 1
  5358. ast = {
  5359. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\U0000000X"'),
  5360. },
  5361. }, {
  5362. hl('DoubleQuote', '"'),
  5363. hl('DoubleQuotedEscape', '\\U0000000'),
  5364. hl('DoubleQuotedBody', 'X'),
  5365. hl('DoubleQuote', '"'),
  5366. })
  5367. check_parsing('"\\U00000000X"', {
  5368. -- 0123456789012
  5369. -- 0 1
  5370. ast = {
  5371. fmtn('DoubleQuotedString', 'val="\\000X"', ':0:0:"\\U00000000X"'),
  5372. },
  5373. }, {
  5374. hl('DoubleQuote', '"'),
  5375. hl('DoubleQuotedEscape', '\\U00000000'),
  5376. hl('DoubleQuotedBody', 'X'),
  5377. hl('DoubleQuote', '"'),
  5378. })
  5379. check_parsing('"\\x000X"', {
  5380. -- 01234567
  5381. ast = {
  5382. fmtn('DoubleQuotedString', 'val="\\0000X"', ':0:0:"\\x000X"'),
  5383. },
  5384. }, {
  5385. hl('DoubleQuote', '"'),
  5386. hl('DoubleQuotedEscape', '\\x00'),
  5387. hl('DoubleQuotedBody', '0X'),
  5388. hl('DoubleQuote', '"'),
  5389. })
  5390. check_parsing('"\\X000X"', {
  5391. -- 01234567
  5392. ast = {
  5393. fmtn('DoubleQuotedString', 'val="\\0000X"', ':0:0:"\\X000X"'),
  5394. },
  5395. }, {
  5396. hl('DoubleQuote', '"'),
  5397. hl('DoubleQuotedEscape', '\\X00'),
  5398. hl('DoubleQuotedBody', '0X'),
  5399. hl('DoubleQuote', '"'),
  5400. })
  5401. check_parsing('"\\u00000X"', {
  5402. -- 0123456789
  5403. ast = {
  5404. fmtn('DoubleQuotedString', 'val="\\0000X"', ':0:0:"\\u00000X"'),
  5405. },
  5406. }, {
  5407. hl('DoubleQuote', '"'),
  5408. hl('DoubleQuotedEscape', '\\u0000'),
  5409. hl('DoubleQuotedBody', '0X'),
  5410. hl('DoubleQuote', '"'),
  5411. })
  5412. check_parsing('"\\U000000000X"', {
  5413. -- 01234567890123
  5414. -- 0 1
  5415. ast = {
  5416. fmtn('DoubleQuotedString', 'val="\\0000X"', ':0:0:"\\U000000000X"'),
  5417. },
  5418. }, {
  5419. hl('DoubleQuote', '"'),
  5420. hl('DoubleQuotedEscape', '\\U00000000'),
  5421. hl('DoubleQuotedBody', '0X'),
  5422. hl('DoubleQuote', '"'),
  5423. })
  5424. check_parsing('"\\0"', {
  5425. -- 0123
  5426. ast = {
  5427. fmtn('DoubleQuotedString', 'val="\\000"', ':0:0:"\\0"'),
  5428. },
  5429. }, {
  5430. hl('DoubleQuote', '"'),
  5431. hl('DoubleQuotedEscape', '\\0'),
  5432. hl('DoubleQuote', '"'),
  5433. })
  5434. check_parsing('"\\00"', {
  5435. -- 01234
  5436. ast = {
  5437. fmtn('DoubleQuotedString', 'val="\\000"', ':0:0:"\\00"'),
  5438. },
  5439. }, {
  5440. hl('DoubleQuote', '"'),
  5441. hl('DoubleQuotedEscape', '\\00'),
  5442. hl('DoubleQuote', '"'),
  5443. })
  5444. check_parsing('"\\000"', {
  5445. -- 012345
  5446. ast = {
  5447. fmtn('DoubleQuotedString', 'val="\\000"', ':0:0:"\\000"'),
  5448. },
  5449. }, {
  5450. hl('DoubleQuote', '"'),
  5451. hl('DoubleQuotedEscape', '\\000'),
  5452. hl('DoubleQuote', '"'),
  5453. })
  5454. check_parsing('"\\0000"', {
  5455. -- 0123456
  5456. ast = {
  5457. fmtn('DoubleQuotedString', 'val="\\0000"', ':0:0:"\\0000"'),
  5458. },
  5459. }, {
  5460. hl('DoubleQuote', '"'),
  5461. hl('DoubleQuotedEscape', '\\000'),
  5462. hl('DoubleQuotedBody', '0'),
  5463. hl('DoubleQuote', '"'),
  5464. })
  5465. check_parsing('"\\8"', {
  5466. -- 0123
  5467. ast = {
  5468. fmtn('DoubleQuotedString', 'val="8"', ':0:0:"\\8"'),
  5469. },
  5470. }, {
  5471. hl('DoubleQuote', '"'),
  5472. hl('DoubleQuotedUnknownEscape', '\\8'),
  5473. hl('DoubleQuote', '"'),
  5474. })
  5475. check_parsing('"\\08"', {
  5476. -- 01234
  5477. ast = {
  5478. fmtn('DoubleQuotedString', 'val="\\0008"', ':0:0:"\\08"'),
  5479. },
  5480. }, {
  5481. hl('DoubleQuote', '"'),
  5482. hl('DoubleQuotedEscape', '\\0'),
  5483. hl('DoubleQuotedBody', '8'),
  5484. hl('DoubleQuote', '"'),
  5485. })
  5486. check_parsing('"\\008"', {
  5487. -- 012345
  5488. ast = {
  5489. fmtn('DoubleQuotedString', 'val="\\0008"', ':0:0:"\\008"'),
  5490. },
  5491. }, {
  5492. hl('DoubleQuote', '"'),
  5493. hl('DoubleQuotedEscape', '\\00'),
  5494. hl('DoubleQuotedBody', '8'),
  5495. hl('DoubleQuote', '"'),
  5496. })
  5497. check_parsing('"\\0008"', {
  5498. -- 0123456
  5499. ast = {
  5500. fmtn('DoubleQuotedString', 'val="\\0008"', ':0:0:"\\0008"'),
  5501. },
  5502. }, {
  5503. hl('DoubleQuote', '"'),
  5504. hl('DoubleQuotedEscape', '\\000'),
  5505. hl('DoubleQuotedBody', '8'),
  5506. hl('DoubleQuote', '"'),
  5507. })
  5508. check_parsing('"\\777"', {
  5509. -- 012345
  5510. ast = {
  5511. fmtn('DoubleQuotedString', 'val="\255"', ':0:0:"\\777"'),
  5512. },
  5513. }, {
  5514. hl('DoubleQuote', '"'),
  5515. hl('DoubleQuotedEscape', '\\777'),
  5516. hl('DoubleQuote', '"'),
  5517. })
  5518. check_parsing('"\\050"', {
  5519. -- 012345
  5520. ast = {
  5521. fmtn('DoubleQuotedString', 'val="\40"', ':0:0:"\\050"'),
  5522. },
  5523. }, {
  5524. hl('DoubleQuote', '"'),
  5525. hl('DoubleQuotedEscape', '\\050'),
  5526. hl('DoubleQuote', '"'),
  5527. })
  5528. check_parsing('"\\<C-u>"', {
  5529. -- 012345
  5530. ast = {
  5531. fmtn('DoubleQuotedString', 'val="\\021"', ':0:0:"\\<C-u>"'),
  5532. },
  5533. }, {
  5534. hl('DoubleQuote', '"'),
  5535. hl('DoubleQuotedEscape', '\\<C-u>'),
  5536. hl('DoubleQuote', '"'),
  5537. })
  5538. check_parsing('"\\<', {
  5539. -- 012
  5540. ast = {
  5541. fmtn('DoubleQuotedString', 'val="<"', ':0:0:"\\<'),
  5542. },
  5543. err = {
  5544. arg = '"\\<',
  5545. msg = 'E114: Missing double quote: %.*s',
  5546. },
  5547. }, {
  5548. hl('InvalidDoubleQuote', '"'),
  5549. hl('InvalidDoubleQuotedUnknownEscape', '\\<'),
  5550. })
  5551. check_parsing('"\\<"', {
  5552. -- 0123
  5553. ast = {
  5554. fmtn('DoubleQuotedString', 'val="<"', ':0:0:"\\<"'),
  5555. },
  5556. }, {
  5557. hl('DoubleQuote', '"'),
  5558. hl('DoubleQuotedUnknownEscape', '\\<'),
  5559. hl('DoubleQuote', '"'),
  5560. })
  5561. check_parsing('"\\<C-u"', {
  5562. -- 0123456
  5563. ast = {
  5564. fmtn('DoubleQuotedString', 'val="<C-u"', ':0:0:"\\<C-u"'),
  5565. },
  5566. }, {
  5567. hl('DoubleQuote', '"'),
  5568. hl('DoubleQuotedUnknownEscape', '\\<'),
  5569. hl('DoubleQuotedBody', 'C-u'),
  5570. hl('DoubleQuote', '"'),
  5571. })
  5572. end)
  5573. itp('works with multiplication-like operators', function()
  5574. check_parsing('2+2*2', {
  5575. -- 01234
  5576. ast = {
  5577. {
  5578. 'BinaryPlus:0:1:+',
  5579. children = {
  5580. 'Integer(val=2):0:0:2',
  5581. {
  5582. 'Multiplication:0:3:*',
  5583. children = {
  5584. 'Integer(val=2):0:2:2',
  5585. 'Integer(val=2):0:4:2',
  5586. },
  5587. },
  5588. },
  5589. },
  5590. },
  5591. }, {
  5592. hl('Number', '2'),
  5593. hl('BinaryPlus', '+'),
  5594. hl('Number', '2'),
  5595. hl('Multiplication', '*'),
  5596. hl('Number', '2'),
  5597. })
  5598. check_parsing('2+2*', {
  5599. -- 0123
  5600. ast = {
  5601. {
  5602. 'BinaryPlus:0:1:+',
  5603. children = {
  5604. 'Integer(val=2):0:0:2',
  5605. {
  5606. 'Multiplication:0:3:*',
  5607. children = {
  5608. 'Integer(val=2):0:2:2',
  5609. },
  5610. },
  5611. },
  5612. },
  5613. },
  5614. err = {
  5615. arg = '',
  5616. msg = 'E15: Expected value, got EOC: %.*s',
  5617. },
  5618. }, {
  5619. hl('Number', '2'),
  5620. hl('BinaryPlus', '+'),
  5621. hl('Number', '2'),
  5622. hl('Multiplication', '*'),
  5623. })
  5624. check_parsing('2+*2', {
  5625. -- 0123
  5626. ast = {
  5627. {
  5628. 'BinaryPlus:0:1:+',
  5629. children = {
  5630. 'Integer(val=2):0:0:2',
  5631. {
  5632. 'Multiplication:0:2:*',
  5633. children = {
  5634. 'Missing:0:2:',
  5635. 'Integer(val=2):0:3:2',
  5636. },
  5637. },
  5638. },
  5639. },
  5640. },
  5641. err = {
  5642. arg = '*2',
  5643. msg = 'E15: Unexpected multiplication-like operator: %.*s',
  5644. },
  5645. }, {
  5646. hl('Number', '2'),
  5647. hl('BinaryPlus', '+'),
  5648. hl('InvalidMultiplication', '*'),
  5649. hl('Number', '2'),
  5650. })
  5651. check_parsing('2+2/2', {
  5652. -- 01234
  5653. ast = {
  5654. {
  5655. 'BinaryPlus:0:1:+',
  5656. children = {
  5657. 'Integer(val=2):0:0:2',
  5658. {
  5659. 'Division:0:3:/',
  5660. children = {
  5661. 'Integer(val=2):0:2:2',
  5662. 'Integer(val=2):0:4:2',
  5663. },
  5664. },
  5665. },
  5666. },
  5667. },
  5668. }, {
  5669. hl('Number', '2'),
  5670. hl('BinaryPlus', '+'),
  5671. hl('Number', '2'),
  5672. hl('Division', '/'),
  5673. hl('Number', '2'),
  5674. })
  5675. check_parsing('2+2/', {
  5676. -- 0123
  5677. ast = {
  5678. {
  5679. 'BinaryPlus:0:1:+',
  5680. children = {
  5681. 'Integer(val=2):0:0:2',
  5682. {
  5683. 'Division:0:3:/',
  5684. children = {
  5685. 'Integer(val=2):0:2:2',
  5686. },
  5687. },
  5688. },
  5689. },
  5690. },
  5691. err = {
  5692. arg = '',
  5693. msg = 'E15: Expected value, got EOC: %.*s',
  5694. },
  5695. }, {
  5696. hl('Number', '2'),
  5697. hl('BinaryPlus', '+'),
  5698. hl('Number', '2'),
  5699. hl('Division', '/'),
  5700. })
  5701. check_parsing('2+/2', {
  5702. -- 0123
  5703. ast = {
  5704. {
  5705. 'BinaryPlus:0:1:+',
  5706. children = {
  5707. 'Integer(val=2):0:0:2',
  5708. {
  5709. 'Division:0:2:/',
  5710. children = {
  5711. 'Missing:0:2:',
  5712. 'Integer(val=2):0:3:2',
  5713. },
  5714. },
  5715. },
  5716. },
  5717. },
  5718. err = {
  5719. arg = '/2',
  5720. msg = 'E15: Unexpected multiplication-like operator: %.*s',
  5721. },
  5722. }, {
  5723. hl('Number', '2'),
  5724. hl('BinaryPlus', '+'),
  5725. hl('InvalidDivision', '/'),
  5726. hl('Number', '2'),
  5727. })
  5728. check_parsing('2+2%2', {
  5729. -- 01234
  5730. ast = {
  5731. {
  5732. 'BinaryPlus:0:1:+',
  5733. children = {
  5734. 'Integer(val=2):0:0:2',
  5735. {
  5736. 'Mod:0:3:%',
  5737. children = {
  5738. 'Integer(val=2):0:2:2',
  5739. 'Integer(val=2):0:4:2',
  5740. },
  5741. },
  5742. },
  5743. },
  5744. },
  5745. }, {
  5746. hl('Number', '2'),
  5747. hl('BinaryPlus', '+'),
  5748. hl('Number', '2'),
  5749. hl('Mod', '%'),
  5750. hl('Number', '2'),
  5751. })
  5752. check_parsing('2+2%', {
  5753. -- 0123
  5754. ast = {
  5755. {
  5756. 'BinaryPlus:0:1:+',
  5757. children = {
  5758. 'Integer(val=2):0:0:2',
  5759. {
  5760. 'Mod:0:3:%',
  5761. children = {
  5762. 'Integer(val=2):0:2:2',
  5763. },
  5764. },
  5765. },
  5766. },
  5767. },
  5768. err = {
  5769. arg = '',
  5770. msg = 'E15: Expected value, got EOC: %.*s',
  5771. },
  5772. }, {
  5773. hl('Number', '2'),
  5774. hl('BinaryPlus', '+'),
  5775. hl('Number', '2'),
  5776. hl('Mod', '%'),
  5777. })
  5778. check_parsing('2+%2', {
  5779. -- 0123
  5780. ast = {
  5781. {
  5782. 'BinaryPlus:0:1:+',
  5783. children = {
  5784. 'Integer(val=2):0:0:2',
  5785. {
  5786. 'Mod:0:2:%',
  5787. children = {
  5788. 'Missing:0:2:',
  5789. 'Integer(val=2):0:3:2',
  5790. },
  5791. },
  5792. },
  5793. },
  5794. },
  5795. err = {
  5796. arg = '%2',
  5797. msg = 'E15: Unexpected multiplication-like operator: %.*s',
  5798. },
  5799. }, {
  5800. hl('Number', '2'),
  5801. hl('BinaryPlus', '+'),
  5802. hl('InvalidMod', '%'),
  5803. hl('Number', '2'),
  5804. })
  5805. end)
  5806. itp('works with -', function()
  5807. check_parsing('@a', {
  5808. ast = {
  5809. 'Register(name=a):0:0:@a',
  5810. },
  5811. }, {
  5812. hl('Register', '@a'),
  5813. })
  5814. check_parsing('-@a', {
  5815. ast = {
  5816. {
  5817. 'UnaryMinus:0:0:-',
  5818. children = {
  5819. 'Register(name=a):0:1:@a',
  5820. },
  5821. },
  5822. },
  5823. }, {
  5824. hl('UnaryMinus', '-'),
  5825. hl('Register', '@a'),
  5826. })
  5827. check_parsing('@a-@b', {
  5828. ast = {
  5829. {
  5830. 'BinaryMinus:0:2:-',
  5831. children = {
  5832. 'Register(name=a):0:0:@a',
  5833. 'Register(name=b):0:3:@b',
  5834. },
  5835. },
  5836. },
  5837. }, {
  5838. hl('Register', '@a'),
  5839. hl('BinaryMinus', '-'),
  5840. hl('Register', '@b'),
  5841. })
  5842. check_parsing('@a-@b-@c', {
  5843. ast = {
  5844. {
  5845. 'BinaryMinus:0:5:-',
  5846. children = {
  5847. {
  5848. 'BinaryMinus:0:2:-',
  5849. children = {
  5850. 'Register(name=a):0:0:@a',
  5851. 'Register(name=b):0:3:@b',
  5852. },
  5853. },
  5854. 'Register(name=c):0:6:@c',
  5855. },
  5856. },
  5857. },
  5858. }, {
  5859. hl('Register', '@a'),
  5860. hl('BinaryMinus', '-'),
  5861. hl('Register', '@b'),
  5862. hl('BinaryMinus', '-'),
  5863. hl('Register', '@c'),
  5864. })
  5865. check_parsing('-@a-@b', {
  5866. ast = {
  5867. {
  5868. 'BinaryMinus:0:3:-',
  5869. children = {
  5870. {
  5871. 'UnaryMinus:0:0:-',
  5872. children = {
  5873. 'Register(name=a):0:1:@a',
  5874. },
  5875. },
  5876. 'Register(name=b):0:4:@b',
  5877. },
  5878. },
  5879. },
  5880. }, {
  5881. hl('UnaryMinus', '-'),
  5882. hl('Register', '@a'),
  5883. hl('BinaryMinus', '-'),
  5884. hl('Register', '@b'),
  5885. })
  5886. check_parsing('-@a--@b', {
  5887. ast = {
  5888. {
  5889. 'BinaryMinus:0:3:-',
  5890. children = {
  5891. {
  5892. 'UnaryMinus:0:0:-',
  5893. children = {
  5894. 'Register(name=a):0:1:@a',
  5895. },
  5896. },
  5897. {
  5898. 'UnaryMinus:0:4:-',
  5899. children = {
  5900. 'Register(name=b):0:5:@b',
  5901. },
  5902. },
  5903. },
  5904. },
  5905. },
  5906. }, {
  5907. hl('UnaryMinus', '-'),
  5908. hl('Register', '@a'),
  5909. hl('BinaryMinus', '-'),
  5910. hl('UnaryMinus', '-'),
  5911. hl('Register', '@b'),
  5912. })
  5913. check_parsing('-', {
  5914. ast = {
  5915. 'UnaryMinus:0:0:-',
  5916. },
  5917. err = {
  5918. arg = '',
  5919. msg = 'E15: Expected value, got EOC: %.*s',
  5920. },
  5921. }, {
  5922. hl('UnaryMinus', '-'),
  5923. })
  5924. check_parsing(' -', {
  5925. ast = {
  5926. 'UnaryMinus:0:0: -',
  5927. },
  5928. err = {
  5929. arg = '',
  5930. msg = 'E15: Expected value, got EOC: %.*s',
  5931. },
  5932. }, {
  5933. hl('UnaryMinus', '-', 1),
  5934. })
  5935. check_parsing('@a- ', {
  5936. ast = {
  5937. {
  5938. 'BinaryMinus:0:2:-',
  5939. children = {
  5940. 'Register(name=a):0:0:@a',
  5941. },
  5942. },
  5943. },
  5944. err = {
  5945. arg = '',
  5946. msg = 'E15: Expected value, got EOC: %.*s',
  5947. },
  5948. }, {
  5949. hl('Register', '@a'),
  5950. hl('BinaryMinus', '-'),
  5951. })
  5952. end)
  5953. itp('works with logical operators', function()
  5954. check_parsing('a && b || c && d', {
  5955. -- 0123456789012345
  5956. -- 0 1
  5957. ast = {
  5958. {
  5959. 'Or:0:6: ||',
  5960. children = {
  5961. {
  5962. 'And:0:1: &&',
  5963. children = {
  5964. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  5965. 'PlainIdentifier(scope=0,ident=b):0:4: b',
  5966. },
  5967. },
  5968. {
  5969. 'And:0:11: &&',
  5970. children = {
  5971. 'PlainIdentifier(scope=0,ident=c):0:9: c',
  5972. 'PlainIdentifier(scope=0,ident=d):0:14: d',
  5973. },
  5974. },
  5975. },
  5976. },
  5977. },
  5978. }, {
  5979. hl('IdentifierName', 'a'),
  5980. hl('And', '&&', 1),
  5981. hl('IdentifierName', 'b', 1),
  5982. hl('Or', '||', 1),
  5983. hl('IdentifierName', 'c', 1),
  5984. hl('And', '&&', 1),
  5985. hl('IdentifierName', 'd', 1),
  5986. })
  5987. check_parsing('&& a', {
  5988. -- 0123
  5989. ast = {
  5990. {
  5991. 'And:0:0:&&',
  5992. children = {
  5993. 'Missing:0:0:',
  5994. 'PlainIdentifier(scope=0,ident=a):0:2: a',
  5995. },
  5996. },
  5997. },
  5998. err = {
  5999. arg = '&& a',
  6000. msg = 'E15: Unexpected and operator: %.*s',
  6001. },
  6002. }, {
  6003. hl('InvalidAnd', '&&'),
  6004. hl('IdentifierName', 'a', 1),
  6005. })
  6006. check_parsing('|| a', {
  6007. -- 0123
  6008. ast = {
  6009. {
  6010. 'Or:0:0:||',
  6011. children = {
  6012. 'Missing:0:0:',
  6013. 'PlainIdentifier(scope=0,ident=a):0:2: a',
  6014. },
  6015. },
  6016. },
  6017. err = {
  6018. arg = '|| a',
  6019. msg = 'E15: Unexpected or operator: %.*s',
  6020. },
  6021. }, {
  6022. hl('InvalidOr', '||'),
  6023. hl('IdentifierName', 'a', 1),
  6024. })
  6025. check_parsing('a||', {
  6026. -- 012
  6027. ast = {
  6028. {
  6029. 'Or:0:1:||',
  6030. children = {
  6031. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  6032. },
  6033. },
  6034. },
  6035. err = {
  6036. arg = '',
  6037. msg = 'E15: Expected value, got EOC: %.*s',
  6038. },
  6039. }, {
  6040. hl('IdentifierName', 'a'),
  6041. hl('Or', '||'),
  6042. })
  6043. check_parsing('a&&', {
  6044. -- 012
  6045. ast = {
  6046. {
  6047. 'And:0:1:&&',
  6048. children = {
  6049. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  6050. },
  6051. },
  6052. },
  6053. err = {
  6054. arg = '',
  6055. msg = 'E15: Expected value, got EOC: %.*s',
  6056. },
  6057. }, {
  6058. hl('IdentifierName', 'a'),
  6059. hl('And', '&&'),
  6060. })
  6061. check_parsing('(&&)', {
  6062. -- 0123
  6063. ast = {
  6064. {
  6065. 'Nested:0:0:(',
  6066. children = {
  6067. {
  6068. 'And:0:1:&&',
  6069. children = {
  6070. 'Missing:0:1:',
  6071. 'Missing:0:3:',
  6072. },
  6073. },
  6074. },
  6075. },
  6076. },
  6077. err = {
  6078. arg = '&&)',
  6079. msg = 'E15: Unexpected and operator: %.*s',
  6080. },
  6081. }, {
  6082. hl('NestingParenthesis', '('),
  6083. hl('InvalidAnd', '&&'),
  6084. hl('InvalidNestingParenthesis', ')'),
  6085. })
  6086. check_parsing('(||)', {
  6087. -- 0123
  6088. ast = {
  6089. {
  6090. 'Nested:0:0:(',
  6091. children = {
  6092. {
  6093. 'Or:0:1:||',
  6094. children = {
  6095. 'Missing:0:1:',
  6096. 'Missing:0:3:',
  6097. },
  6098. },
  6099. },
  6100. },
  6101. },
  6102. err = {
  6103. arg = '||)',
  6104. msg = 'E15: Unexpected or operator: %.*s',
  6105. },
  6106. }, {
  6107. hl('NestingParenthesis', '('),
  6108. hl('InvalidOr', '||'),
  6109. hl('InvalidNestingParenthesis', ')'),
  6110. })
  6111. check_parsing('(a||)', {
  6112. -- 01234
  6113. ast = {
  6114. {
  6115. 'Nested:0:0:(',
  6116. children = {
  6117. {
  6118. 'Or:0:2:||',
  6119. children = {
  6120. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  6121. 'Missing:0:4:',
  6122. },
  6123. },
  6124. },
  6125. },
  6126. },
  6127. err = {
  6128. arg = ')',
  6129. msg = 'E15: Expected value, got parenthesis: %.*s',
  6130. },
  6131. }, {
  6132. hl('NestingParenthesis', '('),
  6133. hl('IdentifierName', 'a'),
  6134. hl('Or', '||'),
  6135. hl('InvalidNestingParenthesis', ')'),
  6136. })
  6137. check_parsing('(a&&)', {
  6138. -- 01234
  6139. ast = {
  6140. {
  6141. 'Nested:0:0:(',
  6142. children = {
  6143. {
  6144. 'And:0:2:&&',
  6145. children = {
  6146. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  6147. 'Missing:0:4:',
  6148. },
  6149. },
  6150. },
  6151. },
  6152. },
  6153. err = {
  6154. arg = ')',
  6155. msg = 'E15: Expected value, got parenthesis: %.*s',
  6156. },
  6157. }, {
  6158. hl('NestingParenthesis', '('),
  6159. hl('IdentifierName', 'a'),
  6160. hl('And', '&&'),
  6161. hl('InvalidNestingParenthesis', ')'),
  6162. })
  6163. check_parsing('(&&a)', {
  6164. -- 01234
  6165. ast = {
  6166. {
  6167. 'Nested:0:0:(',
  6168. children = {
  6169. {
  6170. 'And:0:1:&&',
  6171. children = {
  6172. 'Missing:0:1:',
  6173. 'PlainIdentifier(scope=0,ident=a):0:3:a',
  6174. },
  6175. },
  6176. },
  6177. },
  6178. },
  6179. err = {
  6180. arg = '&&a)',
  6181. msg = 'E15: Unexpected and operator: %.*s',
  6182. },
  6183. }, {
  6184. hl('NestingParenthesis', '('),
  6185. hl('InvalidAnd', '&&'),
  6186. hl('IdentifierName', 'a'),
  6187. hl('NestingParenthesis', ')'),
  6188. })
  6189. check_parsing('(||a)', {
  6190. -- 01234
  6191. ast = {
  6192. {
  6193. 'Nested:0:0:(',
  6194. children = {
  6195. {
  6196. 'Or:0:1:||',
  6197. children = {
  6198. 'Missing:0:1:',
  6199. 'PlainIdentifier(scope=0,ident=a):0:3:a',
  6200. },
  6201. },
  6202. },
  6203. },
  6204. },
  6205. err = {
  6206. arg = '||a)',
  6207. msg = 'E15: Unexpected or operator: %.*s',
  6208. },
  6209. }, {
  6210. hl('NestingParenthesis', '('),
  6211. hl('InvalidOr', '||'),
  6212. hl('IdentifierName', 'a'),
  6213. hl('NestingParenthesis', ')'),
  6214. })
  6215. end)
  6216. itp('works with &opt', function()
  6217. check_parsing('&', {
  6218. -- 0
  6219. ast = {
  6220. 'Option(scope=0,ident=):0:0:&',
  6221. },
  6222. err = {
  6223. arg = '&',
  6224. msg = 'E112: Option name missing: %.*s',
  6225. },
  6226. }, {
  6227. hl('InvalidOptionSigil', '&'),
  6228. })
  6229. check_parsing('&opt', {
  6230. -- 0123
  6231. ast = {
  6232. 'Option(scope=0,ident=opt):0:0:&opt',
  6233. },
  6234. }, {
  6235. hl('OptionSigil', '&'),
  6236. hl('OptionName', 'opt'),
  6237. })
  6238. check_parsing('&l:opt', {
  6239. -- 012345
  6240. ast = {
  6241. 'Option(scope=l,ident=opt):0:0:&l:opt',
  6242. },
  6243. }, {
  6244. hl('OptionSigil', '&'),
  6245. hl('OptionScope', 'l'),
  6246. hl('OptionScopeDelimiter', ':'),
  6247. hl('OptionName', 'opt'),
  6248. })
  6249. check_parsing('&g:opt', {
  6250. -- 012345
  6251. ast = {
  6252. 'Option(scope=g,ident=opt):0:0:&g:opt',
  6253. },
  6254. }, {
  6255. hl('OptionSigil', '&'),
  6256. hl('OptionScope', 'g'),
  6257. hl('OptionScopeDelimiter', ':'),
  6258. hl('OptionName', 'opt'),
  6259. })
  6260. check_parsing('&s:opt', {
  6261. -- 012345
  6262. ast = {
  6263. {
  6264. 'Colon:0:2::',
  6265. children = {
  6266. 'Option(scope=0,ident=s):0:0:&s',
  6267. 'PlainIdentifier(scope=0,ident=opt):0:3:opt',
  6268. },
  6269. },
  6270. },
  6271. err = {
  6272. arg = ':opt',
  6273. msg = 'E15: Colon outside of dictionary or ternary operator: %.*s',
  6274. },
  6275. }, {
  6276. hl('OptionSigil', '&'),
  6277. hl('OptionName', 's'),
  6278. hl('InvalidColon', ':'),
  6279. hl('IdentifierName', 'opt'),
  6280. })
  6281. check_parsing('& ', {
  6282. -- 01
  6283. ast = {
  6284. 'Option(scope=0,ident=):0:0:&',
  6285. },
  6286. err = {
  6287. arg = '& ',
  6288. msg = 'E112: Option name missing: %.*s',
  6289. },
  6290. }, {
  6291. hl('InvalidOptionSigil', '&'),
  6292. })
  6293. check_parsing('&-', {
  6294. -- 01
  6295. ast = {
  6296. {
  6297. 'BinaryMinus:0:1:-',
  6298. children = {
  6299. 'Option(scope=0,ident=):0:0:&',
  6300. },
  6301. },
  6302. },
  6303. err = {
  6304. arg = '&-',
  6305. msg = 'E112: Option name missing: %.*s',
  6306. },
  6307. }, {
  6308. hl('InvalidOptionSigil', '&'),
  6309. hl('BinaryMinus', '-'),
  6310. })
  6311. check_parsing('&A', {
  6312. -- 01
  6313. ast = {
  6314. 'Option(scope=0,ident=A):0:0:&A',
  6315. },
  6316. }, {
  6317. hl('OptionSigil', '&'),
  6318. hl('OptionName', 'A'),
  6319. })
  6320. check_parsing('&xxx_yyy', {
  6321. -- 01234567
  6322. ast = {
  6323. {
  6324. 'OpMissing:0:4:',
  6325. children = {
  6326. 'Option(scope=0,ident=xxx):0:0:&xxx',
  6327. 'PlainIdentifier(scope=0,ident=_yyy):0:4:_yyy',
  6328. },
  6329. },
  6330. },
  6331. err = {
  6332. arg = '_yyy',
  6333. msg = 'E15: Missing operator: %.*s',
  6334. },
  6335. }, {
  6336. hl('OptionSigil', '&'),
  6337. hl('OptionName', 'xxx'),
  6338. hl('InvalidIdentifierName', '_yyy'),
  6339. }, {
  6340. [1] = {
  6341. ast = {
  6342. len = 4,
  6343. err = REMOVE_THIS,
  6344. ast = {
  6345. 'Option(scope=0,ident=xxx):0:0:&xxx',
  6346. },
  6347. },
  6348. hl_fs = {
  6349. [3] = REMOVE_THIS,
  6350. },
  6351. },
  6352. })
  6353. check_parsing('(1+&)', {
  6354. -- 01234
  6355. ast = {
  6356. {
  6357. 'Nested:0:0:(',
  6358. children = {
  6359. {
  6360. 'BinaryPlus:0:2:+',
  6361. children = {
  6362. 'Integer(val=1):0:1:1',
  6363. 'Option(scope=0,ident=):0:3:&',
  6364. },
  6365. },
  6366. },
  6367. },
  6368. },
  6369. err = {
  6370. arg = '&)',
  6371. msg = 'E112: Option name missing: %.*s',
  6372. },
  6373. }, {
  6374. hl('NestingParenthesis', '('),
  6375. hl('Number', '1'),
  6376. hl('BinaryPlus', '+'),
  6377. hl('InvalidOptionSigil', '&'),
  6378. hl('NestingParenthesis', ')'),
  6379. })
  6380. check_parsing('(&+1)', {
  6381. -- 01234
  6382. ast = {
  6383. {
  6384. 'Nested:0:0:(',
  6385. children = {
  6386. {
  6387. 'BinaryPlus:0:2:+',
  6388. children = {
  6389. 'Option(scope=0,ident=):0:1:&',
  6390. 'Integer(val=1):0:3:1',
  6391. },
  6392. },
  6393. },
  6394. },
  6395. },
  6396. err = {
  6397. arg = '&+1)',
  6398. msg = 'E112: Option name missing: %.*s',
  6399. },
  6400. }, {
  6401. hl('NestingParenthesis', '('),
  6402. hl('InvalidOptionSigil', '&'),
  6403. hl('BinaryPlus', '+'),
  6404. hl('Number', '1'),
  6405. hl('NestingParenthesis', ')'),
  6406. })
  6407. end)
  6408. itp('works with $ENV', function()
  6409. check_parsing('$', {
  6410. -- 0
  6411. ast = {
  6412. 'Environment(ident=):0:0:$',
  6413. },
  6414. err = {
  6415. arg = '$',
  6416. msg = 'E15: Environment variable name missing',
  6417. },
  6418. }, {
  6419. hl('InvalidEnvironmentSigil', '$'),
  6420. })
  6421. check_parsing('$g:A', {
  6422. -- 0123
  6423. ast = {
  6424. {
  6425. 'Colon:0:2::',
  6426. children = {
  6427. 'Environment(ident=g):0:0:$g',
  6428. 'PlainIdentifier(scope=0,ident=A):0:3:A',
  6429. },
  6430. },
  6431. },
  6432. err = {
  6433. arg = ':A',
  6434. msg = 'E15: Colon outside of dictionary or ternary operator: %.*s',
  6435. },
  6436. }, {
  6437. hl('EnvironmentSigil', '$'),
  6438. hl('EnvironmentName', 'g'),
  6439. hl('InvalidColon', ':'),
  6440. hl('IdentifierName', 'A'),
  6441. })
  6442. check_parsing('$A', {
  6443. -- 01
  6444. ast = {
  6445. 'Environment(ident=A):0:0:$A',
  6446. },
  6447. }, {
  6448. hl('EnvironmentSigil', '$'),
  6449. hl('EnvironmentName', 'A'),
  6450. })
  6451. check_parsing('$ABC', {
  6452. -- 0123
  6453. ast = {
  6454. 'Environment(ident=ABC):0:0:$ABC',
  6455. },
  6456. }, {
  6457. hl('EnvironmentSigil', '$'),
  6458. hl('EnvironmentName', 'ABC'),
  6459. })
  6460. check_parsing('(1+$)', {
  6461. -- 01234
  6462. ast = {
  6463. {
  6464. 'Nested:0:0:(',
  6465. children = {
  6466. {
  6467. 'BinaryPlus:0:2:+',
  6468. children = {
  6469. 'Integer(val=1):0:1:1',
  6470. 'Environment(ident=):0:3:$',
  6471. },
  6472. },
  6473. },
  6474. },
  6475. },
  6476. err = {
  6477. arg = '$)',
  6478. msg = 'E15: Environment variable name missing',
  6479. },
  6480. }, {
  6481. hl('NestingParenthesis', '('),
  6482. hl('Number', '1'),
  6483. hl('BinaryPlus', '+'),
  6484. hl('InvalidEnvironmentSigil', '$'),
  6485. hl('NestingParenthesis', ')'),
  6486. })
  6487. check_parsing('($+1)', {
  6488. -- 01234
  6489. ast = {
  6490. {
  6491. 'Nested:0:0:(',
  6492. children = {
  6493. {
  6494. 'BinaryPlus:0:2:+',
  6495. children = {
  6496. 'Environment(ident=):0:1:$',
  6497. 'Integer(val=1):0:3:1',
  6498. },
  6499. },
  6500. },
  6501. },
  6502. },
  6503. err = {
  6504. arg = '$+1)',
  6505. msg = 'E15: Environment variable name missing',
  6506. },
  6507. }, {
  6508. hl('NestingParenthesis', '('),
  6509. hl('InvalidEnvironmentSigil', '$'),
  6510. hl('BinaryPlus', '+'),
  6511. hl('Number', '1'),
  6512. hl('NestingParenthesis', ')'),
  6513. })
  6514. check_parsing('$_ABC', {
  6515. -- 01234
  6516. ast = {
  6517. 'Environment(ident=_ABC):0:0:$_ABC',
  6518. },
  6519. }, {
  6520. hl('EnvironmentSigil', '$'),
  6521. hl('EnvironmentName', '_ABC'),
  6522. })
  6523. check_parsing('$_', {
  6524. -- 01
  6525. ast = {
  6526. 'Environment(ident=_):0:0:$_',
  6527. },
  6528. }, {
  6529. hl('EnvironmentSigil', '$'),
  6530. hl('EnvironmentName', '_'),
  6531. })
  6532. check_parsing('$ABC_DEF', {
  6533. -- 01234567
  6534. ast = {
  6535. 'Environment(ident=ABC_DEF):0:0:$ABC_DEF',
  6536. },
  6537. }, {
  6538. hl('EnvironmentSigil', '$'),
  6539. hl('EnvironmentName', 'ABC_DEF'),
  6540. })
  6541. end)
  6542. itp('works with unary !', function()
  6543. check_parsing('!', {
  6544. -- 0
  6545. ast = {
  6546. 'Not:0:0:!',
  6547. },
  6548. err = {
  6549. arg = '',
  6550. msg = 'E15: Expected value, got EOC: %.*s',
  6551. },
  6552. }, {
  6553. hl('Not', '!'),
  6554. })
  6555. check_parsing('!!', {
  6556. -- 01
  6557. ast = {
  6558. {
  6559. 'Not:0:0:!',
  6560. children = {
  6561. 'Not:0:1:!',
  6562. },
  6563. },
  6564. },
  6565. err = {
  6566. arg = '',
  6567. msg = 'E15: Expected value, got EOC: %.*s',
  6568. },
  6569. }, {
  6570. hl('Not', '!'),
  6571. hl('Not', '!'),
  6572. })
  6573. check_parsing('!!1', {
  6574. -- 012
  6575. ast = {
  6576. {
  6577. 'Not:0:0:!',
  6578. children = {
  6579. {
  6580. 'Not:0:1:!',
  6581. children = {
  6582. 'Integer(val=1):0:2:1',
  6583. },
  6584. },
  6585. },
  6586. },
  6587. },
  6588. }, {
  6589. hl('Not', '!'),
  6590. hl('Not', '!'),
  6591. hl('Number', '1'),
  6592. })
  6593. check_parsing('!1', {
  6594. -- 01
  6595. ast = {
  6596. {
  6597. 'Not:0:0:!',
  6598. children = {
  6599. 'Integer(val=1):0:1:1',
  6600. },
  6601. },
  6602. },
  6603. }, {
  6604. hl('Not', '!'),
  6605. hl('Number', '1'),
  6606. })
  6607. check_parsing('(!1)', {
  6608. -- 0123
  6609. ast = {
  6610. {
  6611. 'Nested:0:0:(',
  6612. children = {
  6613. {
  6614. 'Not:0:1:!',
  6615. children = {
  6616. 'Integer(val=1):0:2:1',
  6617. },
  6618. },
  6619. },
  6620. },
  6621. },
  6622. }, {
  6623. hl('NestingParenthesis', '('),
  6624. hl('Not', '!'),
  6625. hl('Number', '1'),
  6626. hl('NestingParenthesis', ')'),
  6627. })
  6628. check_parsing('(!)', {
  6629. -- 012
  6630. ast = {
  6631. {
  6632. 'Nested:0:0:(',
  6633. children = {
  6634. {
  6635. 'Not:0:1:!',
  6636. children = {
  6637. 'Missing:0:2:',
  6638. },
  6639. },
  6640. },
  6641. },
  6642. },
  6643. err = {
  6644. arg = ')',
  6645. msg = 'E15: Expected value, got parenthesis: %.*s',
  6646. },
  6647. }, {
  6648. hl('NestingParenthesis', '('),
  6649. hl('Not', '!'),
  6650. hl('InvalidNestingParenthesis', ')'),
  6651. })
  6652. check_parsing('(1!2)', {
  6653. -- 01234
  6654. ast = {
  6655. {
  6656. 'Nested:0:0:(',
  6657. children = {
  6658. {
  6659. 'OpMissing:0:2:',
  6660. children = {
  6661. 'Integer(val=1):0:1:1',
  6662. {
  6663. 'Not:0:2:!',
  6664. children = {
  6665. 'Integer(val=2):0:3:2',
  6666. },
  6667. },
  6668. },
  6669. },
  6670. },
  6671. },
  6672. },
  6673. err = {
  6674. arg = '!2)',
  6675. msg = 'E15: Missing operator: %.*s',
  6676. },
  6677. }, {
  6678. hl('NestingParenthesis', '('),
  6679. hl('Number', '1'),
  6680. hl('InvalidNot', '!'),
  6681. hl('Number', '2'),
  6682. hl('NestingParenthesis', ')'),
  6683. })
  6684. check_parsing('1!2', {
  6685. -- 012
  6686. ast = {
  6687. {
  6688. 'OpMissing:0:1:',
  6689. children = {
  6690. 'Integer(val=1):0:0:1',
  6691. {
  6692. 'Not:0:1:!',
  6693. children = {
  6694. 'Integer(val=2):0:2:2',
  6695. },
  6696. },
  6697. },
  6698. },
  6699. },
  6700. err = {
  6701. arg = '!2',
  6702. msg = 'E15: Missing operator: %.*s',
  6703. },
  6704. }, {
  6705. hl('Number', '1'),
  6706. hl('InvalidNot', '!'),
  6707. hl('Number', '2'),
  6708. }, {
  6709. [1] = {
  6710. ast = {
  6711. len = 1,
  6712. err = REMOVE_THIS,
  6713. ast = {
  6714. 'Integer(val=1):0:0:1',
  6715. },
  6716. },
  6717. hl_fs = {
  6718. [2] = REMOVE_THIS,
  6719. [3] = REMOVE_THIS,
  6720. },
  6721. },
  6722. })
  6723. end)
  6724. itp('highlights numbers with prefix', function()
  6725. check_parsing('0xABCDEF', {
  6726. -- 01234567
  6727. ast = {
  6728. 'Integer(val=11259375):0:0:0xABCDEF',
  6729. },
  6730. }, {
  6731. hl('NumberPrefix', '0x'),
  6732. hl('Number', 'ABCDEF'),
  6733. })
  6734. check_parsing('0Xabcdef', {
  6735. -- 01234567
  6736. ast = {
  6737. 'Integer(val=11259375):0:0:0Xabcdef',
  6738. },
  6739. }, {
  6740. hl('NumberPrefix', '0X'),
  6741. hl('Number', 'abcdef'),
  6742. })
  6743. check_parsing('0XABCDEF', {
  6744. -- 01234567
  6745. ast = {
  6746. 'Integer(val=11259375):0:0:0XABCDEF',
  6747. },
  6748. }, {
  6749. hl('NumberPrefix', '0X'),
  6750. hl('Number', 'ABCDEF'),
  6751. })
  6752. check_parsing('0xabcdef', {
  6753. -- 01234567
  6754. ast = {
  6755. 'Integer(val=11259375):0:0:0xabcdef',
  6756. },
  6757. }, {
  6758. hl('NumberPrefix', '0x'),
  6759. hl('Number', 'abcdef'),
  6760. })
  6761. check_parsing('0b001', {
  6762. -- 01234
  6763. ast = {
  6764. 'Integer(val=1):0:0:0b001',
  6765. },
  6766. }, {
  6767. hl('NumberPrefix', '0b'),
  6768. hl('Number', '001'),
  6769. })
  6770. check_parsing('0B001', {
  6771. -- 01234
  6772. ast = {
  6773. 'Integer(val=1):0:0:0B001',
  6774. },
  6775. }, {
  6776. hl('NumberPrefix', '0B'),
  6777. hl('Number', '001'),
  6778. })
  6779. check_parsing('0B00', {
  6780. -- 0123
  6781. ast = {
  6782. 'Integer(val=0):0:0:0B00',
  6783. },
  6784. }, {
  6785. hl('NumberPrefix', '0B'),
  6786. hl('Number', '00'),
  6787. })
  6788. check_parsing('00', {
  6789. -- 01
  6790. ast = {
  6791. 'Integer(val=0):0:0:00',
  6792. },
  6793. }, {
  6794. hl('NumberPrefix', '0'),
  6795. hl('Number', '0'),
  6796. })
  6797. check_parsing('001', {
  6798. -- 012
  6799. ast = {
  6800. 'Integer(val=1):0:0:001',
  6801. },
  6802. }, {
  6803. hl('NumberPrefix', '0'),
  6804. hl('Number', '01'),
  6805. })
  6806. check_parsing('01', {
  6807. -- 01
  6808. ast = {
  6809. 'Integer(val=1):0:0:01',
  6810. },
  6811. }, {
  6812. hl('NumberPrefix', '0'),
  6813. hl('Number', '1'),
  6814. })
  6815. check_parsing('1', {
  6816. -- 0
  6817. ast = {
  6818. 'Integer(val=1):0:0:1',
  6819. },
  6820. }, {
  6821. hl('Number', '1'),
  6822. })
  6823. end)
  6824. itp('works (KLEE tests)', function()
  6825. check_parsing('\0002&A:\000', {
  6826. len = 0,
  6827. ast = nil,
  6828. err = {
  6829. arg = '\0002&A:\000',
  6830. msg = 'E15: Expected value, got EOC: %.*s',
  6831. },
  6832. }, {}, {
  6833. [2] = {
  6834. ast = {
  6835. len = REMOVE_THIS,
  6836. ast = {
  6837. {
  6838. 'Colon:0:4::',
  6839. children = {
  6840. {
  6841. 'OpMissing:0:2:',
  6842. children = {
  6843. 'Integer(val=2):0:1:2',
  6844. 'Option(scope=0,ident=A):0:2:&A',
  6845. },
  6846. },
  6847. },
  6848. },
  6849. },
  6850. err = {
  6851. msg = 'E15: Unexpected EOC character: %.*s',
  6852. },
  6853. },
  6854. hl_fs = {
  6855. hl('InvalidSpacing', '\0'),
  6856. hl('Number', '2'),
  6857. hl('InvalidOptionSigil', '&'),
  6858. hl('InvalidOptionName', 'A'),
  6859. hl('InvalidColon', ':'),
  6860. hl('InvalidSpacing', '\0'),
  6861. },
  6862. },
  6863. [3] = {
  6864. ast = {
  6865. len = 2,
  6866. ast = {
  6867. 'Integer(val=2):0:1:2',
  6868. },
  6869. err = {
  6870. msg = 'E15: Unexpected EOC character: %.*s',
  6871. },
  6872. },
  6873. hl_fs = {
  6874. hl('InvalidSpacing', '\0'),
  6875. hl('Number', '2'),
  6876. },
  6877. },
  6878. })
  6879. check_parsing({ data = '01', size = 1 }, {
  6880. len = 1,
  6881. ast = {
  6882. 'Integer(val=0):0:0:0',
  6883. },
  6884. }, {
  6885. hl('Number', '0'),
  6886. })
  6887. check_parsing({ data = '001', size = 2 }, {
  6888. len = 2,
  6889. ast = {
  6890. 'Integer(val=0):0:0:00',
  6891. },
  6892. }, {
  6893. hl('NumberPrefix', '0'),
  6894. hl('Number', '0'),
  6895. })
  6896. check_parsing('"\\U\\', {
  6897. -- 0123
  6898. ast = {
  6899. [[DoubleQuotedString(val="U\\"):0:0:"\U\]],
  6900. },
  6901. err = {
  6902. arg = '"\\U\\',
  6903. msg = 'E114: Missing double quote: %.*s',
  6904. },
  6905. }, {
  6906. hl('InvalidDoubleQuote', '"'),
  6907. hl('InvalidDoubleQuotedUnknownEscape', '\\U'),
  6908. hl('InvalidDoubleQuotedBody', '\\'),
  6909. })
  6910. check_parsing('"\\U', {
  6911. -- 012
  6912. ast = {
  6913. fmtn('DoubleQuotedString', 'val="U"', ':0:0:"\\U'),
  6914. },
  6915. err = {
  6916. arg = '"\\U',
  6917. msg = 'E114: Missing double quote: %.*s',
  6918. },
  6919. }, {
  6920. hl('InvalidDoubleQuote', '"'),
  6921. hl('InvalidDoubleQuotedUnknownEscape', '\\U'),
  6922. })
  6923. check_parsing('|"\\U\\', {
  6924. -- 01234
  6925. len = 0,
  6926. err = {
  6927. arg = '|"\\U\\',
  6928. msg = 'E15: Expected value, got EOC: %.*s',
  6929. },
  6930. }, {}, {
  6931. [2] = {
  6932. ast = {
  6933. len = REMOVE_THIS,
  6934. ast = {
  6935. {
  6936. 'Or:0:0:|',
  6937. children = {
  6938. 'Missing:0:0:',
  6939. fmtn('DoubleQuotedString', 'val="U\\\\"', ':0:1:"\\U\\'),
  6940. },
  6941. },
  6942. },
  6943. err = {
  6944. msg = 'E15: Unexpected EOC character: %.*s',
  6945. },
  6946. },
  6947. hl_fs = {
  6948. hl('InvalidOr', '|'),
  6949. hl('InvalidDoubleQuote', '"'),
  6950. hl('InvalidDoubleQuotedUnknownEscape', '\\U'),
  6951. hl('InvalidDoubleQuotedBody', '\\'),
  6952. },
  6953. },
  6954. })
  6955. check_parsing('|"\\e"', {
  6956. -- 01234
  6957. len = 0,
  6958. err = {
  6959. arg = '|"\\e"',
  6960. msg = 'E15: Expected value, got EOC: %.*s',
  6961. },
  6962. }, {}, {
  6963. [2] = {
  6964. ast = {
  6965. len = REMOVE_THIS,
  6966. ast = {
  6967. {
  6968. 'Or:0:0:|',
  6969. children = {
  6970. 'Missing:0:0:',
  6971. fmtn('DoubleQuotedString', 'val="\\027"', ':0:1:"\\e"'),
  6972. },
  6973. },
  6974. },
  6975. err = {
  6976. msg = 'E15: Unexpected EOC character: %.*s',
  6977. },
  6978. },
  6979. hl_fs = {
  6980. hl('InvalidOr', '|'),
  6981. hl('DoubleQuote', '"'),
  6982. hl('DoubleQuotedEscape', '\\e'),
  6983. hl('DoubleQuote', '"'),
  6984. },
  6985. },
  6986. })
  6987. check_parsing('|\029', {
  6988. -- 01
  6989. len = 0,
  6990. err = {
  6991. arg = '|\029',
  6992. msg = 'E15: Expected value, got EOC: %.*s',
  6993. },
  6994. }, {}, {
  6995. [2] = {
  6996. ast = {
  6997. len = REMOVE_THIS,
  6998. ast = {
  6999. {
  7000. 'Or:0:0:|',
  7001. children = {
  7002. 'Missing:0:0:',
  7003. 'PlainIdentifier(scope=0,ident=\029):0:1:\029',
  7004. },
  7005. },
  7006. },
  7007. err = {
  7008. msg = 'E15: Unexpected EOC character: %.*s',
  7009. },
  7010. },
  7011. hl_fs = {
  7012. hl('InvalidOr', '|'),
  7013. hl('InvalidIdentifierName', '\029'),
  7014. },
  7015. },
  7016. })
  7017. check_parsing('"\\<', {
  7018. -- 012
  7019. ast = {
  7020. fmtn('DoubleQuotedString', 'val="<"', ':0:0:"\\<'),
  7021. },
  7022. err = {
  7023. arg = '"\\<',
  7024. msg = 'E114: Missing double quote: %.*s',
  7025. },
  7026. }, {
  7027. hl('InvalidDoubleQuote', '"'),
  7028. hl('InvalidDoubleQuotedUnknownEscape', '\\<'),
  7029. })
  7030. check_parsing('"\\1', {
  7031. -- 01 2
  7032. ast = {
  7033. fmtn('DoubleQuotedString', 'val="\\001"', ':0:0:"\\1'),
  7034. },
  7035. err = {
  7036. arg = '"\\1',
  7037. msg = 'E114: Missing double quote: %.*s',
  7038. },
  7039. }, {
  7040. hl('InvalidDoubleQuote', '"'),
  7041. hl('InvalidDoubleQuotedEscape', '\\1'),
  7042. })
  7043. check_parsing('}l', {
  7044. -- 01
  7045. ast = {
  7046. {
  7047. 'OpMissing:0:1:',
  7048. children = {
  7049. fmtn('UnknownFigure', '---', ':0:0:'),
  7050. 'PlainIdentifier(scope=0,ident=l):0:1:l',
  7051. },
  7052. },
  7053. },
  7054. err = {
  7055. arg = '}l',
  7056. msg = 'E15: Unexpected closing figure brace: %.*s',
  7057. },
  7058. }, {
  7059. hl('InvalidFigureBrace', '}'),
  7060. hl('InvalidIdentifierName', 'l'),
  7061. }, {
  7062. [1] = {
  7063. ast = {
  7064. len = 1,
  7065. ast = {
  7066. fmtn('UnknownFigure', '---', ':0:0:'),
  7067. },
  7068. },
  7069. hl_fs = {
  7070. [2] = REMOVE_THIS,
  7071. },
  7072. },
  7073. })
  7074. check_parsing(':?\000\000\000\000\000\000\000', {
  7075. len = 2,
  7076. ast = {
  7077. {
  7078. 'Colon:0:0::',
  7079. children = {
  7080. 'Missing:0:0:',
  7081. {
  7082. 'Ternary:0:1:?',
  7083. children = {
  7084. 'Missing:0:1:',
  7085. 'TernaryValue:0:1:?',
  7086. },
  7087. },
  7088. },
  7089. },
  7090. },
  7091. err = {
  7092. arg = ':?\000\000\000\000\000\000\000',
  7093. msg = 'E15: Colon outside of dictionary or ternary operator: %.*s',
  7094. },
  7095. }, {
  7096. hl('InvalidColon', ':'),
  7097. hl('InvalidTernary', '?'),
  7098. }, {
  7099. [2] = {
  7100. ast = {
  7101. len = REMOVE_THIS,
  7102. },
  7103. hl_fs = {
  7104. [3] = hl('InvalidSpacing', '\0'),
  7105. [4] = hl('InvalidSpacing', '\0'),
  7106. [5] = hl('InvalidSpacing', '\0'),
  7107. [6] = hl('InvalidSpacing', '\0'),
  7108. [7] = hl('InvalidSpacing', '\0'),
  7109. [8] = hl('InvalidSpacing', '\0'),
  7110. [9] = hl('InvalidSpacing', '\0'),
  7111. },
  7112. },
  7113. })
  7114. end)
  7115. itp('works with assignments', function()
  7116. check_asgn_parsing('a=b', {
  7117. -- 012
  7118. ast = {
  7119. {
  7120. 'Assignment(Plain):0:1:=',
  7121. children = {
  7122. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7123. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  7124. },
  7125. },
  7126. },
  7127. }, {
  7128. hl('IdentifierName', 'a'),
  7129. hl('PlainAssignment', '='),
  7130. hl('IdentifierName', 'b'),
  7131. })
  7132. check_asgn_parsing('a+=b', {
  7133. -- 0123
  7134. ast = {
  7135. {
  7136. 'Assignment(Add):0:1:+=',
  7137. children = {
  7138. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7139. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  7140. },
  7141. },
  7142. },
  7143. }, {
  7144. hl('IdentifierName', 'a'),
  7145. hl('AssignmentWithAddition', '+='),
  7146. hl('IdentifierName', 'b'),
  7147. })
  7148. check_asgn_parsing('a-=b', {
  7149. -- 0123
  7150. ast = {
  7151. {
  7152. 'Assignment(Subtract):0:1:-=',
  7153. children = {
  7154. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7155. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  7156. },
  7157. },
  7158. },
  7159. }, {
  7160. hl('IdentifierName', 'a'),
  7161. hl('AssignmentWithSubtraction', '-='),
  7162. hl('IdentifierName', 'b'),
  7163. })
  7164. check_asgn_parsing('a.=b', {
  7165. -- 0123
  7166. ast = {
  7167. {
  7168. 'Assignment(Concat):0:1:.=',
  7169. children = {
  7170. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7171. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  7172. },
  7173. },
  7174. },
  7175. }, {
  7176. hl('IdentifierName', 'a'),
  7177. hl('AssignmentWithConcatenation', '.='),
  7178. hl('IdentifierName', 'b'),
  7179. })
  7180. check_asgn_parsing('a', {
  7181. -- 0
  7182. ast = {
  7183. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7184. },
  7185. }, {
  7186. hl('IdentifierName', 'a'),
  7187. })
  7188. check_asgn_parsing('a b', {
  7189. -- 012
  7190. ast = {
  7191. {
  7192. 'OpMissing:0:1:',
  7193. children = {
  7194. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7195. 'PlainIdentifier(scope=0,ident=b):0:1: b',
  7196. },
  7197. },
  7198. },
  7199. err = {
  7200. arg = 'b',
  7201. msg = 'E15: Expected assignment operator or subscript: %.*s',
  7202. },
  7203. }, {
  7204. hl('IdentifierName', 'a'),
  7205. hl('InvalidSpacing', ' '),
  7206. hl('IdentifierName', 'b'),
  7207. }, {
  7208. [5] = {
  7209. ast = {
  7210. len = 2,
  7211. ast = {
  7212. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7213. },
  7214. err = REMOVE_THIS,
  7215. },
  7216. hl_fs = {
  7217. [2] = REMOVE_THIS,
  7218. [3] = REMOVE_THIS,
  7219. },
  7220. },
  7221. })
  7222. check_asgn_parsing('[a, b, c]', {
  7223. -- 012345678
  7224. ast = {
  7225. {
  7226. 'ListLiteral:0:0:[',
  7227. children = {
  7228. {
  7229. 'Comma:0:2:,',
  7230. children = {
  7231. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  7232. {
  7233. 'Comma:0:5:,',
  7234. children = {
  7235. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  7236. 'PlainIdentifier(scope=0,ident=c):0:6: c',
  7237. },
  7238. },
  7239. },
  7240. },
  7241. },
  7242. },
  7243. },
  7244. }, {
  7245. hl('List', '['),
  7246. hl('IdentifierName', 'a'),
  7247. hl('Comma', ','),
  7248. hl('IdentifierName', 'b', 1),
  7249. hl('Comma', ','),
  7250. hl('IdentifierName', 'c', 1),
  7251. hl('List', ']'),
  7252. })
  7253. check_asgn_parsing('[a, b]', {
  7254. -- 012345
  7255. ast = {
  7256. {
  7257. 'ListLiteral:0:0:[',
  7258. children = {
  7259. {
  7260. 'Comma:0:2:,',
  7261. children = {
  7262. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  7263. 'PlainIdentifier(scope=0,ident=b):0:3: b',
  7264. },
  7265. },
  7266. },
  7267. },
  7268. },
  7269. }, {
  7270. hl('List', '['),
  7271. hl('IdentifierName', 'a'),
  7272. hl('Comma', ','),
  7273. hl('IdentifierName', 'b', 1),
  7274. hl('List', ']'),
  7275. })
  7276. check_asgn_parsing('[a]', {
  7277. -- 012
  7278. ast = {
  7279. {
  7280. 'ListLiteral:0:0:[',
  7281. children = {
  7282. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  7283. },
  7284. },
  7285. },
  7286. }, {
  7287. hl('List', '['),
  7288. hl('IdentifierName', 'a'),
  7289. hl('List', ']'),
  7290. })
  7291. check_asgn_parsing('[]', {
  7292. -- 01
  7293. ast = {
  7294. 'ListLiteral:0:0:[',
  7295. },
  7296. err = {
  7297. arg = ']',
  7298. msg = 'E475: Unable to assign to empty list: %.*s',
  7299. },
  7300. }, {
  7301. hl('List', '['),
  7302. hl('InvalidList', ']'),
  7303. })
  7304. check_asgn_parsing('a[1] += 3', {
  7305. -- 012345678
  7306. ast = {
  7307. {
  7308. 'Assignment(Add):0:4: +=',
  7309. children = {
  7310. {
  7311. 'Subscript:0:1:[',
  7312. children = {
  7313. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7314. 'Integer(val=1):0:2:1',
  7315. },
  7316. },
  7317. 'Integer(val=3):0:7: 3',
  7318. },
  7319. },
  7320. },
  7321. }, {
  7322. hl('IdentifierName', 'a'),
  7323. hl('SubscriptBracket', '['),
  7324. hl('Number', '1'),
  7325. hl('SubscriptBracket', ']'),
  7326. hl('AssignmentWithAddition', '+=', 1),
  7327. hl('Number', '3', 1),
  7328. })
  7329. check_asgn_parsing('a[1 + 2] += 3', {
  7330. -- 0123456789012
  7331. -- 0 1
  7332. ast = {
  7333. {
  7334. 'Assignment(Add):0:8: +=',
  7335. children = {
  7336. {
  7337. 'Subscript:0:1:[',
  7338. children = {
  7339. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7340. {
  7341. 'BinaryPlus:0:3: +',
  7342. children = {
  7343. 'Integer(val=1):0:2:1',
  7344. 'Integer(val=2):0:5: 2',
  7345. },
  7346. },
  7347. },
  7348. },
  7349. 'Integer(val=3):0:11: 3',
  7350. },
  7351. },
  7352. },
  7353. }, {
  7354. hl('IdentifierName', 'a'),
  7355. hl('SubscriptBracket', '['),
  7356. hl('Number', '1'),
  7357. hl('BinaryPlus', '+', 1),
  7358. hl('Number', '2', 1),
  7359. hl('SubscriptBracket', ']'),
  7360. hl('AssignmentWithAddition', '+=', 1),
  7361. hl('Number', '3', 1),
  7362. })
  7363. check_asgn_parsing('a[{-> {b{3}: 4}[5]}()] += 6', {
  7364. -- 012345678901234567890123456
  7365. -- 0 1 2
  7366. ast = {
  7367. {
  7368. 'Assignment(Add):0:22: +=',
  7369. children = {
  7370. {
  7371. 'Subscript:0:1:[',
  7372. children = {
  7373. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7374. {
  7375. 'Call:0:19:(',
  7376. children = {
  7377. {
  7378. fmtn('Lambda', '\\di', ':0:2:{'),
  7379. children = {
  7380. {
  7381. 'Arrow:0:3:->',
  7382. children = {
  7383. {
  7384. 'Subscript:0:15:[',
  7385. children = {
  7386. {
  7387. fmtn('DictLiteral', '-di', ':0:5: {'),
  7388. children = {
  7389. {
  7390. 'Colon:0:11::',
  7391. children = {
  7392. {
  7393. 'ComplexIdentifier:0:8:',
  7394. children = {
  7395. 'PlainIdentifier(scope=0,ident=b):0:7:b',
  7396. {
  7397. fmtn('CurlyBracesIdentifier', '--i', ':0:8:{'),
  7398. children = {
  7399. 'Integer(val=3):0:9:3',
  7400. },
  7401. },
  7402. },
  7403. },
  7404. 'Integer(val=4):0:12: 4',
  7405. },
  7406. },
  7407. },
  7408. },
  7409. 'Integer(val=5):0:16:5',
  7410. },
  7411. },
  7412. },
  7413. },
  7414. },
  7415. },
  7416. },
  7417. },
  7418. },
  7419. },
  7420. 'Integer(val=6):0:25: 6',
  7421. },
  7422. },
  7423. },
  7424. }, {
  7425. hl('IdentifierName', 'a'),
  7426. hl('SubscriptBracket', '['),
  7427. hl('Lambda', '{'),
  7428. hl('Arrow', '->'),
  7429. hl('Dict', '{', 1),
  7430. hl('IdentifierName', 'b'),
  7431. hl('Curly', '{'),
  7432. hl('Number', '3'),
  7433. hl('Curly', '}'),
  7434. hl('Colon', ':'),
  7435. hl('Number', '4', 1),
  7436. hl('Dict', '}'),
  7437. hl('SubscriptBracket', '['),
  7438. hl('Number', '5'),
  7439. hl('SubscriptBracket', ']'),
  7440. hl('Lambda', '}'),
  7441. hl('CallingParenthesis', '('),
  7442. hl('CallingParenthesis', ')'),
  7443. hl('SubscriptBracket', ']'),
  7444. hl('AssignmentWithAddition', '+=', 1),
  7445. hl('Number', '6', 1),
  7446. })
  7447. check_asgn_parsing('a{1}.2[{-> {b{3}: 4}[5]}()]', {
  7448. -- 012345678901234567890123456
  7449. -- 0 1 2
  7450. ast = {
  7451. {
  7452. 'Subscript:0:6:[',
  7453. children = {
  7454. {
  7455. 'ConcatOrSubscript:0:4:.',
  7456. children = {
  7457. {
  7458. 'ComplexIdentifier:0:1:',
  7459. children = {
  7460. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7461. {
  7462. fmtn('CurlyBracesIdentifier', '--i', ':0:1:{'),
  7463. children = {
  7464. 'Integer(val=1):0:2:1',
  7465. },
  7466. },
  7467. },
  7468. },
  7469. 'PlainKey(key=2):0:5:2',
  7470. },
  7471. },
  7472. {
  7473. 'Call:0:24:(',
  7474. children = {
  7475. {
  7476. fmtn('Lambda', '\\di', ':0:7:{'),
  7477. children = {
  7478. {
  7479. 'Arrow:0:8:->',
  7480. children = {
  7481. {
  7482. 'Subscript:0:20:[',
  7483. children = {
  7484. {
  7485. fmtn('DictLiteral', '-di', ':0:10: {'),
  7486. children = {
  7487. {
  7488. 'Colon:0:16::',
  7489. children = {
  7490. {
  7491. 'ComplexIdentifier:0:13:',
  7492. children = {
  7493. 'PlainIdentifier(scope=0,ident=b):0:12:b',
  7494. {
  7495. fmtn('CurlyBracesIdentifier', '--i', ':0:13:{'),
  7496. children = {
  7497. 'Integer(val=3):0:14:3',
  7498. },
  7499. },
  7500. },
  7501. },
  7502. 'Integer(val=4):0:17: 4',
  7503. },
  7504. },
  7505. },
  7506. },
  7507. 'Integer(val=5):0:21:5',
  7508. },
  7509. },
  7510. },
  7511. },
  7512. },
  7513. },
  7514. },
  7515. },
  7516. },
  7517. },
  7518. },
  7519. }, {
  7520. hl('IdentifierName', 'a'),
  7521. hl('Curly', '{'),
  7522. hl('Number', '1'),
  7523. hl('Curly', '}'),
  7524. hl('ConcatOrSubscript', '.'),
  7525. hl('IdentifierKey', '2'),
  7526. hl('SubscriptBracket', '['),
  7527. hl('Lambda', '{'),
  7528. hl('Arrow', '->'),
  7529. hl('Dict', '{', 1),
  7530. hl('IdentifierName', 'b'),
  7531. hl('Curly', '{'),
  7532. hl('Number', '3'),
  7533. hl('Curly', '}'),
  7534. hl('Colon', ':'),
  7535. hl('Number', '4', 1),
  7536. hl('Dict', '}'),
  7537. hl('SubscriptBracket', '['),
  7538. hl('Number', '5'),
  7539. hl('SubscriptBracket', ']'),
  7540. hl('Lambda', '}'),
  7541. hl('CallingParenthesis', '('),
  7542. hl('CallingParenthesis', ')'),
  7543. hl('SubscriptBracket', ']'),
  7544. })
  7545. check_asgn_parsing('a', {
  7546. -- 0
  7547. ast = {
  7548. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7549. },
  7550. }, {
  7551. hl('IdentifierName', 'a'),
  7552. })
  7553. check_asgn_parsing('{a}', {
  7554. -- 012
  7555. ast = {
  7556. {
  7557. fmtn('CurlyBracesIdentifier', '--i', ':0:0:{'),
  7558. children = {
  7559. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  7560. },
  7561. },
  7562. },
  7563. }, {
  7564. hl('FigureBrace', '{'),
  7565. hl('IdentifierName', 'a'),
  7566. hl('Curly', '}'),
  7567. })
  7568. check_asgn_parsing('{a}b', {
  7569. -- 0123
  7570. ast = {
  7571. {
  7572. 'ComplexIdentifier:0:3:',
  7573. children = {
  7574. {
  7575. fmtn('CurlyBracesIdentifier', '--i', ':0:0:{'),
  7576. children = {
  7577. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  7578. },
  7579. },
  7580. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  7581. },
  7582. },
  7583. },
  7584. }, {
  7585. hl('FigureBrace', '{'),
  7586. hl('IdentifierName', 'a'),
  7587. hl('Curly', '}'),
  7588. hl('IdentifierName', 'b'),
  7589. })
  7590. check_asgn_parsing('a{b}c', {
  7591. -- 01234
  7592. ast = {
  7593. {
  7594. 'ComplexIdentifier:0:1:',
  7595. children = {
  7596. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7597. {
  7598. 'ComplexIdentifier:0:4:',
  7599. children = {
  7600. {
  7601. fmtn('CurlyBracesIdentifier', '--i', ':0:1:{'),
  7602. children = {
  7603. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  7604. },
  7605. },
  7606. 'PlainIdentifier(scope=0,ident=c):0:4:c',
  7607. },
  7608. },
  7609. },
  7610. },
  7611. },
  7612. }, {
  7613. hl('IdentifierName', 'a'),
  7614. hl('Curly', '{'),
  7615. hl('IdentifierName', 'b'),
  7616. hl('Curly', '}'),
  7617. hl('IdentifierName', 'c'),
  7618. })
  7619. check_asgn_parsing('a{b}c[0]', {
  7620. -- 01234567
  7621. ast = {
  7622. {
  7623. 'Subscript:0:5:[',
  7624. children = {
  7625. {
  7626. 'ComplexIdentifier:0:1:',
  7627. children = {
  7628. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7629. {
  7630. 'ComplexIdentifier:0:4:',
  7631. children = {
  7632. {
  7633. fmtn('CurlyBracesIdentifier', '--i', ':0:1:{'),
  7634. children = {
  7635. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  7636. },
  7637. },
  7638. 'PlainIdentifier(scope=0,ident=c):0:4:c',
  7639. },
  7640. },
  7641. },
  7642. },
  7643. 'Integer(val=0):0:6:0',
  7644. },
  7645. },
  7646. },
  7647. }, {
  7648. hl('IdentifierName', 'a'),
  7649. hl('Curly', '{'),
  7650. hl('IdentifierName', 'b'),
  7651. hl('Curly', '}'),
  7652. hl('IdentifierName', 'c'),
  7653. hl('SubscriptBracket', '['),
  7654. hl('Number', '0'),
  7655. hl('SubscriptBracket', ']'),
  7656. })
  7657. check_asgn_parsing('a{b}c.0', {
  7658. -- 0123456
  7659. ast = {
  7660. {
  7661. 'ConcatOrSubscript:0:5:.',
  7662. children = {
  7663. {
  7664. 'ComplexIdentifier:0:1:',
  7665. children = {
  7666. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7667. {
  7668. 'ComplexIdentifier:0:4:',
  7669. children = {
  7670. {
  7671. fmtn('CurlyBracesIdentifier', '--i', ':0:1:{'),
  7672. children = {
  7673. 'PlainIdentifier(scope=0,ident=b):0:2:b',
  7674. },
  7675. },
  7676. 'PlainIdentifier(scope=0,ident=c):0:4:c',
  7677. },
  7678. },
  7679. },
  7680. },
  7681. 'PlainKey(key=0):0:6:0',
  7682. },
  7683. },
  7684. },
  7685. }, {
  7686. hl('IdentifierName', 'a'),
  7687. hl('Curly', '{'),
  7688. hl('IdentifierName', 'b'),
  7689. hl('Curly', '}'),
  7690. hl('IdentifierName', 'c'),
  7691. hl('ConcatOrSubscript', '.'),
  7692. hl('IdentifierKey', '0'),
  7693. })
  7694. check_asgn_parsing('[a{b}c[0].0]', {
  7695. -- 012345678901
  7696. -- 0 1
  7697. ast = {
  7698. {
  7699. 'ListLiteral:0:0:[',
  7700. children = {
  7701. {
  7702. 'ConcatOrSubscript:0:9:.',
  7703. children = {
  7704. {
  7705. 'Subscript:0:6:[',
  7706. children = {
  7707. {
  7708. 'ComplexIdentifier:0:2:',
  7709. children = {
  7710. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  7711. {
  7712. 'ComplexIdentifier:0:5:',
  7713. children = {
  7714. {
  7715. fmtn('CurlyBracesIdentifier', '--i', ':0:2:{'),
  7716. children = {
  7717. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  7718. },
  7719. },
  7720. 'PlainIdentifier(scope=0,ident=c):0:5:c',
  7721. },
  7722. },
  7723. },
  7724. },
  7725. 'Integer(val=0):0:7:0',
  7726. },
  7727. },
  7728. 'PlainKey(key=0):0:10:0',
  7729. },
  7730. },
  7731. },
  7732. },
  7733. },
  7734. }, {
  7735. hl('List', '['),
  7736. hl('IdentifierName', 'a'),
  7737. hl('Curly', '{'),
  7738. hl('IdentifierName', 'b'),
  7739. hl('Curly', '}'),
  7740. hl('IdentifierName', 'c'),
  7741. hl('SubscriptBracket', '['),
  7742. hl('Number', '0'),
  7743. hl('SubscriptBracket', ']'),
  7744. hl('ConcatOrSubscript', '.'),
  7745. hl('IdentifierKey', '0'),
  7746. hl('List', ']'),
  7747. })
  7748. check_asgn_parsing('{a}{b}', {
  7749. -- 012345
  7750. ast = {
  7751. {
  7752. 'ComplexIdentifier:0:3:',
  7753. children = {
  7754. {
  7755. fmtn('CurlyBracesIdentifier', '--i', ':0:0:{'),
  7756. children = {
  7757. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  7758. },
  7759. },
  7760. {
  7761. fmtn('CurlyBracesIdentifier', '--i', ':0:3:{'),
  7762. children = {
  7763. 'PlainIdentifier(scope=0,ident=b):0:4:b',
  7764. },
  7765. },
  7766. },
  7767. },
  7768. },
  7769. }, {
  7770. hl('FigureBrace', '{'),
  7771. hl('IdentifierName', 'a'),
  7772. hl('Curly', '}'),
  7773. hl('Curly', '{'),
  7774. hl('IdentifierName', 'b'),
  7775. hl('Curly', '}'),
  7776. })
  7777. check_asgn_parsing('a.b{c}{d}', {
  7778. -- 012345678
  7779. ast = {
  7780. {
  7781. 'OpMissing:0:3:',
  7782. children = {
  7783. {
  7784. 'ConcatOrSubscript:0:1:.',
  7785. children = {
  7786. 'PlainIdentifier(scope=0,ident=a):0:0:a',
  7787. 'PlainKey(key=b):0:2:b',
  7788. },
  7789. },
  7790. {
  7791. 'ComplexIdentifier:0:6:',
  7792. children = {
  7793. {
  7794. fmtn('CurlyBracesIdentifier', '--i', ':0:3:{'),
  7795. children = {
  7796. 'PlainIdentifier(scope=0,ident=c):0:4:c',
  7797. },
  7798. },
  7799. {
  7800. fmtn('CurlyBracesIdentifier', '--i', ':0:6:{'),
  7801. children = {
  7802. 'PlainIdentifier(scope=0,ident=d):0:7:d',
  7803. },
  7804. },
  7805. },
  7806. },
  7807. },
  7808. },
  7809. },
  7810. err = {
  7811. arg = '{c}{d}',
  7812. msg = 'E15: Missing operator: %.*s',
  7813. },
  7814. }, {
  7815. hl('IdentifierName', 'a'),
  7816. hl('ConcatOrSubscript', '.'),
  7817. hl('IdentifierKey', 'b'),
  7818. hl('InvalidFigureBrace', '{'),
  7819. hl('IdentifierName', 'c'),
  7820. hl('Curly', '}'),
  7821. hl('Curly', '{'),
  7822. hl('IdentifierName', 'd'),
  7823. hl('Curly', '}'),
  7824. })
  7825. check_asgn_parsing('[a] = 1', {
  7826. -- 0123456
  7827. ast = {
  7828. {
  7829. 'Assignment(Plain):0:3: =',
  7830. children = {
  7831. {
  7832. 'ListLiteral:0:0:[',
  7833. children = {
  7834. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  7835. },
  7836. },
  7837. 'Integer(val=1):0:5: 1',
  7838. },
  7839. },
  7840. },
  7841. }, {
  7842. hl('List', '['),
  7843. hl('IdentifierName', 'a'),
  7844. hl('List', ']'),
  7845. hl('PlainAssignment', '=', 1),
  7846. hl('Number', '1', 1),
  7847. })
  7848. check_asgn_parsing('[a[b], [c, [d, [e]]]] = 1', {
  7849. -- 0123456789012345678901234
  7850. -- 0 1 2
  7851. ast = {
  7852. {
  7853. 'Assignment(Plain):0:21: =',
  7854. children = {
  7855. {
  7856. 'ListLiteral:0:0:[',
  7857. children = {
  7858. {
  7859. 'Comma:0:5:,',
  7860. children = {
  7861. {
  7862. 'Subscript:0:2:[',
  7863. children = {
  7864. 'PlainIdentifier(scope=0,ident=a):0:1:a',
  7865. 'PlainIdentifier(scope=0,ident=b):0:3:b',
  7866. },
  7867. },
  7868. {
  7869. 'ListLiteral:0:6: [',
  7870. children = {
  7871. {
  7872. 'Comma:0:9:,',
  7873. children = {
  7874. 'PlainIdentifier(scope=0,ident=c):0:8:c',
  7875. {
  7876. 'ListLiteral:0:10: [',
  7877. children = {
  7878. {
  7879. 'Comma:0:13:,',
  7880. children = {
  7881. 'PlainIdentifier(scope=0,ident=d):0:12:d',
  7882. {
  7883. 'ListLiteral:0:14: [',
  7884. children = {
  7885. 'PlainIdentifier(scope=0,ident=e):0:16:e',
  7886. },
  7887. },
  7888. },
  7889. },
  7890. },
  7891. },
  7892. },
  7893. },
  7894. },
  7895. },
  7896. },
  7897. },
  7898. },
  7899. },
  7900. 'Integer(val=1):0:23: 1',
  7901. },
  7902. },
  7903. },
  7904. err = {
  7905. arg = '[c, [d, [e]]]] = 1',
  7906. msg = 'E475: Nested lists not allowed when assigning: %.*s',
  7907. },
  7908. }, {
  7909. hl('List', '['),
  7910. hl('IdentifierName', 'a'),
  7911. hl('SubscriptBracket', '['),
  7912. hl('IdentifierName', 'b'),
  7913. hl('SubscriptBracket', ']'),
  7914. hl('Comma', ','),
  7915. hl('InvalidList', '[', 1),
  7916. hl('IdentifierName', 'c'),
  7917. hl('Comma', ','),
  7918. hl('InvalidList', '[', 1),
  7919. hl('IdentifierName', 'd'),
  7920. hl('Comma', ','),
  7921. hl('InvalidList', '[', 1),
  7922. hl('IdentifierName', 'e'),
  7923. hl('List', ']'),
  7924. hl('List', ']'),
  7925. hl('List', ']'),
  7926. hl('List', ']'),
  7927. hl('PlainAssignment', '=', 1),
  7928. hl('Number', '1', 1),
  7929. })
  7930. check_asgn_parsing('$X += 1', {
  7931. -- 0123456
  7932. ast = {
  7933. {
  7934. 'Assignment(Add):0:2: +=',
  7935. children = {
  7936. 'Environment(ident=X):0:0:$X',
  7937. 'Integer(val=1):0:5: 1',
  7938. },
  7939. },
  7940. },
  7941. }, {
  7942. hl('EnvironmentSigil', '$'),
  7943. hl('EnvironmentName', 'X'),
  7944. hl('AssignmentWithAddition', '+=', 1),
  7945. hl('Number', '1', 1),
  7946. })
  7947. check_asgn_parsing('@a .= 1', {
  7948. -- 0123456
  7949. ast = {
  7950. {
  7951. 'Assignment(Concat):0:2: .=',
  7952. children = {
  7953. 'Register(name=a):0:0:@a',
  7954. 'Integer(val=1):0:5: 1',
  7955. },
  7956. },
  7957. },
  7958. }, {
  7959. hl('Register', '@a'),
  7960. hl('AssignmentWithConcatenation', '.=', 1),
  7961. hl('Number', '1', 1),
  7962. })
  7963. check_asgn_parsing('&option -= 1', {
  7964. -- 012345678901
  7965. -- 0 1
  7966. ast = {
  7967. {
  7968. 'Assignment(Subtract):0:7: -=',
  7969. children = {
  7970. 'Option(scope=0,ident=option):0:0:&option',
  7971. 'Integer(val=1):0:10: 1',
  7972. },
  7973. },
  7974. },
  7975. }, {
  7976. hl('OptionSigil', '&'),
  7977. hl('OptionName', 'option'),
  7978. hl('AssignmentWithSubtraction', '-=', 1),
  7979. hl('Number', '1', 1),
  7980. })
  7981. check_asgn_parsing('[$X, @a, &l:option] = [1, 2, 3]', {
  7982. -- 0123456789012345678901234567890
  7983. -- 0 1 2 3
  7984. ast = {
  7985. {
  7986. 'Assignment(Plain):0:19: =',
  7987. children = {
  7988. {
  7989. 'ListLiteral:0:0:[',
  7990. children = {
  7991. {
  7992. 'Comma:0:3:,',
  7993. children = {
  7994. 'Environment(ident=X):0:1:$X',
  7995. {
  7996. 'Comma:0:7:,',
  7997. children = {
  7998. 'Register(name=a):0:4: @a',
  7999. 'Option(scope=l,ident=option):0:8: &l:option',
  8000. },
  8001. },
  8002. },
  8003. },
  8004. },
  8005. },
  8006. {
  8007. 'ListLiteral:0:21: [',
  8008. children = {
  8009. {
  8010. 'Comma:0:24:,',
  8011. children = {
  8012. 'Integer(val=1):0:23:1',
  8013. {
  8014. 'Comma:0:27:,',
  8015. children = {
  8016. 'Integer(val=2):0:25: 2',
  8017. 'Integer(val=3):0:28: 3',
  8018. },
  8019. },
  8020. },
  8021. },
  8022. },
  8023. },
  8024. },
  8025. },
  8026. },
  8027. }, {
  8028. hl('List', '['),
  8029. hl('EnvironmentSigil', '$'),
  8030. hl('EnvironmentName', 'X'),
  8031. hl('Comma', ','),
  8032. hl('Register', '@a', 1),
  8033. hl('Comma', ','),
  8034. hl('OptionSigil', '&', 1),
  8035. hl('OptionScope', 'l'),
  8036. hl('OptionScopeDelimiter', ':'),
  8037. hl('OptionName', 'option'),
  8038. hl('List', ']'),
  8039. hl('PlainAssignment', '=', 1),
  8040. hl('List', '[', 1),
  8041. hl('Number', '1'),
  8042. hl('Comma', ','),
  8043. hl('Number', '2', 1),
  8044. hl('Comma', ','),
  8045. hl('Number', '3', 1),
  8046. hl('List', ']'),
  8047. })
  8048. end)
  8049. itp('works with non-ASCII characters', function()
  8050. check_parsing('"«»"«»', {
  8051. -- 013568
  8052. ast = {
  8053. {
  8054. 'OpMissing:0:6:',
  8055. children = {
  8056. 'DoubleQuotedString(val="«»"):0:0:"«»"',
  8057. {
  8058. 'ComplexIdentifier:0:8:',
  8059. children = {
  8060. 'PlainIdentifier(scope=0,ident=«):0:6:«',
  8061. 'PlainIdentifier(scope=0,ident=»):0:8:»',
  8062. },
  8063. },
  8064. },
  8065. },
  8066. },
  8067. err = {
  8068. arg = '«»',
  8069. msg = 'E15: Unidentified character: %.*s',
  8070. },
  8071. }, {
  8072. hl('DoubleQuote', '"'),
  8073. hl('DoubleQuotedBody', '«»'),
  8074. hl('DoubleQuote', '"'),
  8075. hl('InvalidIdentifierName', '«'),
  8076. hl('InvalidIdentifierName', '»'),
  8077. }, {
  8078. [1] = {
  8079. ast = {
  8080. ast = {
  8081. 'DoubleQuotedString(val="«»"):0:0:"«»"',
  8082. },
  8083. len = 6,
  8084. },
  8085. hl_fs = {
  8086. [5] = REMOVE_THIS,
  8087. [4] = REMOVE_THIS,
  8088. },
  8089. },
  8090. })
  8091. check_parsing('"\192"\192"foo"', {
  8092. -- 01 23 45678
  8093. ast = {
  8094. {
  8095. 'OpMissing:0:3:',
  8096. children = {
  8097. 'DoubleQuotedString(val="\192"):0:0:"\192"',
  8098. {
  8099. 'OpMissing:0:4:',
  8100. children = {
  8101. 'PlainIdentifier(scope=0,ident=\192):0:3:\192',
  8102. 'DoubleQuotedString(val="foo"):0:4:"foo"',
  8103. },
  8104. },
  8105. },
  8106. },
  8107. },
  8108. err = {
  8109. arg = '\192"foo"',
  8110. msg = 'E15: Unidentified character: %.*s',
  8111. },
  8112. }, {
  8113. hl('DoubleQuote', '"'),
  8114. hl('DoubleQuotedBody', '\192'),
  8115. hl('DoubleQuote', '"'),
  8116. hl('InvalidIdentifierName', '\192'),
  8117. hl('InvalidDoubleQuote', '"'),
  8118. hl('InvalidDoubleQuotedBody', 'foo'),
  8119. hl('InvalidDoubleQuote', '"'),
  8120. }, {
  8121. [1] = {
  8122. ast = {
  8123. ast = {
  8124. 'DoubleQuotedString(val="\192"):0:0:"\192"',
  8125. },
  8126. len = 3,
  8127. },
  8128. hl_fs = {
  8129. [4] = REMOVE_THIS,
  8130. [5] = REMOVE_THIS,
  8131. [6] = REMOVE_THIS,
  8132. [7] = REMOVE_THIS,
  8133. },
  8134. },
  8135. })
  8136. end)
  8137. end