LaravelTest
173 строки · 4.6 Кб
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("fcl", function(config) {15var indentUnit = config.indentUnit;16
17var keywords = {18"term": true,19"method": true, "accu": true,20"rule": true, "then": true, "is": true, "and": true, "or": true,21"if": true, "default": true22};23
24var start_blocks = {25"var_input": true,26"var_output": true,27"fuzzify": true,28"defuzzify": true,29"function_block": true,30"ruleblock": true31};32
33var end_blocks = {34"end_ruleblock": true,35"end_defuzzify": true,36"end_function_block": true,37"end_fuzzify": true,38"end_var": true39};40
41var atoms = {42"true": true, "false": true, "nan": true,43"real": true, "min": true, "max": true, "cog": true, "cogs": true44};45
46var isOperatorChar = /[+\-*&^%:=<>!|\/]/;47
48function tokenBase(stream, state) {49var ch = stream.next();50
51if (/[\d\.]/.test(ch)) {52if (ch == ".") {53stream.match(/^[0-9]+([eE][\-+]?[0-9]+)?/);54} else if (ch == "0") {55stream.match(/^[xX][0-9a-fA-F]+/) || stream.match(/^0[0-7]+/);56} else {57stream.match(/^[0-9]*\.?[0-9]*([eE][\-+]?[0-9]+)?/);58}59return "number";60}61
62if (ch == "/" || ch == "(") {63if (stream.eat("*")) {64state.tokenize = tokenComment;65return tokenComment(stream, state);66}67if (stream.eat("/")) {68stream.skipToEnd();69return "comment";70}71}72if (isOperatorChar.test(ch)) {73stream.eatWhile(isOperatorChar);74return "operator";75}76stream.eatWhile(/[\w\$_\xa1-\uffff]/);77
78var cur = stream.current().toLowerCase();79if (keywords.propertyIsEnumerable(cur) ||80start_blocks.propertyIsEnumerable(cur) ||81end_blocks.propertyIsEnumerable(cur)) {82return "keyword";83}84if (atoms.propertyIsEnumerable(cur)) return "atom";85return "variable";86}87
88
89function tokenComment(stream, state) {90var maybeEnd = false, ch;91while (ch = stream.next()) {92if ((ch == "/" || ch == ")") && maybeEnd) {93state.tokenize = tokenBase;94break;95}96maybeEnd = (ch == "*");97}98return "comment";99}100
101function Context(indented, column, type, align, prev) {102this.indented = indented;103this.column = column;104this.type = type;105this.align = align;106this.prev = prev;107}108
109function pushContext(state, col, type) {110return state.context = new Context(state.indented, col, type, null, state.context);111}112
113function popContext(state) {114if (!state.context.prev) return;115var t = state.context.type;116if (t == "end_block")117state.indented = state.context.indented;118return state.context = state.context.prev;119}120
121// Interface122
123return {124startState: function(basecolumn) {125return {126tokenize: null,127context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),128indented: 0,129startOfLine: true130};131},132
133token: function(stream, state) {134var ctx = state.context;135if (stream.sol()) {136if (ctx.align == null) ctx.align = false;137state.indented = stream.indentation();138state.startOfLine = true;139}140if (stream.eatSpace()) return null;141
142var style = (state.tokenize || tokenBase)(stream, state);143if (style == "comment") return style;144if (ctx.align == null) ctx.align = true;145
146var cur = stream.current().toLowerCase();147
148if (start_blocks.propertyIsEnumerable(cur)) pushContext(state, stream.column(), "end_block");149else if (end_blocks.propertyIsEnumerable(cur)) popContext(state);150
151state.startOfLine = false;152return style;153},154
155indent: function(state, textAfter) {156if (state.tokenize != tokenBase && state.tokenize != null) return 0;157var ctx = state.context;158
159var closing = end_blocks.propertyIsEnumerable(textAfter);160if (ctx.align) return ctx.column + (closing ? 0 : 1);161else return ctx.indented + (closing ? 0 : indentUnit);162},163
164electricChars: "ryk",165fold: "brace",166blockCommentStart: "(*",167blockCommentEnd: "*)",168lineComment: "//"169};170});171
172CodeMirror.defineMIME("text/x-fcl", "fcl");173});174