LaravelTest
162 строки · 4.7 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("turtle", function(config) {15var indentUnit = config.indentUnit;16var curPunc;17
18function wordRegexp(words) {19return new RegExp("^(?:" + words.join("|") + ")$", "i");20}21var ops = wordRegexp([]);22var keywords = wordRegexp(["@prefix", "@base", "a"]);23var operatorChars = /[*+\-<>=&|]/;24
25function tokenBase(stream, state) {26var ch = stream.next();27curPunc = null;28if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) {29stream.match(/^[^\s\u00a0>]*>?/);30return "atom";31}32else if (ch == "\"" || ch == "'") {33state.tokenize = tokenLiteral(ch);34return state.tokenize(stream, state);35}36else if (/[{}\(\),\.;\[\]]/.test(ch)) {37curPunc = ch;38return null;39}40else if (ch == "#") {41stream.skipToEnd();42return "comment";43}44else if (operatorChars.test(ch)) {45stream.eatWhile(operatorChars);46return null;47}48else if (ch == ":") {49return "operator";50} else {51stream.eatWhile(/[_\w\d]/);52if(stream.peek() == ":") {53return "variable-3";54} else {55var word = stream.current();56
57if(keywords.test(word)) {58return "meta";59}60
61if(ch >= "A" && ch <= "Z") {62return "comment";63} else {64return "keyword";65}66}67var word = stream.current();68if (ops.test(word))69return null;70else if (keywords.test(word))71return "meta";72else73return "variable";74}75}76
77function tokenLiteral(quote) {78return function(stream, state) {79var escaped = false, ch;80while ((ch = stream.next()) != null) {81if (ch == quote && !escaped) {82state.tokenize = tokenBase;83break;84}85escaped = !escaped && ch == "\\";86}87return "string";88};89}90
91function pushContext(state, type, col) {92state.context = {prev: state.context, indent: state.indent, col: col, type: type};93}94function popContext(state) {95state.indent = state.context.indent;96state.context = state.context.prev;97}98
99return {100startState: function() {101return {tokenize: tokenBase,102context: null,103indent: 0,104col: 0};105},106
107token: function(stream, state) {108if (stream.sol()) {109if (state.context && state.context.align == null) state.context.align = false;110state.indent = stream.indentation();111}112if (stream.eatSpace()) return null;113var style = state.tokenize(stream, state);114
115if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") {116state.context.align = true;117}118
119if (curPunc == "(") pushContext(state, ")", stream.column());120else if (curPunc == "[") pushContext(state, "]", stream.column());121else if (curPunc == "{") pushContext(state, "}", stream.column());122else if (/[\]\}\)]/.test(curPunc)) {123while (state.context && state.context.type == "pattern") popContext(state);124if (state.context && curPunc == state.context.type) popContext(state);125}126else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state);127else if (/atom|string|variable/.test(style) && state.context) {128if (/[\}\]]/.test(state.context.type))129pushContext(state, "pattern", stream.column());130else if (state.context.type == "pattern" && !state.context.align) {131state.context.align = true;132state.context.col = stream.column();133}134}135
136return style;137},138
139indent: function(state, textAfter) {140var firstChar = textAfter && textAfter.charAt(0);141var context = state.context;142if (/[\]\}]/.test(firstChar))143while (context && context.type == "pattern") context = context.prev;144
145var closing = context && firstChar == context.type;146if (!context)147return 0;148else if (context.type == "pattern")149return context.col;150else if (context.align)151return context.col + (closing ? 0 : 1);152else153return context.indent + (closing ? 0 : indentUnit);154},155
156lineComment: "#"157};158});159
160CodeMirror.defineMIME("text/turtle", "turtle");161
162});163