function parseWords(e){for(var n={},t=e.split(" "),r=0;r<t.length;++r)n[t[r]]=!0;return n}var keywords=parseWords("#end #else #break #stop #[[ #]] #{end} #{else} #{break} #{stop}"),functions=parseWords("#if #elseif #foreach #set #include #parse #macro #define #evaluate #{if} #{elseif} #{foreach} #{set} #{include} #{parse} #{macro} #{define} #{evaluate}"),specials=parseWords("$foreach.count $foreach.hasNext $foreach.first $foreach.last $foreach.topmost $foreach.parent.count $foreach.parent.hasNext $foreach.parent.first $foreach.parent.last $foreach.parent $velocityCount $!bodyContent $bodyContent"),isOperatorChar=/[+\-*&%=<>!?:\/|]/;function chain(e,n,t){return n.tokenize=t,t(e,n)}function tokenBase(e,n){var t=n.beforeParams;n.beforeParams=!1;var r=e.next();if("'"==r&&!n.inString&&n.inParams)return n.lastTokenWasBuiltin=!1,chain(e,n,tokenString(r));if('"'!=r){if(/[\[\]{}\(\),;\.]/.test(r))return "("==r&&t?n.inParams=!0:")"==r&&(n.inParams=!1,n.lastTokenWasBuiltin=!0),null;if(/\d/.test(r))return n.lastTokenWasBuiltin=!1,e.eatWhile(/[\w\.]/),"number";if("#"==r&&e.eat("*"))return n.lastTokenWasBuiltin=!1,chain(e,n,tokenComment);if("#"==r&&e.match(/ *\[ *\[/))return n.lastTokenWasBuiltin=!1,chain(e,n,tokenUnparsed);if("#"==r&&e.eat("#"))return n.lastTokenWasBuiltin=!1,e.skipToEnd(),"comment";if("$"==r)return e.eatWhile(/[\w\d\$_\.{}-]/),specials&&specials.propertyIsEnumerable(e.current())?"keyword":(n.lastTokenWasBuiltin=!0,n.beforeParams=!0,"builtin");if(isOperatorChar.test(r))return n.lastTokenWasBuiltin=!1,e.eatWhile(isOperatorChar),"operator";e.eatWhile(/[\w\$_{}@]/);var a=e.current();return keywords&&keywords.propertyIsEnumerable(a)?"keyword":functions&&functions.propertyIsEnumerable(a)||e.current().match(/^#@?[a-z0-9_]+ *$/i)&&"("==e.peek()&&(!functions||!functions.propertyIsEnumerable(a.toLowerCase()))?(n.beforeParams=!0,n.lastTokenWasBuiltin=!1,"keyword"):n.inString?(n.lastTokenWasBuiltin=!1,"string"):e.pos>a.length&&"."==e.string.charAt(e.pos-a.length-1)&&n.lastTokenWasBuiltin?"builtin":(n.lastTokenWasBuiltin=!1,null)}return n.lastTokenWasBuiltin=!1,n.inString?(n.inString=!1,"string"):n.inParams?chain(e,n,tokenString(r)):void 0}function tokenString(e){return function(n,t){for(var r,a=!1,i=!1;null!=(r=n.next());){if(r==e&&!a){i=!0;break}if('"'==e&&"$"==n.peek()&&!a){t.inString=!0,i=!0;break}a=!a&&"\\"==r;}return i&&(t.tokenize=tokenBase),"string"}}function tokenComment(e,n){for(var t,r=!1;t=e.next();){if("#"==t&&r){n.tokenize=tokenBase;break}r="*"==t;}return "comment"}function tokenUnparsed(e,n){for(var t,r=0;t=e.next();){if("#"==t&&2==r){n.tokenize=tokenBase;break}"]"==t?r++:" "!=t&&(r=0);}return "meta"}const velocity={startState:function(){return {tokenize:tokenBase,beforeParams:!1,inParams:!1,inString:!1,lastTokenWasBuiltin:!1}},token:function(e,n){return e.eatSpace()?null:n.tokenize(e,n)},languageData:{commentTokens:{line:"##",block:{open:"#*",close:"*#"}}}};

export { velocity };
