function words(str){for(var obj={},words2=str.split(","),i=0;i<words2.length;++i){var allCaps=words2[i].toUpperCase(),firstCap=words2[i].charAt(0).toUpperCase()+words2[i].slice(1);obj[words2[i]]=!0,obj[allCaps]=!0,obj[firstCap]=!0}return obj}function metaHook(stream){return stream.eatWhile(/[\w\$_]/),"meta"}var curPunc,atoms=words("null"),hooks={"`":metaHook,$:metaHook},keywords=words("abs,access,after,alias,all,and,architecture,array,assert,attribute,begin,block,body,buffer,bus,case,component,configuration,constant,disconnect,downto,else,elsif,end,end block,end case,end component,end for,end generate,end if,end loop,end process,end record,end units,entity,exit,file,for,function,generate,generic,generic map,group,guarded,if,impure,in,inertial,inout,is,label,library,linkage,literal,loop,map,mod,nand,new,next,nor,null,of,on,open,or,others,out,package,package body,port,port map,postponed,procedure,process,pure,range,record,register,reject,rem,report,return,rol,ror,select,severity,signal,sla,sll,sra,srl,subtype,then,to,transport,type,unaffected,units,until,use,variable,wait,when,while,with,xnor,xor"),blockKeywords=words("architecture,entity,begin,case,port,else,elsif,end,for,function,if"),isOperatorChar=/[&|~><!\)\(*#%@+\/=?\:;}{,\.\^\-\[\]]/;function tokenBase(stream,state){var quote,ch=stream.next();if(hooks[ch]){var result=hooks[ch](stream,state);if(!1!==result)return result}if('"'==ch)return state.tokenize=(quote=ch,function(stream,state){for(var next,escaped=!1,end=!1;null!=(next=stream.next());){if(next==quote&&!escaped){end=!0;break}escaped=!escaped&&"--"==next}return!end&&escaped||(state.tokenize=tokenBase),"string.special"}),state.tokenize(stream,state);if("'"==ch)return state.tokenize=function(quote){return function(stream,state){for(var next,escaped=!1,end=!1;null!=(next=stream.next());){if(next==quote&&!escaped){end=!0;break}escaped=!escaped&&"--"==next}return!end&&escaped||(state.tokenize=tokenBase),"string"}}(ch),state.tokenize(stream,state);if(/[\[\]{}\(\),;\:\.]/.test(ch))return curPunc=ch,null;if(/[\d']/.test(ch))return stream.eatWhile(/[\w\.']/),"number";if("-"==ch&&stream.eat("-"))return stream.skipToEnd(),"comment";if(isOperatorChar.test(ch))return stream.eatWhile(isOperatorChar),"operator";stream.eatWhile(/[\w\$_]/);var cur=stream.current();return keywords.propertyIsEnumerable(cur.toLowerCase())?(blockKeywords.propertyIsEnumerable(cur)&&(curPunc="newstatement"),"keyword"):atoms.propertyIsEnumerable(cur)?"atom":"variable"}function Context(indented,column,type,align,prev){this.indented=indented,this.column=column,this.type=type,this.align=align,this.prev=prev}function pushContext(state,col,type){return state.context=new Context(state.indented,col,type,null,state.context)}function popContext(state){var t=state.context.type;return")"!=t&&"]"!=t&&"}"!=t||(state.indented=state.context.indented),state.context=state.context.prev}const vhdl={name:"vhdl",startState:function(indentUnit){return{tokenize:null,context:new Context(-indentUnit,0,"top",!1),indented:0,startOfLine:!0}},token:function(stream,state){var ctx=state.context;if(stream.sol()&&(null==ctx.align&&(ctx.align=!1),state.indented=stream.indentation(),state.startOfLine=!0),stream.eatSpace())return null;curPunc=null;var style=(state.tokenize||tokenBase)(stream,state);if("comment"==style||"meta"==style)return style;if(null==ctx.align&&(ctx.align=!0),";"!=curPunc&&":"!=curPunc||"statement"!=ctx.type)if("{"==curPunc)pushContext(state,stream.column(),"}");else if("["==curPunc)pushContext(state,stream.column(),"]");else if("("==curPunc)pushContext(state,stream.column(),")");else if("}"==curPunc){for(;"statement"==ctx.type;)ctx=popContext(state);for("}"==ctx.type&&(ctx=popContext(state));"statement"==ctx.type;)ctx=popContext(state)}else curPunc==ctx.type?popContext(state):("}"==ctx.type||"top"==ctx.type||"statement"==ctx.type&&"newstatement"==curPunc)&&pushContext(state,stream.column(),"statement");else popContext(state);return state.startOfLine=!1,style},indent:function(state,textAfter,cx){if(state.tokenize!=tokenBase&&null!=state.tokenize)return 0;var firstChar=textAfter&&textAfter.charAt(0),ctx=state.context,closing=firstChar==ctx.type;return"statement"==ctx.type?ctx.indented+("{"==firstChar?0:cx.unit):ctx.align?ctx.column+(closing?0:1):ctx.indented+(closing?0:cx.unit)},languageData:{indentOnInput:/^\s*[{}]$/,commentTokens:{line:"--"}}};export{vhdl};
