diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/codemirror/mode/smalltalk | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-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')
-rw-r--r-- | js/codemirror/mode/smalltalk/index.html | 56 | ||||
-rw-r--r-- | js/codemirror/mode/smalltalk/smalltalk.js | 122 |
2 files changed, 178 insertions, 0 deletions
diff --git a/js/codemirror/mode/smalltalk/index.html b/js/codemirror/mode/smalltalk/index.html new file mode 100644 index 00000000..67cb22b4 --- /dev/null +++ b/js/codemirror/mode/smalltalk/index.html | |||
@@ -0,0 +1,56 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror 2: Smalltalk mode</title> | ||
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
6 | <script src="../../lib/codemirror.js"></script> | ||
7 | <script src="smalltalk.js"></script> | ||
8 | <link rel="stylesheet" href="../../theme/default.css"> | ||
9 | <link rel="stylesheet" href="../../css/docs.css"> | ||
10 | <style> | ||
11 | .CodeMirror {border: 2px solid #dee; border-right-width: 10px;} | ||
12 | .CodeMirror-gutter {border: none; background: #dee;} | ||
13 | .CodeMirror-gutter pre {color: white; font-weight: bold;} | ||
14 | </style> | ||
15 | </head> | ||
16 | <body> | ||
17 | <h1>CodeMirror 2: Smalltalk mode</h1> | ||
18 | |||
19 | <form><textarea id="code" name="code"> | ||
20 | " | ||
21 | This is a test of the Smalltalk code | ||
22 | " | ||
23 | Seaside.WAComponent subclass: #MyCounter [ | ||
24 | | count | | ||
25 | MyCounter class >> canBeRoot [ ^true ] | ||
26 | |||
27 | initialize [ | ||
28 | super initialize. | ||
29 | count := 0. | ||
30 | ] | ||
31 | states [ ^{ self } ] | ||
32 | renderContentOn: html [ | ||
33 | html heading: count. | ||
34 | html anchor callback: [ count := count + 1 ]; with: '++'. | ||
35 | html space. | ||
36 | html anchor callback: [ count := count - 1 ]; with: '--'. | ||
37 | ] | ||
38 | ] | ||
39 | |||
40 | MyCounter registerAsApplication: 'mycounter' | ||
41 | </textarea></form> | ||
42 | |||
43 | <script> | ||
44 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
45 | lineNumbers: true, | ||
46 | matchBrackets: true, | ||
47 | mode: "text/x-stsrc", | ||
48 | indentUnit: 4 | ||
49 | }); | ||
50 | </script> | ||
51 | |||
52 | <p>Simple Smalltalk mode.</p> | ||
53 | |||
54 | <p><strong>MIME types defined:</strong> <code>text/x-stsrc</code>.</p> | ||
55 | </body> | ||
56 | </html> | ||
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 @@ | |||
1 | CodeMirror.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 | |||
122 | CodeMirror.defineMIME("text/x-stsrc", {name: "smalltalk"}); | ||