diff options
Diffstat (limited to 'imports/codemirror/mode')
79 files changed, 11414 insertions, 0 deletions
diff --git a/imports/codemirror/mode/clike/clike.js b/imports/codemirror/mode/clike/clike.js new file mode 100755 index 00000000..69877efd --- /dev/null +++ b/imports/codemirror/mode/clike/clike.js | |||
@@ -0,0 +1,249 @@ | |||
1 | CodeMirror.defineMode("clike", function(config, parserConfig) { | ||
2 | var indentUnit = config.indentUnit, | ||
3 | keywords = parserConfig.keywords || {}, | ||
4 | blockKeywords = parserConfig.blockKeywords || {}, | ||
5 | atoms = parserConfig.atoms || {}, | ||
6 | hooks = parserConfig.hooks || {}, | ||
7 | multiLineStrings = parserConfig.multiLineStrings; | ||
8 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; | ||
9 | |||
10 | var curPunc; | ||
11 | |||
12 | function tokenBase(stream, state) { | ||
13 | var ch = stream.next(); | ||
14 | if (hooks[ch]) { | ||
15 | var result = hooks[ch](stream, state); | ||
16 | if (result !== false) return result; | ||
17 | } | ||
18 | if (ch == '"' || ch == "'") { | ||
19 | state.tokenize = tokenString(ch); | ||
20 | return state.tokenize(stream, state); | ||
21 | } | ||
22 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | ||
23 | curPunc = ch; | ||
24 | return null | ||
25 | } | ||
26 | if (/\d/.test(ch)) { | ||
27 | stream.eatWhile(/[\w\.]/); | ||
28 | return "number"; | ||
29 | } | ||
30 | if (ch == "/") { | ||
31 | if (stream.eat("*")) { | ||
32 | state.tokenize = tokenComment; | ||
33 | return tokenComment(stream, state); | ||
34 | } | ||
35 | if (stream.eat("/")) { | ||
36 | stream.skipToEnd(); | ||
37 | return "comment"; | ||
38 | } | ||
39 | } | ||
40 | if (isOperatorChar.test(ch)) { | ||
41 | stream.eatWhile(isOperatorChar); | ||
42 | return "operator"; | ||
43 | } | ||
44 | stream.eatWhile(/[\w\$_]/); | ||
45 | var cur = stream.current(); | ||
46 | if (keywords.propertyIsEnumerable(cur)) { | ||
47 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | ||
48 | return "keyword"; | ||
49 | } | ||
50 | if (atoms.propertyIsEnumerable(cur)) return "atom"; | ||
51 | return "word"; | ||
52 | } | ||
53 | |||
54 | function tokenString(quote) { | ||
55 | return function(stream, state) { | ||
56 | var escaped = false, next, end = false; | ||
57 | while ((next = stream.next()) != null) { | ||
58 | if (next == quote && !escaped) {end = true; break;} | ||
59 | escaped = !escaped && next == "\\"; | ||
60 | } | ||
61 | if (end || !(escaped || multiLineStrings)) | ||
62 | state.tokenize = tokenBase; | ||
63 | return "string"; | ||
64 | }; | ||
65 | } | ||
66 | |||
67 | function tokenComment(stream, state) { | ||
68 | var maybeEnd = false, ch; | ||
69 | while (ch = stream.next()) { | ||
70 | if (ch == "/" && maybeEnd) { | ||
71 | state.tokenize = tokenBase; | ||
72 | break; | ||
73 | } | ||
74 | maybeEnd = (ch == "*"); | ||
75 | } | ||
76 | return "comment"; | ||
77 | } | ||
78 | |||
79 | function Context(indented, column, type, align, prev) { | ||
80 | this.indented = indented; | ||
81 | this.column = column; | ||
82 | this.type = type; | ||
83 | this.align = align; | ||
84 | this.prev = prev; | ||
85 | } | ||
86 | function pushContext(state, col, type) { | ||
87 | return state.context = new Context(state.indented, col, type, null, state.context); | ||
88 | } | ||
89 | function popContext(state) { | ||
90 | var t = state.context.type; | ||
91 | if (t == ")" || t == "]" || t == "}") | ||
92 | state.indented = state.context.indented; | ||
93 | return state.context = state.context.prev; | ||
94 | } | ||
95 | |||
96 | // Interface | ||
97 | |||
98 | return { | ||