You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
3.5 KiB
1 lines
3.5 KiB
var i=function(e){return new RegExp("^(?:"+e.join("|")+")$","i")},p=function(e){a=null;var t=e.next();if(t==='"')return e.match(/^.*?"/),"string";if(t==="'")return e.match(/^.*?'/),"string";if(/[{}\(\),\.;\[\]]/.test(t))return a=t,"punctuation";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 u.test(n)?"builtin":m.test(n)?"def":x.test(n)||h.test(n)?"keyword":"variable"},o=function(e,t,n){return e.context={prev:e.context,indent:e.indent,col:n,type:t}},s=function(e){return e.indent=e.context.indent,e.context=e.context.prev},a,u=i(["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"]),m=i(["all","and","any","contains","exists","has","in","none","not","or","single","xor"]),x=i(["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"]),h=i(["access","active","assign","all","alter","as","catalog","change","copy","create","constraint","constraints","current","database","databases","dbms","default","deny","drop","element","elements","exists","from","grant","graph","graphs","if","index","indexes","label","labels","management","match","name","names","new","node","nodes","not","of","on","or","password","populated","privileges","property","read","relationship","relationships","remove","replace","required","revoke","role","roles","set","show","start","status","stop","suspended","to","traverse","type","types","user","users","with","write"]),d=/[*+\-<>=&|~%^]/;const f={name:"cypher",startState:function(){return{tokenize:p,context:null,indent:0,col:0}},token:function(e,t){if(e.sol()&&(t.context&&t.context.align==null&&(t.context.align=!1),t.indent=e.indentation()),e.eatSpace())return null;var n=t.tokenize(e,t);if(n!=="comment"&&t.context&&t.context.align==null&&t.context.type!=="pattern"&&(t.context.align=!0),a==="(")o(t,")",e.column());else if(a==="[")o(t,"]",e.column());else if(a==="{")o(t,"}",e.column());else if(/[\]\}\)]/.test(a)){for(;t.context&&t.context.type==="pattern";)s(t);t.context&&a===t.context.type&&s(t)}else a==="."&&t.context&&t.context.type==="pattern"?s(t):/atom|string|variable/.test(n)&&t.context&&(/[\}\]]/.test(t.context.type)?o(t,"pattern",e.column()):t.context.type==="pattern"&&!t.context.align&&(t.context.align=!0,t.context.col=e.column()));return n},indent:function(e,t,n){var l=t&&t.charAt(0),r=e.context;if(/[\]\}]/.test(l))for(;r&&r.type==="pattern";)r=r.prev;var c=r&&l===r.type;return r?r.type==="keywords"?null:r.align?r.col+(c?0:1):r.indent+(c?0:n.unit):0}};export{f as cypher};
|