5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode("fcl", function(config) {
15
var indentUnit = config.indentUnit;
19
"method": true, "accu": true,
20
"rule": true, "then": true, "is": true, "and": true, "or": true,
21
"if": true, "default": true
29
"function_block": true,
34
"end_ruleblock": true,
35
"end_defuzzify": true,
36
"end_function_block": true,
42
"true": true, "false": true, "nan": true,
43
"real": true, "min": true, "max": true, "cog": true, "cogs": true
46
var isOperatorChar = /[+\-*&^%:=<>!|\/]/;
48
function tokenBase(stream, state) {
49
var ch = stream.next();
51
if (/[\d\.]/.test(ch)) {
53
stream.match(/^[0-9]+([eE][\-+]?[0-9]+)?/);
54
} else if (ch == "0") {
55
stream.match(/^[xX][0-9a-fA-F]+/) || stream.match(/^0[0-7]+/);
57
stream.match(/^[0-9]*\.?[0-9]*([eE][\-+]?[0-9]+)?/);
62
if (ch == "/" || ch == "(") {
63
if (stream.eat("*")) {
64
state.tokenize = tokenComment;
65
return tokenComment(stream, state);
67
if (stream.eat("/")) {
72
if (isOperatorChar.test(ch)) {
73
stream.eatWhile(isOperatorChar);
76
stream.eatWhile(/[\w\$_\xa1-\uffff]/);
78
var cur = stream.current().toLowerCase();
79
if (keywords.propertyIsEnumerable(cur) ||
80
start_blocks.propertyIsEnumerable(cur) ||
81
end_blocks.propertyIsEnumerable(cur)) {
84
if (atoms.propertyIsEnumerable(cur)) return "atom";
89
function tokenComment(stream, state) {
90
var maybeEnd = false, ch;
91
while (ch = stream.next()) {
92
if ((ch == "/" || ch == ")") && maybeEnd) {
93
state.tokenize = tokenBase;
96
maybeEnd = (ch == "*");
101
function Context(indented, column, type, align, prev) {
102
this.indented = indented;
103
this.column = column;
109
function pushContext(state, col, type) {
110
return state.context = new Context(state.indented, col, type, null, state.context);
113
function popContext(state) {
114
if (!state.context.prev) return;
115
var t = state.context.type;
116
if (t == "end_block")
117
state.indented = state.context.indented;
118
return state.context = state.context.prev;
124
startState: function(basecolumn) {
127
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
133
token: function(stream, state) {
134
var ctx = state.context;
136
if (ctx.align == null) ctx.align = false;
137
state.indented = stream.indentation();
138
state.startOfLine = true;
140
if (stream.eatSpace()) return null;
142
var style = (state.tokenize || tokenBase)(stream, state);
143
if (style == "comment") return style;
144
if (ctx.align == null) ctx.align = true;
146
var cur = stream.current().toLowerCase();
148
if (start_blocks.propertyIsEnumerable(cur)) pushContext(state, stream.column(), "end_block");
149
else if (end_blocks.propertyIsEnumerable(cur)) popContext(state);
151
state.startOfLine = false;
155
indent: function(state, textAfter) {
156
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
157
var ctx = state.context;
159
var closing = end_blocks.propertyIsEnumerable(textAfter);
160
if (ctx.align) return ctx.column + (closing ? 0 : 1);
161
else return ctx.indented + (closing ? 0 : indentUnit);
164
electricChars: "ryk",
166
blockCommentStart: "(*",
167
blockCommentEnd: "*)",
172
CodeMirror.defineMIME("text/x-fcl", "fcl");