codemirror-rails 3.00 → 3.02
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -2
- data/lib/codemirror/rails/version.rb +2 -2
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/db/.gitkeep +0 -0
- data/test/integration/codemirror_rails_integration_test.rb +1 -1
- data/vendor/assets/javascripts/codemirror.js +385 -152
- data/vendor/assets/javascripts/codemirror/keymaps/vim.js +279 -66
- data/vendor/assets/javascripts/codemirror/modes/apl.js +160 -0
- data/vendor/assets/javascripts/codemirror/modes/asterisk.js +183 -0
- data/vendor/assets/javascripts/codemirror/modes/clike.js +2 -0
- data/vendor/assets/javascripts/codemirror/modes/clojure.js +3 -3
- data/vendor/assets/javascripts/codemirror/modes/css.js +2 -2
- data/vendor/assets/javascripts/codemirror/modes/d.js +205 -0
- data/vendor/assets/javascripts/codemirror/modes/gfm.js +2 -1
- data/vendor/assets/javascripts/codemirror/modes/javascript.js +13 -2
- data/vendor/assets/javascripts/codemirror/modes/markdown.js +8 -7
- data/vendor/assets/javascripts/codemirror/modes/properties.js +0 -0
- data/vendor/assets/javascripts/codemirror/modes/sass.js +349 -0
- data/vendor/assets/javascripts/codemirror/modes/sieve.js +37 -10
- data/vendor/assets/javascripts/codemirror/modes/sql.js +268 -0
- data/vendor/assets/javascripts/codemirror/modes/xquery.js +8 -8
- data/vendor/assets/javascripts/codemirror/utils/collapserange.js +68 -0
- data/vendor/assets/javascripts/codemirror/utils/dialog.js +1 -0
- data/vendor/assets/javascripts/codemirror/utils/foldcode.js +2 -1
- data/vendor/assets/javascripts/codemirror/utils/formatting.js +9 -3
- data/vendor/assets/javascripts/codemirror/utils/javascript-hint.js +5 -4
- data/vendor/assets/javascripts/codemirror/utils/python-hint.js +93 -0
- data/vendor/assets/javascripts/codemirror/utils/runmode-standalone.js +51 -10
- data/vendor/assets/javascripts/codemirror/utils/search.js +20 -8
- data/vendor/assets/javascripts/codemirror/utils/searchcursor.js +17 -10
- data/vendor/assets/stylesheets/codemirror.css +10 -9
- metadata +47 -15
- data/vendor/assets/javascripts/codemirror/modes/xmlpure.js +0 -490
- data/vendor/assets/stylesheets/codemirror/modes/diff.css +0 -3
@@ -0,0 +1,160 @@
|
|
1
|
+
CodeMirror.defineMode("apl", function() {
|
2
|
+
var builtInOps = {
|
3
|
+
".": "innerProduct",
|
4
|
+
"\\": "scan",
|
5
|
+
"/": "reduce",
|
6
|
+
"⌿": "reduce1Axis",
|
7
|
+
"⍀": "scan1Axis",
|
8
|
+
"¨": "each",
|
9
|
+
"⍣": "power"
|
10
|
+
};
|
11
|
+
var builtInFuncs = {
|
12
|
+
"+": ["conjugate", "add"],
|
13
|
+
"−": ["negate", "subtract"],
|
14
|
+
"×": ["signOf", "multiply"],
|
15
|
+
"÷": ["reciprocal", "divide"],
|
16
|
+
"⌈": ["ceiling", "greaterOf"],
|
17
|
+
"⌊": ["floor", "lesserOf"],
|
18
|
+
"∣": ["absolute", "residue"],
|
19
|
+
"⍳": ["indexGenerate", "indexOf"],
|
20
|
+
"?": ["roll", "deal"],
|
21
|
+
"⋆": ["exponentiate", "toThePowerOf"],
|
22
|
+
"⍟": ["naturalLog", "logToTheBase"],
|
23
|
+
"○": ["piTimes", "circularFuncs"],
|
24
|
+
"!": ["factorial", "binomial"],
|
25
|
+
"⌹": ["matrixInverse", "matrixDivide"],
|
26
|
+
"<": [null, "lessThan"],
|
27
|
+
"≤": [null, "lessThanOrEqual"],
|
28
|
+
"=": [null, "equals"],
|
29
|
+
">": [null, "greaterThan"],
|
30
|
+
"≥": [null, "greaterThanOrEqual"],
|
31
|
+
"≠": [null, "notEqual"],
|
32
|
+
"≡": ["depth", "match"],
|
33
|
+
"≢": [null, "notMatch"],
|
34
|
+
"∈": ["enlist", "membership"],
|
35
|
+
"⍷": [null, "find"],
|
36
|
+
"∪": ["unique", "union"],
|
37
|
+
"∩": [null, "intersection"],
|
38
|
+
"∼": ["not", "without"],
|
39
|
+
"∨": [null, "or"],
|
40
|
+
"∧": [null, "and"],
|
41
|
+
"⍱": [null, "nor"],
|
42
|
+
"⍲": [null, "nand"],
|
43
|
+
"⍴": ["shapeOf", "reshape"],
|
44
|
+
",": ["ravel", "catenate"],
|
45
|
+
"⍪": [null, "firstAxisCatenate"],
|
46
|
+
"⌽": ["reverse", "rotate"],
|
47
|
+
"⊖": ["axis1Reverse", "axis1Rotate"],
|
48
|
+
"⍉": ["transpose", null],
|
49
|
+
"↑": ["first", "take"],
|
50
|
+
"↓": [null, "drop"],
|
51
|
+
"⊂": ["enclose", "partitionWithAxis"],
|
52
|
+
"⊃": ["diclose", "pick"],
|
53
|
+
"⌷": [null, "index"],
|
54
|
+
"⍋": ["gradeUp", null],
|
55
|
+
"⍒": ["gradeDown", null],
|
56
|
+
"⊤": ["encode", null],
|
57
|
+
"⊥": ["decode", null],
|
58
|
+
"⍕": ["format", "formatByExample"],
|
59
|
+
"⍎": ["execute", null],
|
60
|
+
"⊣": ["stop", "left"],
|
61
|
+
"⊢": ["pass", "right"]
|
62
|
+
};
|
63
|
+
|
64
|
+
var isOperator = /[\.\/⌿⍀¨⍣]/;
|
65
|
+
var isNiladic = /⍬/;
|
66
|
+
var isFunction = /[\+−×÷⌈⌊∣⍳\?⋆⍟○!⌹<≤=>≥≠≡≢∈⍷∪∩∼∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢]/;
|
67
|
+
var isArrow = /←/;
|
68
|
+
var isComment = /[⍝#].*$/;
|
69
|
+
|
70
|
+
var stringEater = function(type) {
|
71
|
+
var prev;
|
72
|
+
prev = false;
|
73
|
+
return function(c) {
|
74
|
+
prev = c;
|
75
|
+
if (c === type) {
|
76
|
+
return prev === "\\";
|
77
|
+
}
|
78
|
+
return true;
|
79
|
+
};
|
80
|
+
};
|
81
|
+
return {
|
82
|
+
startState: function() {
|
83
|
+
return {
|
84
|
+
prev: false,
|
85
|
+
func: false,
|
86
|
+
op: false,
|
87
|
+
string: false,
|
88
|
+
escape: false
|
89
|
+
};
|
90
|
+
},
|
91
|
+
token: function(stream, state) {
|
92
|
+
var ch, funcName, word;
|
93
|
+
if (stream.eatSpace()) {
|
94
|
+
return null;
|
95
|
+
}
|
96
|
+
ch = stream.next();
|
97
|
+
if (ch === '"' || ch === "'") {
|
98
|
+
stream.eatWhile(stringEater(ch));
|
99
|
+
stream.next();
|
100
|
+
state.prev = true;
|
101
|
+
return "string";
|
102
|
+
}
|
103
|
+
if (/[\[{\(]/.test(ch)) {
|
104
|
+
state.prev = false;
|
105
|
+
return null;
|
106
|
+
}
|
107
|
+
if (/[\]}\)]/.test(ch)) {
|
108
|
+
state.prev = true;
|
109
|
+
return null;
|
110
|
+
}
|
111
|
+
if (isNiladic.test(ch)) {
|
112
|
+
state.prev = false;
|
113
|
+
return "niladic";
|
114
|
+
}
|
115
|
+
if (/[¯\d]/.test(ch)) {
|
116
|
+
if (state.func) {
|
117
|
+
state.func = false;
|
118
|
+
state.prev = false;
|
119
|
+
} else {
|
120
|
+
state.prev = true;
|
121
|
+
}
|
122
|
+
stream.eatWhile(/[\w\.]/);
|
123
|
+
return "number";
|
124
|
+
}
|
125
|
+
if (isOperator.test(ch)) {
|
126
|
+
return "operator apl-" + builtInOps[ch];
|
127
|
+
}
|
128
|
+
if (isArrow.test(ch)) {
|
129
|
+
return "apl-arrow";
|
130
|
+
}
|
131
|
+
if (isFunction.test(ch)) {
|
132
|
+
funcName = "apl-";
|
133
|
+
if (builtInFuncs[ch] != null) {
|
134
|
+
if (state.prev) {
|
135
|
+
funcName += builtInFuncs[ch][1];
|
136
|
+
} else {
|
137
|
+
funcName += builtInFuncs[ch][0];
|
138
|
+
}
|
139
|
+
}
|
140
|
+
state.func = true;
|
141
|
+
state.prev = false;
|
142
|
+
return "function " + funcName;
|
143
|
+
}
|
144
|
+
if (isComment.test(ch)) {
|
145
|
+
stream.skipToEnd();
|
146
|
+
return "comment";
|
147
|
+
}
|
148
|
+
if (ch === "∘" && stream.peek() === ".") {
|
149
|
+
stream.next();
|
150
|
+
return "function jot-dot";
|
151
|
+
}
|
152
|
+
stream.eatWhile(/[\w\$_]/);
|
153
|
+
word = stream.current();
|
154
|
+
state.prev = true;
|
155
|
+
return "keyword";
|
156
|
+
}
|
157
|
+
};
|
158
|
+
});
|
159
|
+
|
160
|
+
CodeMirror.defineMIME("text/apl", "apl");
|
@@ -0,0 +1,183 @@
|
|
1
|
+
/*
|
2
|
+
* =====================================================================================
|
3
|
+
*
|
4
|
+
* Filename: mode/asterisk/asterisk.js
|
5
|
+
*
|
6
|
+
* Description: CodeMirror mode for Asterisk dialplan
|
7
|
+
*
|
8
|
+
* Created: 05/17/2012 09:20:25 PM
|
9
|
+
* Revision: none
|
10
|
+
*
|
11
|
+
* Author: Stas Kobzar (stas@modulis.ca),
|
12
|
+
* Company: Modulis.ca Inc.
|
13
|
+
*
|
14
|
+
* =====================================================================================
|
15
|
+
*/
|
16
|
+
|
17
|
+
CodeMirror.defineMode("asterisk", function() {
|
18
|
+
var atoms = ["exten", "same", "include","ignorepat","switch"],
|
19
|
+
dpcmd = ["#include","#exec"],
|
20
|
+
apps = [
|
21
|
+
"addqueuemember","adsiprog","aelsub","agentlogin","agentmonitoroutgoing","agi",
|
22
|
+
"alarmreceiver","amd","answer","authenticate","background","backgrounddetect",
|
23
|
+
"bridge","busy","callcompletioncancel","callcompletionrequest","celgenuserevent",
|
24
|
+
"changemonitor","chanisavail","channelredirect","chanspy","clearhash","confbridge",
|
25
|
+
"congestion","continuewhile","controlplayback","dahdiacceptr2call","dahdibarge",
|
26
|
+
"dahdiras","dahdiscan","dahdisendcallreroutingfacility","dahdisendkeypadfacility",
|
27
|
+
"datetime","dbdel","dbdeltree","deadagi","dial","dictate","directory","disa",
|
28
|
+
"dumpchan","eagi","echo","endwhile","exec","execif","execiftime","exitwhile","extenspy",
|
29
|
+
"externalivr","festival","flash","followme","forkcdr","getcpeid","gosub","gosubif",
|
30
|
+
"goto","gotoif","gotoiftime","hangup","iax2provision","ices","importvar","incomplete",
|
31
|
+
"ivrdemo","jabberjoin","jabberleave","jabbersend","jabbersendgroup","jabberstatus",
|
32
|
+
"jack","log","macro","macroexclusive","macroexit","macroif","mailboxexists","meetme",
|
33
|
+
"meetmeadmin","meetmechanneladmin","meetmecount","milliwatt","minivmaccmess","minivmdelete",
|
34
|
+
"minivmgreet","minivmmwi","minivmnotify","minivmrecord","mixmonitor","monitor","morsecode",
|
35
|
+
"mp3player","mset","musiconhold","nbscat","nocdr","noop","odbc","odbc","odbcfinish",
|
36
|
+
"originate","ospauth","ospfinish","osplookup","ospnext","page","park","parkandannounce",
|
37
|
+
"parkedcall","pausemonitor","pausequeuemember","pickup","pickupchan","playback","playtones",
|
38
|
+
"privacymanager","proceeding","progress","queue","queuelog","raiseexception","read","readexten",
|
39
|
+
"readfile","receivefax","receivefax","receivefax","record","removequeuemember",
|
40
|
+
"resetcdr","retrydial","return","ringing","sayalpha","saycountedadj","saycountednoun",
|
41
|
+
"saycountpl","saydigits","saynumber","sayphonetic","sayunixtime","senddtmf","sendfax",
|
42
|
+
"sendfax","sendfax","sendimage","sendtext","sendurl","set","setamaflags",
|
43
|
+
"setcallerpres","setmusiconhold","sipaddheader","sipdtmfmode","sipremoveheader","skel",
|
44
|
+
"slastation","slatrunk","sms","softhangup","speechactivategrammar","speechbackground",
|
45
|
+
"speechcreate","speechdeactivategrammar","speechdestroy","speechloadgrammar","speechprocessingsound",
|
46
|
+
"speechstart","speechunloadgrammar","stackpop","startmusiconhold","stopmixmonitor","stopmonitor",
|
47
|
+
"stopmusiconhold","stopplaytones","system","testclient","testserver","transfer","tryexec",
|
48
|
+
"trysystem","unpausemonitor","unpausequeuemember","userevent","verbose","vmauthenticate",
|
49
|
+
"vmsayname","voicemail","voicemailmain","wait","waitexten","waitfornoise","waitforring",
|
50
|
+
"waitforsilence","waitmusiconhold","waituntil","while","zapateller"
|
51
|
+
];
|
52
|
+
|
53
|
+
function basicToken(stream,state){
|
54
|
+
var cur = '';
|
55
|
+
var ch = '';
|
56
|
+
ch = stream.next();
|
57
|
+
// comment
|
58
|
+
if(ch == ";") {
|
59
|
+
stream.skipToEnd();
|
60
|
+
return "comment";
|
61
|
+
}
|
62
|
+
// context
|
63
|
+
if(ch == '[') {
|
64
|
+
stream.skipTo(']');
|
65
|
+
stream.eat(']');
|
66
|
+
return "header";
|
67
|
+
}
|
68
|
+
// string
|
69
|
+
if(ch == '"') {
|
70
|
+
stream.skipTo('"');
|
71
|
+
return "string";
|
72
|
+
}
|
73
|
+
if(ch == "'") {
|
74
|
+
stream.skipTo("'");
|
75
|
+
return "string-2";
|
76
|
+
}
|
77
|
+
// dialplan commands
|
78
|
+
if(ch == '#') {
|
79
|
+
stream.eatWhile(/\w/);
|
80
|
+
cur = stream.current();
|
81
|
+
if(dpcmd.indexOf(cur) !== -1) {
|
82
|
+
stream.skipToEnd();
|
83
|
+
return "strong";
|
84
|
+
}
|
85
|
+
}
|
86
|
+
// application args
|
87
|
+
if(ch == '$'){
|
88
|
+
var ch1 = stream.peek();
|
89
|
+
if(ch1 == '{'){
|
90
|
+
stream.skipTo('}');
|
91
|
+
stream.eat('}');
|
92
|
+
return "variable-3";
|
93
|
+
}
|
94
|
+
}
|
95
|
+
// extension
|
96
|
+
stream.eatWhile(/\w/);
|
97
|
+
cur = stream.current();
|
98
|
+
if(atoms.indexOf(cur) !== -1) {
|
99
|
+
state.extenStart = true;
|
100
|
+
switch(cur) {
|
101
|
+
case 'same': state.extenSame = true; break;
|
102
|
+
case 'include':
|
103
|
+
case 'switch':
|
104
|
+
case 'ignorepat':
|
105
|
+
state.extenInclude = true;break;
|
106
|
+
default:break;
|
107
|
+
}
|
108
|
+
return "atom";
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
return {
|
113
|
+
startState: function() {
|
114
|
+
return {
|
115
|
+
extenStart: false,
|
116
|
+
extenSame: false,
|
117
|
+
extenInclude: false,
|
118
|
+
extenExten: false,
|
119
|
+
extenPriority: false,
|
120
|
+
extenApplication: false
|
121
|
+
};
|
122
|
+
},
|
123
|
+
token: function(stream, state) {
|
124
|
+
|
125
|
+
var cur = '';
|
126
|
+
var ch = '';
|
127
|
+
if(stream.eatSpace()) return null;
|
128
|
+
// extension started
|
129
|
+
if(state.extenStart){
|
130
|
+
stream.eatWhile(/[^\s]/);
|
131
|
+
cur = stream.current();
|
132
|
+
if(/^=>?$/.test(cur)){
|
133
|
+
state.extenExten = true;
|
134
|
+
state.extenStart = false;
|
135
|
+
return "strong";
|
136
|
+
} else {
|
137
|
+
state.extenStart = false;
|
138
|
+
stream.skipToEnd();
|
139
|
+
return "error";
|
140
|
+
}
|
141
|
+
} else if(state.extenExten) {
|
142
|
+
// set exten and priority
|
143
|
+
state.extenExten = false;
|
144
|
+
state.extenPriority = true;
|
145
|
+
stream.eatWhile(/[^,]/);
|
146
|
+
if(state.extenInclude) {
|
147
|
+
stream.skipToEnd();
|
148
|
+
state.extenPriority = false;
|
149
|
+
state.extenInclude = false;
|
150
|
+
}
|
151
|
+
if(state.extenSame) {
|
152
|
+
state.extenPriority = false;
|
153
|
+
state.extenSame = false;
|
154
|
+
state.extenApplication = true;
|
155
|
+
}
|
156
|
+
return "tag";
|
157
|
+
} else if(state.extenPriority) {
|
158
|
+
state.extenPriority = false;
|
159
|
+
state.extenApplication = true;
|
160
|
+
ch = stream.next(); // get comma
|
161
|
+
if(state.extenSame) return null;
|
162
|
+
stream.eatWhile(/[^,]/);
|
163
|
+
return "number";
|
164
|
+
} else if(state.extenApplication) {
|
165
|
+
stream.eatWhile(/,/);
|
166
|
+
cur = stream.current();
|
167
|
+
if(cur === ',') return null;
|
168
|
+
stream.eatWhile(/\w/);
|
169
|
+
cur = stream.current().toLowerCase();
|
170
|
+
state.extenApplication = false;
|
171
|
+
if(apps.indexOf(cur) !== -1){
|
172
|
+
return "def strong";
|
173
|
+
}
|
174
|
+
} else{
|
175
|
+
return basicToken(stream,state);
|
176
|
+
}
|
177
|
+
|
178
|
+
return null;
|
179
|
+
}
|
180
|
+
};
|
181
|
+
});
|
182
|
+
|
183
|
+
CodeMirror.defineMIME("text/x-asterisk", "asterisk");
|
@@ -1,6 +1,7 @@
|
|
1
1
|
CodeMirror.defineMode("clike", function(config, parserConfig) {
|
2
2
|
var indentUnit = config.indentUnit,
|
3
3
|
statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
|
4
|
+
dontAlignCalls = parserConfig.dontAlignCalls,
|
4
5
|
keywords = parserConfig.keywords || {},
|
5
6
|
builtin = parserConfig.builtin || {},
|
6
7
|
blockKeywords = parserConfig.blockKeywords || {},
|
@@ -149,6 +150,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|
149
150
|
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
|
150
151
|
var closing = firstChar == ctx.type;
|
151
152
|
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
|
153
|
+
else if (dontAlignCalls && ctx.type == ")" && !closing) return ctx.indented + statementIndentUnit;
|
152
154
|
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
153
155
|
else return ctx.indented + (closing ? 0 : indentUnit);
|
154
156
|
},
|
@@ -142,7 +142,7 @@ CodeMirror.defineMode("clojure", function () {
|
|
142
142
|
returnType = COMMENT;
|
143
143
|
} else if (isNumber(ch,stream)){
|
144
144
|
returnType = NUMBER;
|
145
|
-
} else if (ch == "(" || ch == "[") {
|
145
|
+
} else if (ch == "(" || ch == "[" || ch == "{" ) {
|
146
146
|
var keyWord = '', indentTemp = stream.column(), letter;
|
147
147
|
/**
|
148
148
|
Either
|
@@ -172,9 +172,9 @@ CodeMirror.defineMode("clojure", function () {
|
|
172
172
|
stream.backUp(stream.current().length - 1); // undo all the eating
|
173
173
|
|
174
174
|
returnType = BRACKET;
|
175
|
-
} else if (ch == ")" || ch == "]") {
|
175
|
+
} else if (ch == ")" || ch == "]" || ch == "}") {
|
176
176
|
returnType = BRACKET;
|
177
|
-
if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
|
177
|
+
if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : (ch == "]" ? "[" :"{"))) {
|
178
178
|
popStack(state);
|
179
179
|
}
|
180
180
|
} else if ( ch == ":" ) {
|
@@ -222,14 +222,14 @@ CodeMirror.defineMode("css", function(config) {
|
|
222
222
|
stream.eatWhile(/[\w.%]/);
|
223
223
|
return ret("number", "unit");
|
224
224
|
} else if (stream.match(/^[^-]+-/)) {
|
225
|
-
return ret("meta",
|
225
|
+
return ret("meta", "meta");
|
226
226
|
}
|
227
227
|
}
|
228
228
|
else if (/[,+>*\/]/.test(ch)) {
|
229
229
|
return ret(null, "select-op");
|
230
230
|
}
|
231
231
|
else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
|
232
|
-
return ret("qualifier",
|
232
|
+
return ret("qualifier", "qualifier");
|
233
233
|
}
|
234
234
|
else if (ch == ":") {
|
235
235
|
return ret("operator", ch);
|
@@ -0,0 +1,205 @@
|
|
1
|
+
CodeMirror.defineMode("d", function(config, parserConfig) {
|
2
|
+
var indentUnit = config.indentUnit,
|
3
|
+
statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
|
4
|
+
keywords = parserConfig.keywords || {},
|
5
|
+
builtin = parserConfig.builtin || {},
|
6
|
+
blockKeywords = parserConfig.blockKeywords || {},
|
7
|
+
atoms = parserConfig.atoms || {},
|
8
|
+
hooks = parserConfig.hooks || {},
|
9
|
+
multiLineStrings = parserConfig.multiLineStrings;
|
10
|
+
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
|
11
|
+
|
12
|
+
var curPunc;
|
13
|
+
|
14
|
+
function tokenBase(stream, state) {
|
15
|
+
var ch = stream.next();
|
16
|
+
if (hooks[ch]) {
|
17
|
+
var result = hooks[ch](stream, state);
|
18
|
+
if (result !== false) return result;
|
19
|
+
}
|
20
|
+
if (ch == '"' || ch == "'" || ch == "`") {
|
21
|
+
state.tokenize = tokenString(ch);
|
22
|
+
return state.tokenize(stream, state);
|
23
|
+
}
|
24
|
+
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
25
|
+
curPunc = ch;
|
26
|
+
return null;
|
27
|
+
}
|
28
|
+
if (/\d/.test(ch)) {
|
29
|
+
stream.eatWhile(/[\w\.]/);
|
30
|
+
return "number";
|
31
|
+
}
|
32
|
+
if (ch == "/") {
|
33
|
+
if (stream.eat("+")) {
|
34
|
+
state.tokenize = tokenComment;
|
35
|
+
return tokenNestedComment(stream, state);
|
36
|
+
}
|
37
|
+
if (stream.eat("*")) {
|
38
|
+
state.tokenize = tokenComment;
|
39
|
+
return tokenComment(stream, state);
|
40
|
+
}
|
41
|
+
if (stream.eat("/")) {
|
42
|
+
stream.skipToEnd();
|
43
|
+
return "comment";
|
44
|
+
}
|
45
|
+
}
|
46
|
+
if (isOperatorChar.test(ch)) {
|
47
|
+
stream.eatWhile(isOperatorChar);
|
48
|
+
return "operator";
|
49
|
+
}
|
50
|
+
stream.eatWhile(/[\w\$_]/);
|
51
|
+
var cur = stream.current();
|
52
|
+
if (keywords.propertyIsEnumerable(cur)) {
|
53
|
+
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
54
|
+
return "keyword";
|
55
|
+
}
|
56
|
+
if (builtin.propertyIsEnumerable(cur)) {
|
57
|
+
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
58
|
+
return "builtin";
|
59
|
+
}
|
60
|
+
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
61
|
+
return "variable";
|
62
|
+
}
|
63
|
+
|
64
|
+
function tokenString(quote) {
|
65
|
+
return function(stream, state) {
|
66
|
+
var escaped = false, next, end = false;
|
67
|
+
while ((next = stream.next()) != null) {
|
68
|
+
if (next == quote && !escaped) {end = true; break;}
|
69
|
+
escaped = !escaped && next == "\\";
|
70
|
+
}
|
71
|
+
if (end || !(escaped || multiLineStrings))
|
72
|
+
state.tokenize = null;
|
73
|
+
return "string";
|
74
|
+
};
|
75
|
+
}
|
76
|
+
|
77
|
+
function tokenComment(stream, state) {
|
78
|
+
var maybeEnd = false, ch;
|
79
|
+
while (ch = stream.next()) {
|
80
|
+
if (ch == "/" && maybeEnd) {
|
81
|
+
state.tokenize = null;
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
maybeEnd = (ch == "*");
|
85
|
+
}
|
86
|
+
return "comment";
|
87
|
+
}
|
88
|
+
|
89
|
+
function tokenNestedComment(stream, state) {
|
90
|
+
var maybeEnd = false, ch;
|
91
|
+
while (ch = stream.next()) {
|
92
|
+
if (ch == "/" && maybeEnd) {
|
93
|
+
state.tokenize = null;
|
94
|
+
break;
|
95
|
+
}
|
96
|
+
maybeEnd = (ch == "+");
|
97
|
+
}
|
98
|
+
return "comment";
|
99
|
+
}
|
100
|
+
|
101
|
+
function Context(indented, column, type, align, prev) {
|
102
|
+
this.indented = indented;
|
103
|
+
this.column = column;
|
104
|
+
this.type = type;
|
105
|
+
this.align = align;
|
106
|
+
this.prev = prev;
|
107
|
+
}
|
108
|
+
function pushContext(state, col, type) {
|
109
|
+
var indent = state.indented;
|
110
|
+
if (state.context && state.context.type == "statement")
|
111
|
+
indent = state.context.indented;
|
112
|
+
return state.context = new Context(indent, col, type, null, state.context);
|
113
|
+
}
|
114
|
+
function popContext(state) {
|
115
|
+
var t = state.context.type;
|
116
|
+
if (t == ")" || t == "]" || t == "}")
|
117
|
+
state.indented = state.context.indented;
|
118
|
+
return state.context = state.context.prev;
|
119
|
+
}
|
120
|
+
|
121
|
+
// Interface
|
122
|
+
|
123
|
+
return {
|
124
|
+
startState: function(basecolumn) {
|
125
|
+
return {
|
126
|
+
tokenize: null,
|
127
|
+
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
128
|
+
indented: 0,
|
129
|
+
startOfLine: true
|
130
|
+
};
|
131
|
+
},
|
132
|
+
|
133
|
+
token: function(stream, state) {
|
134
|
+
var ctx = state.context;
|
135
|
+
if (stream.sol()) {
|
136
|
+
if (ctx.align == null) ctx.align = false;
|
137
|
+
state.indented = stream.indentation();
|
138
|
+
state.startOfLine = true;
|
139
|
+
}
|
140
|
+
if (stream.eatSpace()) return null;
|
141
|
+
curPunc = null;
|
142
|
+
var style = (state.tokenize || tokenBase)(stream, state);
|
143
|
+
if (style == "comment" || style == "meta") return style;
|
144
|
+
if (ctx.align == null) ctx.align = true;
|
145
|
+
|
146
|
+
if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
|
147
|
+
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
148
|
+
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
149
|
+
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
150
|
+
else if (curPunc == "}") {
|
151
|
+
while (ctx.type == "statement") ctx = popContext(state);
|
152
|
+
if (ctx.type == "}") ctx = popContext(state);
|
153
|
+
while (ctx.type == "statement") ctx = popContext(state);
|
154
|
+
}
|
155
|
+
else if (curPunc == ctx.type) popContext(state);
|
156
|
+
else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))
|
157
|
+
pushContext(state, stream.column(), "statement");
|
158
|
+
state.startOfLine = false;
|
159
|
+
return style;
|
160
|
+
},
|
161
|
+
|
162
|
+
indent: function(state, textAfter) {
|
163
|
+
if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
|
164
|
+
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
|
165
|
+
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
|
166
|
+
var closing = firstChar == ctx.type;
|
167
|
+
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
|
168
|
+
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
169
|
+
else return ctx.indented + (closing ? 0 : indentUnit);
|
170
|
+
},
|
171
|
+
|
172
|
+
electricChars: "{}"
|
173
|
+
};
|
174
|
+
});
|
175
|
+
|
176
|
+
(function() {
|
177
|
+
function words(str) {
|
178
|
+
var obj = {}, words = str.split(" ");
|
179
|
+
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
180
|
+
return obj;
|
181
|
+
}
|
182
|
+
|
183
|
+
var blockKeywords = "body catch class do else enum for foreach foreach_reverse if in interface mixin " +
|
184
|
+
"out scope struct switch try union unittest version while with";
|
185
|
+
|
186
|
+
CodeMirror.defineMIME("text/x-d", {
|
187
|
+
name: "d",
|
188
|
+
keywords: words("abstract alias align asm assert auto break case cast cdouble cent cfloat const continue " +
|
189
|
+
"debug default delegate delete deprecated export extern final finally function goto immutable " +
|
190
|
+
"import inout invariant is lazy macro module new nothrow override package pragma private " +
|
191
|
+
"protected public pure ref return shared short static super synchronized template this " +
|
192
|
+
"throw typedef typeid typeof volatile __FILE__ __LINE__ __gshared __traits __vector __parameters " +
|
193
|
+
blockKeywords),
|
194
|
+
blockKeywords: words(blockKeywords),
|
195
|
+
builtin: words("bool byte char creal dchar double float idouble ifloat int ireal long real short ubyte " +
|
196
|
+
"ucent uint ulong ushort wchar wstring void size_t sizediff_t"),
|
197
|
+
atoms: words("exit failure success true false null"),
|
198
|
+
hooks: {
|
199
|
+
"@": function(stream, _state) {
|
200
|
+
stream.eatWhile(/[\w\$_]/);
|
201
|
+
return "meta";
|
202
|
+
}
|
203
|
+
}
|
204
|
+
});
|
205
|
+
}());
|