aboutsummaryrefslogtreecommitdiff
path: root/js/codemirror/mode/smalltalk/smalltalk.js
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/codemirror/mode/smalltalk/smalltalk.js
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/codemirror/mode/smalltalk/smalltalk.js')
-rw-r--r--js/codemirror/mode/smalltalk/smalltalk.js122
1 files changed, 122 insertions, 0 deletions
diff --git a/js/codemirror/mode/smalltalk/smalltalk.js b/js/codemirror/mode/smalltalk/smalltalk.js
new file mode 100644
index 00000000..a5b14e14
--- /dev/null
+++ b/js/codemirror/mode/smalltalk/smalltalk.js
@@ -0,0 +1,122 @@
1CodeMirror.defineMode("smalltalk", function(config, parserConfig) {
2 var keywords = {"true": 1, "false": 1, nil: 1, self: 1, "super": 1, thisContext: 1};
3 var indentUnit = config.indentUnit;
4
5 function chain(stream, state, f) {
6 state.tokenize = f;
7 return f(stream, state);
8 }
9
10 var type;
11 function ret(tp, style) {
12 type = tp;
13 return style;
14 }
15
16 function tokenBase(stream, state) {
17 var ch = stream.next();
18 if (ch == '"')
19 return chain(stream, state, tokenComment(ch));
20 else if (ch == "'")
21 return chain(stream, state, tokenString(ch));
22 else if (ch == "#") {
23 stream.eatWhile(/[\w\$_]/);
24 return ret("string", "string");
25 }
26 else if (/\d/.test(ch)) {
27 stream.eatWhile(/[\w\.]/)
28 return ret("number", "number");
29 }
30 else if (/[\[\]()]/.test(ch)) {
31 return ret(ch, null);
32 }
33 else {
34 stream.eatWhile(/[\w\$_]/);
35 if (keywords && keywords.propertyIsEnumerable(stream.current())) return ret("keyword", "keyword");
36 return ret("word", "variable");
37 }
38 }
39
40 function tokenString(quote) {
41 return function(stream, state) {
42 var escaped = false, next, end = false;
43 while ((next = stream.next()) != null) {
44 if (next == quote && !escaped) {end = true; break;}
45 escaped = !escaped && next == "\\";
46 }
47 if (end || !(escaped))
48 state.tokenize = tokenBase;
49 return ret("string", "string");
50 };
51 }
52
53 function tokenComment(quote) {
54 return function(stream, state) {
55 var next, end = false;
56 while ((next = stream.next()) != null) {
57 if (next == quote) {end = true; break;}
58 }
59 if (end)
60 state.tokenize = tokenBase;
61 return ret("comment", "comment");
62 };
63 }
64
65 function Context(indented, column, type, align, prev) {
66 this.indented = indented;
67 this.column = column;
68 this.type = type;
69 this.align = align;
70 this.prev = prev;
71 }
72
73 function pushContext(state, col, type) {
74 return state.context = new Context(state.indented, col, type, null, state.context);
75 }
76 function popContext(state) {
77 return state.context = state.context.prev;
78 }
79
80 // Interface
81
82 return {
83 startState: function(basecolumn) {
84 return {
85 tokenize: tokenBase,
86 context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
87 indented: 0,
88 startOfLine: true
89 };
90 },
91
92 token: function(stream, state) {
93 var ctx = state.context;
94 if (stream.sol()) {
95 if (ctx.align == null) ctx.align = false;
96 state.indented = stream.indentation();
97 state.startOfLine = true;
98 }
99 if (stream.eatSpace()) return null;
100 var style = state.tokenize(stream, state);
101 if (type == "comment") return style;
102 if (ctx.align == null) ctx.align = true;
103
104 if (type == "[") pushContext(state, stream.column(), "]");
105 else if (type == "(") pushContext(state, stream.column(), ")");
106 else if (type == ctx.type) popContext(state);
107 state.startOfLine = false;
108 return style;
109 },
110
111 indent: function(state, textAfter) {
112 if (state.tokenize != tokenBase) return 0;
113 var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type;
114 if (ctx.align) return ctx.column + (closing ? 0 : 1);
115 else return ctx.indented + (closing ? 0 : indentUnit);
116 },
117
118 electricChars: "]"
119 };
120});
121
122CodeMirror.defineMIME("text/x-stsrc", {name: "smalltalk"});