turtle-web-editor/js/turtle.min.js

1 line
2.1 KiB
JavaScript
Raw Normal View History

2020-04-29 15:43:06 +02:00
!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],t):t(CodeMirror)}(function(t){"use strict";t.defineMode("turtle",function(t){var i,c=t.indentUnit;function e(t){return new RegExp("^(?:"+t.join("|")+")$","i")}e([]);var l=e(["@prefix","@base","a"]),u=/[*+\-<>=&|]/;function a(t,e){var r,n=t.next();if(i=null,"<"!=n||t.match(/^[\s\u00a0=]/,!1)){if('"'==n||"'"==n)return e.tokenize=(r=n,function(t,e){for(var n,o=!1;null!=(n=t.next());){if(n==r&&!o){e.tokenize=a;break}o=!o&&"\\"==n}return"string"}),e.tokenize(t,e);if(/[{}\(\),\.;\[\]]/.test(n))return i=n,null;if("#"==n)return t.skipToEnd(),"comment";if(u.test(n))return t.eatWhile(u),null;if(":"==n)return"operator";if(t.eatWhile(/[_\w\d]/),":"==t.peek())return"variable-3";var o=t.current();return l.test(o)?"meta":"A"<=n&&n<="Z"?"comment":"keyword"}return t.match(/^[^\s\u00a0>]*>?/),"atom"}function o(t,e,n){t.context={prev:t.context,indent:t.indent,col:n,type:e}}function r(t){t.indent=t.context.indent,t.context=t.context.prev}return{startState:function(){return{tokenize:a,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),"("==i)o(e,")",t.column());else if("["==i)o(e,"]",t.column());else if("{"==i)o(e,"}",t.column());else if(/[\]\}\)]/.test(i)){for(;e.context&&"pattern"==e.context.type;)r(e);e.context&&i==e.context.type&&r(e)}else"."==i&&e.context&&"pattern"==e.context.type?r(e):/atom|string|variable/.test(n)&&e.context&&(/[\}\]]/.test(e.context.type)?o(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){var n=e&&e.charAt(0),o=t.context;if(/[\]\}]/.test(n))for(;o&&"pattern"==o.type;)o=o.prev;var r=o&&n==o.type;return o?"pattern"==o.type?o.col:o.align?o.col+(r?0:1):o.indent+(r?0:c):0},lineComment:"#"}}),t.defineMIME("text/turtle","turtle")});