function words(e){for(var t={},n=e.split(","),r=0;r<n.length;++r){var o=n[r].toUpperCase(),i=n[r].charAt(0).toUpperCase()+n[r].slice(1);t[n[r]]=!0,t[o]=!0,t[i]=!0;}return t}function metaHook(e){return e.eatWhile(/[\w\$_]/),"meta"}var curPunc,atoms=words("null"),hooks={"`":metaHook,$:metaHook},multiLineStrings=!1,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(e,t){var n=e.next();if(hooks[n]){var r=hooks[n](e,t);if(!1!==r)return r}if('"'==n)return t.tokenize=tokenString2(n),t.tokenize(e,t);if("'"==n)return t.tokenize=tokenString(n),t.tokenize(e,t);if(/[\[\]{}\(\),;\:\.]/.test(n))return curPunc=n,null;if(/[\d']/.test(n))return e.eatWhile(/[\w\.']/),"number";if("-"==n&&e.eat("-"))return e.skipToEnd(),"comment";if(isOperatorChar.test(n))return e.eatWhile(isOperatorChar),"operator";e.eatWhile(/[\w\$_]/);var o=e.current();return keywords.propertyIsEnumerable(o.toLowerCase())?(blockKeywords.propertyIsEnumerable(o)&&(curPunc="newstatement"),"keyword"):atoms.propertyIsEnumerable(o)?"atom":"variable"}function tokenString(e){return function(t,n){for(var r,o=!1,i=!1;null!=(r=t.next());){if(r==e&&!o){i=!0;break}o=!o&&"--"==r;}return (i||!o&&!multiLineStrings)&&(n.tokenize=tokenBase),"string"}}function tokenString2(e){return function(t,n){for(var r,o=!1,i=!1;null!=(r=t.next());){if(r==e&&!o){i=!0;break}o=!o&&"--"==r;}return (i||!o&&!multiLineStrings)&&(n.tokenize=tokenBase),"string.special"}}function Context(e,t,n,r,o){this.indented=e,this.column=t,this.type=n,this.align=r,this.prev=o;}function pushContext(e,t,n){return e.context=new Context(e.indented,t,n,null,e.context)}function popContext(e){var t=e.context.type;return ")"!=t&&"]"!=t&&"}"!=t||(e.indented=e.context.indented),e.context=e.context.prev}const vhdl={startState:function(e){return {tokenize:null,context:new Context(-e,0,"top",!1),indented:0,startOfLine:!0}},token:function(e,t){var n=t.context;if(e.sol()&&(null==n.align&&(n.align=!1),t.indented=e.indentation(),t.startOfLine=!0),e.eatSpace())return null;curPunc=null;var r=(t.tokenize||tokenBase)(e,t);if("comment"==r||"meta"==r)return r;if(null==n.align&&(n.align=!0),";"!=curPunc&&":"!=curPunc||"statement"!=n.type)if("{"==curPunc)pushContext(t,e.column(),"}");else if("["==curPunc)pushContext(t,e.column(),"]");else if("("==curPunc)pushContext(t,e.column(),")");else if("}"==curPunc){for(;"statement"==n.type;)n=popContext(t);for("}"==n.type&&(n=popContext(t));"statement"==n.type;)n=popContext(t);}else curPunc==n.type?popContext(t):("}"==n.type||"top"==n.type||"statement"==n.type&&"newstatement"==curPunc)&&pushContext(t,e.column(),"statement");else popContext(t);return t.startOfLine=!1,r},indent:function(e,t,n){if(e.tokenize!=tokenBase&&null!=e.tokenize)return 0;var r=t&&t.charAt(0),o=e.context,i=r==o.type;return "statement"==o.type?o.indented+("{"==r?0:n.unit):o.align?o.column+(i?0:1):o.indented+(i?0:n.unit)},languageData:{indentOnInput:/^\s*[{}]$/,commentTokens:{line:"--"}}};

export { vhdl };
