(function(mod){if("object"==typeof exports&&"object"==typeof module)mod(require("../../lib/codemirror"));else if("function"==typeof define&&define.amd)define(["../../lib/codemirror"],mod);else mod(CodeMirror)})(function(CodeMirror){"use strict";CodeMirror.defineMode("velocity",function(){function parseWords(str){for(var obj={},words=str.split(" "),i=0;i<words.length;++i)obj[words[i]]=!0;return obj}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(stream,state,f){state.tokenize=f;return f(stream,state)}function tokenBase(stream,state){var beforeParams=state.beforeParams;state.beforeParams=!1;var ch=stream.next();if("'"==ch&&!state.inString&&state.inParams){state.lastTokenWasBuiltin=!1;return chain(stream,state,tokenString(ch))}else if("\""==ch){state.lastTokenWasBuiltin=!1;if(state.inString){state.inString=!1;return"string"}else if(state.inParams)return chain(stream,state,tokenString(ch))}else if(/[\[\]{}\(\),;\.]/.test(ch)){if("("==ch&&beforeParams)state.inParams=!0;else if(")"==ch){state.inParams=!1;state.lastTokenWasBuiltin=!0}return null}else if(/\d/.test(ch)){state.lastTokenWasBuiltin=!1;stream.eatWhile(/[\w\.]/);return"number"}else if("#"==ch&&stream.eat("*")){state.lastTokenWasBuiltin=!1;return chain(stream,state,tokenComment)}else if("#"==ch&&stream.match(/ *\[ *\[/)){state.lastTokenWasBuiltin=!1;return chain(stream,state,tokenUnparsed)}else if("#"==ch&&stream.eat("#")){state.lastTokenWasBuiltin=!1;stream.skipToEnd();return"comment"}else if("$"==ch){stream.eatWhile(/[\w\d\$_\.{}-]/);if(specials&&specials.propertyIsEnumerable(stream.current())){return"keyword"}else{state.lastTokenWasBuiltin=!0;state.beforeParams=!0;return"builtin"}}else if(isOperatorChar.test(ch)){state.lastTokenWasBuiltin=!1;stream.eatWhile(isOperatorChar);return"operator"}else{stream.eatWhile(/[\w\$_{}@]/);var word=stream.current();if(keywords&&keywords.propertyIsEnumerable(word))return"keyword";if(functions&&functions.propertyIsEnumerable(word)||stream.current().match(/^#@?[a-z0-9_]+ *$/i)&&"("==stream.peek()&&!(functions&&functions.propertyIsEnumerable(word.toLowerCase()))){state.beforeParams=!0;state.lastTokenWasBuiltin=!1;return"keyword"}if(state.inString){state.lastTokenWasBuiltin=!1;return"string"}if(stream.pos>word.length&&"."==stream.string.charAt(stream.pos-word.length-1)&&state.lastTokenWasBuiltin)return"builtin";state.lastTokenWasBuiltin=!1;return null}}function tokenString(quote){return function(stream,state){var escaped=!1,next,end=!1;while(null!=(next=stream.next())){if(next==quote&&!escaped){end=!0;break}if("\""==quote&&"$"==stream.peek()&&!escaped){state.inString=!0;end=!0;break}escaped=!escaped&&"\\"==next}if(end)state.tokenize=tokenBase;return"string"}}function tokenComment(stream,state){var maybeEnd=!1,ch;while(ch=stream.next()){if("#"==ch&&maybeEnd){state.tokenize=tokenBase;break}maybeEnd="*"==ch}return"comment"}function tokenUnparsed(stream,state){var maybeEnd=0,ch;while(ch=stream.next()){if("#"==ch&&2==maybeEnd){state.tokenize=tokenBase;break}if("]"==ch)maybeEnd++;else if(" "!=ch)maybeEnd=0}return"meta"}return{startState:function(){return{tokenize:tokenBase,beforeParams:!1,inParams:!1,inString:!1,lastTokenWasBuiltin:!1}},token:function(stream,state){if(stream.eatSpace())return null;return state.tokenize(stream,state)},blockCommentStart:"#*",blockCommentEnd:"*#",lineComment:"##",fold:"velocity"}});CodeMirror.defineMIME("text/velocity","velocity")});