|
|
- import{ContextTracker,ExternalTokenizer,LRParser}from"@lezer/lr";import{styleTags,tags}from"@lezer/highlight";const TSExtends=1,noSemi=281,incdec=2,incdecPrefix=3,templateContent=282,InterpolationStart=4,templateEnd=283,insertSemi=284,spaces=286,newline=287,LineComment=5,BlockComment=6,Dialect_ts=1;const space=[9,10,11,12,13,32,133,160,5760,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8232,8233,8239,8287,12288];const braceR=125,braceL=123,semicolon=59,slash=47,star=42,plus=43,minus=45,dollar=36,backtick=96,backslash=92;const trackNewline=new ContextTracker({start:false,shift(context,term){return term==LineComment||term==BlockComment||term==spaces?context:term==newline},strict:false});const insertSemicolon=new ExternalTokenizer((input,stack)=>{let{next}=input;if((next==braceR||next==-1||stack.context)&&stack.canShift(insertSemi))input.acceptToken(insertSemi)},{contextual:true,fallback:true});const noSemicolon=new ExternalTokenizer((input,stack)=>{let{next}=input,after;if(space.indexOf(next)>-1)return;if(next==slash&&((after=input.peek(1))==slash||after==star))return;if(next!=braceR&&next!=semicolon&&next!=-1&&!stack.context&&stack.canShift(noSemi))input.acceptToken(noSemi)},{contextual:true});const incdecToken=new ExternalTokenizer((input,stack)=>{let{next}=input;if(next==plus||next==minus){input.advance();if(next==input.next){input.advance();let mayPostfix=!stack.context&&stack.canShift(incdec);input.acceptToken(mayPostfix?incdec:incdecPrefix)}}},{contextual:true});const template=new ExternalTokenizer(input=>{for(let afterDollar=false,i=0;;i++){let{next}=input;if(next<0){if(i)input.acceptToken(templateContent);break}else if(next==backtick){if(i)input.acceptToken(templateContent);else input.acceptToken(templateEnd,1);break}else if(next==braceL&&afterDollar){if(i==1)input.acceptToken(InterpolationStart,1);else input.acceptToken(templateContent,-1);break}else if(next==10&&i){input.advance();input.acceptToken(templateContent);break}else if(next==backslash){input.advance()}afterDollar=next==dollar;input.advance()}});const tsExtends=new ExternalTokenizer((input,stack)=>{if(input.next!=101||!stack.dialectEnabled(Dialect_ts))return;input.advance();for(let i=0;i<6;i++){if(input.next!="xtends".charCodeAt(i))return;input.advance()}if(input.next>=57&&input.next<=65||input.next>=48&&input.next<=90||input.next==95||input.next>=97&&input.next<=122||input.next>160)return;input.acceptToken(TSExtends)});const jsHighlight=styleTags({"get set async static":tags.modifier,"for while do if else switch try catch finally return throw break continue default case":tags.controlKeyword,"in of await yield void typeof delete instanceof":tags.operatorKeyword,"let var const function class extends":tags.definitionKeyword,"import export from":tags.moduleKeyword,"with debugger as new":tags.keyword,TemplateString:tags.special(tags.string),super:tags.atom,BooleanLiteral:tags.bool,this:tags.self,null:tags.null,Star:tags.modifier,VariableName:tags.variableName,"CallExpression/VariableName TaggedTemplateExpression/VariableName":tags.function(tags.variableName),VariableDefinition:tags.definition(tags.variableName),Label:tags.labelName,PropertyName:tags.propertyName,PrivatePropertyName:tags.special(tags.propertyName),"CallExpression/MemberExpression/PropertyName":tags.function(tags.propertyName),"FunctionDeclaration/VariableDefinition":tags.function(tags.definition(tags.variableName)),"ClassDeclaration/VariableDefinition":tags.definition(tags.className),PropertyDefinition:tags.definition(tags.propertyName),PrivatePropertyDefinition:tags.definition(tags.special(tags.propertyName)),UpdateOp:tags.updateOperator,LineComment:tags.lineComment,BlockComment:tags.blockComment,Number:tags.number,String:tags.string,ArithOp:tags.arithmeticOperator,LogicOp:tags.logicOperator,BitOp:tags.bitwiseOperator,CompareOp:tags.compareOperator,RegExp:tags.regexp,Equals:tags.definitionOperator,Arrow:tags.function(tags.punctuation),": Spread":tags.punctuation,"( )":tags.paren,"[ ]":tags.squareBracket,"{ }":tags.brace,"InterpolationStart InterpolationEnd":tags.special(tags.brace)
|