var curPunc;function wordRegexp(t){return new RegExp("^(?:"+t.join("|")+")$","i")}var ops=wordRegexp(["str","lang","langmatches","datatype","bound","sameterm","isiri","isuri","iri","uri","bnode","count","sum","min","max","avg","sample","group_concat","rand","abs","ceil","floor","round","concat","substr","strlen","replace","ucase","lcase","encode_for_uri","contains","strstarts","strends","strbefore","strafter","year","month","day","hours","minutes","seconds","timezone","tz","now","uuid","struuid","md5","sha1","sha256","sha384","sha512","coalesce","if","strlang","strdt","isnumeric","regex","exists","isblank","isliteral","a","bind"]),keywords=wordRegexp(["base","prefix","select","distinct","reduced","construct","describe","ask","from","named","where","order","limit","offset","filter","optional","graph","by","asc","desc","as","having","undef","values","group","minus","in","not","service","silent","using","insert","delete","union","true","false","with","data","copy","to","move","add","create","drop","clear","load"]),operatorChars=/[*+\-<>=&|\^\/!\?]/;function tokenBase(t,e){var n=t.next();if(curPunc=null,"$"==n||"?"==n)return "?"==n&&t.match(/\s/,!1)?"operator":(t.match(/^[A-Za-z0-9_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][A-Za-z0-9_\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]*/),"variableName.local");if("<"!=n||t.match(/^[\s\u00a0=]/,!1)){if('"'==n||"'"==n)return e.tokenize=tokenLiteral(n),e.tokenize(t,e);if(/[{}\(\),\.;\[\]]/.test(n))return curPunc=n,"bracket";if("#"==n)return t.skipToEnd(),"comment";if("^"===n)return "^"===(n=t.peek())?t.eat("^"):t.eatWhile(operatorChars),"operator";if(operatorChars.test(n))return t.eatWhile(operatorChars),"operator";if(":"==n)return eatPnLocal(t),"atom";if("@"==n)return t.eatWhile(/[a-z\d\-]/i),"meta";if(t.eatWhile(/[_\w\d]/),t.eat(":"))return eatPnLocal(t),"atom";var r=t.current();return ops.test(r)?"builtin":keywords.test(r)?"keyword":"variable"}return t.match(/^[^\s\u00a0>]*>?/),"atom"}function eatPnLocal(t){for(;t.match(/([:\w\d._-]|\\[-\\_~.!$&'()*+,;=/?#@%]|%[a-fA-F0-9][a-fA-F0-9])/););}function tokenLiteral(t){return function(e,n){for(var r,o=!1;null!=(r=e.next());){if(r==t&&!o){n.tokenize=tokenBase;break}o=!o&&"\\"==r;}return "string"}}function pushContext(t,e,n){t.context={prev:t.context,indent:t.indent,col:n,type:e};}function popContext(t){t.indent=t.context.indent,t.context=t.context.prev;}const sparql={startState:function(){return {tokenize:tokenBase,context:null,indent:0,col:0}},token:function(t,e){if(t.sol()&&(e.context&&null==e.context.align&&(e.context.align=!1),e.indent=t.indentation()),t.eatSpace())return null;var n=e.tokenize(t,e);if("comment"!=n&&e.context&&null==e.context.align&&"pattern"!=e.context.type&&(e.context.align=!0),"("==curPunc)pushContext(e,")",t.column());else if("["==curPunc)pushContext(e,"]",t.column());else if("{"==curPunc)pushContext(e,"}",t.column());else if(/[\]\}\)]/.test(curPunc)){for(;e.context&&"pattern"==e.context.type;)popContext(e);e.context&&curPunc==e.context.type&&(popContext(e),"}"==curPunc&&e.context&&"pattern"==e.context.type&&popContext(e));}else "."==curPunc&&e.context&&"pattern"==e.context.type?popContext(e):/atom|string|variable/.test(n)&&e.context&&(/[\}\]]/.test(e.context.type)?pushContext(e,"pattern",t.column()):"pattern"!=e.context.type||e.context.align||(e.context.align=!0,e.context.col=t.column()));return n},indent:function(t,e,n){var r=e&&e.charAt(0),o=t.context;if(/[\]\}]/.test(r))for(;o&&"pattern"==o.type;)o=o.prev;var u=o&&r==o.type;return o?"pattern"==o.type?o.col:o.align?o.col+(u?0:1):o.indent+(u?0:n.unit):0},languageData:{commentTokens:{line:"#"}}};

export { sparql };
