!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(u){"use strict";function n(e){return new RegExp("^(?:"+e.join("|")+")$","i")}u.defineMode("cypher",function(e){function t(e){var t=e.next();if('"'===t)return e.match(/.*?"/),"string";if("'"===t)return e.match(/.*?'/),"string";if(/[{}\(\),\.;\[\]]/.test(t))return o=t,"node";if("/"===t&&e.eat("/"))return e.skipToEnd(),"comment";if(d.test(t))return e.eatWhile(d),null;if(e.eatWhile(/[_\w\d]/),e.eat(":"))return e.eatWhile(/[\w\d_\-]/),"atom";var n=e.current();return c.test(n)?"builtin":s.test(n)?"def":l.test(n)?"keyword":"variable"}function r(e,t,n){return e.context={prev:e.context,indent:e.indent,col:n,type:t}}function i(e){return e.indent=e.context.indent,e.context=e.context.prev}var o,a=e.indentUnit,c=n(["abs","acos","allShortestPaths","asin","atan","atan2","avg","ceil","coalesce","collect","cos","cot","count","degrees","e","endnode","exp","extract","filter","floor","haversin","head","id","keys","labels","last","left","length","log","log10","lower","ltrim","max","min","node","nodes","percentileCont","percentileDisc","pi","radians","rand","range","reduce","rel","relationship","relationships","replace","reverse","right","round","rtrim","shortestPath","sign","sin","size","split","sqrt","startnode","stdev","stdevp","str","substring","sum","tail","tan","timestamp","toFloat","toInt","toString","trim","type","upper"]),s=n(["all","and","any","contains","exists","has","in","none","not","or","single","xor"]),l=n(["as","asc","ascending","assert","by","case","commit","constraint","create","csv","cypher","delete","desc","descending","detach","distinct","drop","else","end","ends","explain","false","fieldterminator","foreach","from","headers","in","index","is","join","limit","load","match","merge","null","on","optional","order","periodic","profile","remove","return","scan","set","skip","start","starts","then","true","union","unique","unwind","using","when","where","with","call","yield"]),d=/[*+\-<>=&|~%^]/;return{startState:function(){return{tokenize:t,context:null,indent:0,col:0}},token:function(e,t){if(e.sol()&&(t.context&&null==t.context.align&&(t.context.align=!1),t.indent=e.indentation()),e.eatSpace())return null;var n=t.tokenize(e,t);if("comment"!==n&&t.context&&null==t.context.align&&"pattern"!==t.context.type&&(t.context.align=!0),"("===o)r(t,")",e.column());else if("["===o)r(t,"]",e.column());else if("{"===o)r(t,"}",e.column());else if(/[\]\}\)]/.test(o)){for(;t.context&&"pattern"===t.context.type;)i(t);t.context&&o===t.context.type&&i(t)}else"."===o&&t.context&&"pattern"===t.context.type?i(t):/atom|string|variable/.test(n)&&t.context&&(/[\}\]]/.test(t.context.type)?r(t,"pattern",e.column()):"pattern"!==t.context.type||t.context.align||(t.context.align=!0,t.context.col=e.column()));return n},indent:function(e,t){var n=t&&t.charAt(0),r=e.context;if(/[\]\}]/.test(n))for(;r&&"pattern"===r.type;)r=r.prev;var i=r&&n===r.type;return r?"keywords"===r.type?u.commands.newlineAndIndent:r.align?r.col+(i?0:1):r.indent+(i?0:a):0}}}),u.modeExtensions.cypher={autoFormatLineBreaks:function(e){for(var t=e.split("\n"),n=/\s+\b(return|where|order by|match|with|skip|limit|create|delete|set)\b\s/g,r=0;r<t.length;r++)t[r]=t[r].replace(n," \n$1 ").trim();return t.join("\n")}},u.defineMIME("application/x-cypher-query","cypher")});