AmberRack 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/.gitignore +74 -0
  2. data/.rvmrc +4 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +62 -0
  5. data/README.md +17 -0
  6. data/Rakefile +24 -0
  7. data/amber-rack.gemspec +33 -0
  8. data/app/amber_app.rb +35 -0
  9. data/app/javascripts/Benchfib.deploy.js +159 -0
  10. data/app/javascripts/Benchfib.js +159 -0
  11. data/app/javascripts/Canvas.deploy.js +1464 -0
  12. data/app/javascripts/Canvas.js +1464 -0
  13. data/app/javascripts/Compiler.deploy.js +1587 -0
  14. data/app/javascripts/Compiler.js +1587 -0
  15. data/app/javascripts/Examples.deploy.js +800 -0
  16. data/app/javascripts/Examples.js +800 -0
  17. data/app/javascripts/IDE.deploy.js +3457 -0
  18. data/app/javascripts/IDE.js +3457 -0
  19. data/app/javascripts/IDE.js.bak +3420 -0
  20. data/app/javascripts/JQuery.deploy.js +898 -0
  21. data/app/javascripts/JQuery.js +898 -0
  22. data/app/javascripts/Kernel.deploy.js +6761 -0
  23. data/app/javascripts/Kernel.js +6761 -0
  24. data/app/javascripts/Parser.deploy.js +1655 -0
  25. data/app/javascripts/Parser.js +1655 -0
  26. data/app/javascripts/Raphael-Core.js +0 -0
  27. data/app/javascripts/Raphael-Graph.js +0 -0
  28. data/app/javascripts/SUnit.deploy.js +1059 -0
  29. data/app/javascripts/SUnit.js +1059 -0
  30. data/app/javascripts/application.js +2 -0
  31. data/app/javascripts/boot.js +466 -0
  32. data/app/javascripts/init.js +2 -0
  33. data/app/javascripts/jquery-1.4.4.min.js +167 -0
  34. data/app/javascripts/jquery-ui-1.8.9.custom.min.js +781 -0
  35. data/app/javascripts/jquery.textarea.js +267 -0
  36. data/app/javascripts/jtalk.js +78 -0
  37. data/app/javascripts/lib/CodeMirror/LICENSE +19 -0
  38. data/app/javascripts/lib/CodeMirror/README.md +6 -0
  39. data/app/javascripts/lib/CodeMirror/compress.html +92 -0
  40. data/app/javascripts/lib/CodeMirror/css/baboon.png +0 -0
  41. data/app/javascripts/lib/CodeMirror/css/baboon_vector.svg +153 -0
  42. data/app/javascripts/lib/CodeMirror/css/docs.css +154 -0
  43. data/app/javascripts/lib/CodeMirror/demo/activeline.html +72 -0
  44. data/app/javascripts/lib/CodeMirror/demo/changemode.html +51 -0
  45. data/app/javascripts/lib/CodeMirror/demo/complete.html +79 -0
  46. data/app/javascripts/lib/CodeMirror/demo/complete.js +151 -0
  47. data/app/javascripts/lib/CodeMirror/demo/fullscreen.html +158 -0
  48. data/app/javascripts/lib/CodeMirror/demo/marker.html +53 -0
  49. data/app/javascripts/lib/CodeMirror/demo/mustache.html +57 -0
  50. data/app/javascripts/lib/CodeMirror/demo/preview.html +75 -0
  51. data/app/javascripts/lib/CodeMirror/demo/resize.html +44 -0
  52. data/app/javascripts/lib/CodeMirror/demo/runmode.html +50 -0
  53. data/app/javascripts/lib/CodeMirror/demo/search.html +106 -0
  54. data/app/javascripts/lib/CodeMirror/demo/theme.html +53 -0
  55. data/app/javascripts/lib/CodeMirror/index.html +239 -0
  56. data/app/javascripts/lib/CodeMirror/internals.html +389 -0
  57. data/app/javascripts/lib/CodeMirror/lib/codemirror.css +67 -0
  58. data/app/javascripts/lib/CodeMirror/lib/codemirror.js +2144 -0
  59. data/app/javascripts/lib/CodeMirror/lib/overlay.js +51 -0
  60. data/app/javascripts/lib/CodeMirror/lib/runmode.js +27 -0
  61. data/app/javascripts/lib/CodeMirror/manual.html +854 -0
  62. data/app/javascripts/lib/CodeMirror/mode/clike/clike.js +247 -0
  63. data/app/javascripts/lib/CodeMirror/mode/clike/index.html +102 -0
  64. data/app/javascripts/lib/CodeMirror/mode/css/css.js +124 -0
  65. data/app/javascripts/lib/CodeMirror/mode/css/index.html +56 -0
  66. data/app/javascripts/lib/CodeMirror/mode/diff/diff.css +3 -0
  67. data/app/javascripts/lib/CodeMirror/mode/diff/diff.js +13 -0
  68. data/app/javascripts/lib/CodeMirror/mode/diff/index.html +99 -0
  69. data/app/javascripts/lib/CodeMirror/mode/haskell/haskell.js +242 -0
  70. data/app/javascripts/lib/CodeMirror/mode/haskell/index.html +60 -0
  71. data/app/javascripts/lib/CodeMirror/mode/htmlmixed/htmlmixed.js +79 -0
  72. data/app/javascripts/lib/CodeMirror/mode/htmlmixed/index.html +52 -0
  73. data/app/javascripts/lib/CodeMirror/mode/javascript/index.html +78 -0
  74. data/app/javascripts/lib/CodeMirror/mode/javascript/javascript.js +348 -0
  75. data/app/javascripts/lib/CodeMirror/mode/lua/index.html +72 -0
  76. data/app/javascripts/lib/CodeMirror/mode/lua/lua.js +138 -0
  77. data/app/javascripts/lib/CodeMirror/mode/php/index.html +49 -0
  78. data/app/javascripts/lib/CodeMirror/mode/php/php.js +110 -0
  79. data/app/javascripts/lib/CodeMirror/mode/plsql/index.html +63 -0
  80. data/app/javascripts/lib/CodeMirror/mode/plsql/plsql.js +217 -0
  81. data/app/javascripts/lib/CodeMirror/mode/python/LICENSE.txt +21 -0
  82. data/app/javascripts/lib/CodeMirror/mode/python/index.html +123 -0
  83. data/app/javascripts/lib/CodeMirror/mode/python/python.js +321 -0
  84. data/app/javascripts/lib/CodeMirror/mode/rst/index.html +526 -0
  85. data/app/javascripts/lib/CodeMirror/mode/rst/rst.css +75 -0
  86. data/app/javascripts/lib/CodeMirror/mode/rst/rst.js +333 -0
  87. data/app/javascripts/lib/CodeMirror/mode/scheme/index.html +65 -0
  88. data/app/javascripts/lib/CodeMirror/mode/scheme/scheme.js +181 -0
  89. data/app/javascripts/lib/CodeMirror/mode/smalltalk/index.html +56 -0
  90. data/app/javascripts/lib/CodeMirror/mode/smalltalk/smalltalk.js +134 -0
  91. data/app/javascripts/lib/CodeMirror/mode/sparql/index.html +41 -0
  92. data/app/javascripts/lib/CodeMirror/mode/sparql/sparql.js +143 -0
  93. data/app/javascripts/lib/CodeMirror/mode/stex/index.html +96 -0
  94. data/app/javascripts/lib/CodeMirror/mode/stex/stex.js +167 -0
  95. data/app/javascripts/lib/CodeMirror/mode/xml/index.html +42 -0
  96. data/app/javascripts/lib/CodeMirror/mode/xml/xml.js +231 -0
  97. data/app/javascripts/lib/CodeMirror/mode/yaml/index.html +68 -0
  98. data/app/javascripts/lib/CodeMirror/mode/yaml/yaml.js +95 -0
  99. data/app/javascripts/lib/CodeMirror/oldrelease.html +178 -0
  100. data/app/javascripts/lib/CodeMirror/test/index.html +29 -0
  101. data/app/javascripts/lib/CodeMirror/test/test.js +249 -0
  102. data/app/javascripts/lib/CodeMirror/theme/default.css +18 -0
  103. data/app/javascripts/lib/CodeMirror/theme/elegant.css +9 -0
  104. data/app/javascripts/lib/CodeMirror/theme/jtalk.css +21 -0
  105. data/app/javascripts/lib/CodeMirror/theme/neat.css +8 -0
  106. data/app/javascripts/lib/CodeMirror/theme/night.css +20 -0
  107. data/app/javascripts/lib/jQuery/jquery-1.4.4.min.js +167 -0
  108. data/app/javascripts/lib/jQuery/jquery-ui-1.8.9.custom.min.js +781 -0
  109. data/app/javascripts/lib/jQuery/jquery.textarea.js +267 -0
  110. data/app/smalltalk/Canvas.st +481 -0
  111. data/app/smalltalk/IDE.st +1752 -0
  112. data/config.ru +2 -0
  113. data/lib/amber-rack.rb +4 -0
  114. data/lib/amber-rack/version.rb +3 -0
  115. data/public/CodeMirror/LICENSE +19 -0
  116. data/public/CodeMirror/README.md +6 -0
  117. data/public/CodeMirror/compress.html +92 -0
  118. data/public/CodeMirror/css/baboon.png +0 -0
  119. data/public/CodeMirror/css/baboon_vector.svg +153 -0
  120. data/public/CodeMirror/css/docs.css +154 -0
  121. data/public/CodeMirror/demo/activeline.html +72 -0
  122. data/public/CodeMirror/demo/changemode.html +51 -0
  123. data/public/CodeMirror/demo/complete.html +79 -0
  124. data/public/CodeMirror/demo/complete.js +151 -0
  125. data/public/CodeMirror/demo/fullscreen.html +158 -0
  126. data/public/CodeMirror/demo/marker.html +53 -0
  127. data/public/CodeMirror/demo/mustache.html +57 -0
  128. data/public/CodeMirror/demo/preview.html +75 -0
  129. data/public/CodeMirror/demo/resize.html +44 -0
  130. data/public/CodeMirror/demo/runmode.html +50 -0
  131. data/public/CodeMirror/demo/search.html +106 -0
  132. data/public/CodeMirror/demo/theme.html +53 -0
  133. data/public/CodeMirror/index.html +239 -0
  134. data/public/CodeMirror/internals.html +389 -0
  135. data/public/CodeMirror/lib/codemirror.css +67 -0
  136. data/public/CodeMirror/lib/codemirror.js +2144 -0
  137. data/public/CodeMirror/lib/overlay.js +51 -0
  138. data/public/CodeMirror/lib/runmode.js +27 -0
  139. data/public/CodeMirror/manual.html +854 -0
  140. data/public/CodeMirror/mode/clike/clike.js +247 -0
  141. data/public/CodeMirror/mode/clike/index.html +102 -0
  142. data/public/CodeMirror/mode/css/css.js +124 -0
  143. data/public/CodeMirror/mode/css/index.html +56 -0
  144. data/public/CodeMirror/mode/diff/diff.css +3 -0
  145. data/public/CodeMirror/mode/diff/diff.js +13 -0
  146. data/public/CodeMirror/mode/diff/index.html +99 -0
  147. data/public/CodeMirror/mode/haskell/haskell.js +242 -0
  148. data/public/CodeMirror/mode/haskell/index.html +60 -0
  149. data/public/CodeMirror/mode/htmlmixed/htmlmixed.js +79 -0
  150. data/public/CodeMirror/mode/htmlmixed/index.html +52 -0
  151. data/public/CodeMirror/mode/javascript/index.html +78 -0
  152. data/public/CodeMirror/mode/javascript/javascript.js +348 -0
  153. data/public/CodeMirror/mode/lua/index.html +72 -0
  154. data/public/CodeMirror/mode/lua/lua.js +138 -0
  155. data/public/CodeMirror/mode/php/index.html +49 -0
  156. data/public/CodeMirror/mode/php/php.js +110 -0
  157. data/public/CodeMirror/mode/plsql/index.html +63 -0
  158. data/public/CodeMirror/mode/plsql/plsql.js +217 -0
  159. data/public/CodeMirror/mode/python/LICENSE.txt +21 -0
  160. data/public/CodeMirror/mode/python/index.html +123 -0
  161. data/public/CodeMirror/mode/python/python.js +321 -0
  162. data/public/CodeMirror/mode/rst/index.html +526 -0
  163. data/public/CodeMirror/mode/rst/rst.css +75 -0
  164. data/public/CodeMirror/mode/rst/rst.js +333 -0
  165. data/public/CodeMirror/mode/scheme/index.html +65 -0
  166. data/public/CodeMirror/mode/scheme/scheme.js +181 -0
  167. data/public/CodeMirror/mode/smalltalk/index.html +56 -0
  168. data/public/CodeMirror/mode/smalltalk/smalltalk.js +134 -0
  169. data/public/CodeMirror/mode/sparql/index.html +41 -0
  170. data/public/CodeMirror/mode/sparql/sparql.js +143 -0
  171. data/public/CodeMirror/mode/stex/index.html +96 -0
  172. data/public/CodeMirror/mode/stex/stex.js +167 -0
  173. data/public/CodeMirror/mode/xml/index.html +42 -0
  174. data/public/CodeMirror/mode/xml/xml.js +231 -0
  175. data/public/CodeMirror/mode/yaml/index.html +68 -0
  176. data/public/CodeMirror/mode/yaml/yaml.js +95 -0
  177. data/public/CodeMirror/oldrelease.html +178 -0
  178. data/public/CodeMirror/test/index.html +29 -0
  179. data/public/CodeMirror/test/test.js +249 -0
  180. data/public/CodeMirror/theme/default.css +18 -0
  181. data/public/CodeMirror/theme/elegant.css +9 -0
  182. data/public/CodeMirror/theme/jtalk.css +21 -0
  183. data/public/CodeMirror/theme/neat.css +8 -0
  184. data/public/CodeMirror/theme/night.css +20 -0
  185. data/public/css/jtalk.css +362 -0
  186. data/public/css/style.css +456 -0
  187. data/public/css/sunit.css +66 -0
  188. data/public/ide/fork_me.png +0 -0
  189. data/public/ide/screen2.png +0 -0
  190. data/public/ide/style.css +456 -0
  191. data/public/ide/syntax.css +61 -0
  192. data/public/ide/text_header.png +0 -0
  193. data/public/ide/title_container1.png +0 -0
  194. data/public/images/background_box.png +0 -0
  195. data/public/images/background_header.png +0 -0
  196. data/public/images/balloon_header.png +0 -0
  197. data/views/index.haml +66 -0
  198. metadata +341 -0
@@ -0,0 +1,56 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: CSS mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="css.js"></script>
8
+ <link rel="stylesheet" href="../../theme/default.css">
9
+ <style>.CodeMirror {background: #f8f8f8;}</style>
10
+ <link rel="stylesheet" href="../../css/docs.css">
11
+ </head>
12
+ <body>
13
+ <h1>CodeMirror 2: CSS mode</h1>
14
+ <form><textarea id="code" name="code">
15
+ /* Some example CSS */
16
+
17
+ @import url("something.css");
18
+
19
+ body {
20
+ margin: 0;
21
+ padding: 3em 6em;
22
+ font-family: tahoma, arial, sans-serif;
23
+ color: #000;
24
+ }
25
+
26
+ #navigation a {
27
+ font-weight: bold;
28
+ text-decoration: none !important;
29
+ }
30
+
31
+ h1 {
32
+ font-size: 2.5em;
33
+ }
34
+
35
+ h2 {
36
+ font-size: 1.7em;
37
+ }
38
+
39
+ h1:before, h2:before {
40
+ content: "::";
41
+ }
42
+
43
+ code {
44
+ font-family: courier, monospace;
45
+ font-size: 80%;
46
+ color: #418A8A;
47
+ }
48
+ </textarea></form>
49
+ <script>
50
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
51
+ </script>
52
+
53
+ <p><strong>MIME types defined:</strong> <code>text/css</code>.</p>
54
+
55
+ </body>
56
+ </html>
@@ -0,0 +1,3 @@
1
+ .cm-s-default span.cm-rangeinfo {color: #a0b;}
2
+ .cm-s-default span.cm-minus {color: #a22;}
3
+ .cm-s-default span.cm-plus {color: #2b2;}
@@ -0,0 +1,13 @@
1
+ CodeMirror.defineMode("diff", function() {
2
+ return {
3
+ token: function(stream) {
4
+ var ch = stream.next();
5
+ stream.skipToEnd();
6
+ if (ch == "+") return "plus";
7
+ if (ch == "-") return "minus";
8
+ if (ch == "@") return "rangeinfo";
9
+ }
10
+ };
11
+ });
12
+
13
+ CodeMirror.defineMIME("text/x-diff", "diff");
@@ -0,0 +1,99 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: Diff mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="diff.js"></script>
8
+ <link rel="stylesheet" href="diff.css">
9
+ <style>.CodeMirror {border-top: 1px solid #ddd; border-bottom: 1px solid #ddd;}</style>
10
+ <link rel="stylesheet" href="../../css/docs.css">
11
+ </head>
12
+ <body>
13
+ <h1>CodeMirror 2: Diff mode</h1>
14
+ <form><textarea id="code" name="code">
15
+ diff --git a/index.html b/index.html
16
+ index c1d9156..7764744 100644
17
+ --- a/index.html
18
+ +++ b/index.html
19
+ @@ -95,7 +95,8 @@ StringStream.prototype = {
20
+ <script>
21
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
22
+ lineNumbers: true,
23
+ - autoMatchBrackets: true
24
+ + autoMatchBrackets: true,
25
+ + onGutterClick: function(x){console.log(x);}
26
+ });
27
+ </script>
28
+ </body>
29
+ diff --git a/lib/codemirror.js b/lib/codemirror.js
30
+ index 04646a9..9a39cc7 100644
31
+ --- a/lib/codemirror.js
32
+ +++ b/lib/codemirror.js
33
+ @@ -399,10 +399,16 @@ var CodeMirror = (function() {
34
+ }
35
+
36
+ function onMouseDown(e) {
37
+ - var start = posFromMouse(e), last = start;
38
+ + var start = posFromMouse(e), last = start, target = e.target();
39
+ if (!start) return;
40
+ setCursor(start.line, start.ch, false);
41
+ if (e.button() != 1) return;
42
+ + if (target.parentNode == gutter) {
43
+ + if (options.onGutterClick)
44
+ + options.onGutterClick(indexOf(gutter.childNodes, target) + showingFrom);
45
+ + return;
46
+ + }
47
+ +
48
+ if (!focused) onFocus();
49
+
50
+ e.stop();
51
+ @@ -808,7 +814,7 @@ var CodeMirror = (function() {
52
+ for (var i = showingFrom; i < showingTo; ++i) {
53
+ var marker = lines[i].gutterMarker;
54
+ if (marker) html.push('<div class="' + marker.style + '">' + htmlEscape(marker.text) + '</div>');
55
+ - else html.push("<div>" + (options.lineNumbers ? i + 1 : "\u00a0") + "</div>");
56
+ + else html.push("<div>" + (options.lineNumbers ? i + options.firstLineNumber : "\u00a0") + "</div>");
57
+ }
58
+ gutter.style.display = "none"; // TODO test whether this actually helps
59
+ gutter.innerHTML = html.join("");
60
+ @@ -1371,10 +1377,8 @@ var CodeMirror = (function() {
61
+ if (option == "parser") setParser(value);
62
+ else if (option === "lineNumbers") setLineNumbers(value);
63
+ else if (option === "gutter") setGutter(value);
64
+ - else if (option === "readOnly") options.readOnly = value;
65
+ - else if (option === "indentUnit") {options.indentUnit = indentUnit = value; setParser(options.parser);}
66
+ - else if (/^(?:enterMode|tabMode|indentWithTabs|readOnly|autoMatchBrackets|undoDepth)$/.test(option)) options[option] = value;
67
+ - else throw new Error("Can't set option " + option);
68
+ + else if (option === "indentUnit") {options.indentUnit = value; setParser(options.parser);}
69
+ + else options[option] = value;
70
+ },
71
+ cursorCoords: cursorCoords,
72
+ undo: operation(undo),
73
+ @@ -1402,7 +1406,8 @@ var CodeMirror = (function() {
74
+ replaceRange: operation(replaceRange),
75
+
76
+ operation: function(f){return operation(f)();},
77
+ - refresh: function(){updateDisplay([{from: 0, to: lines.length}]);}
78
+ + refresh: function(){updateDisplay([{from: 0, to: lines.length}]);},
79
+ + getInputField: function(){return input;}
80
+ };
81
+ return instance;
82
+ }
83
+ @@ -1420,6 +1425,7 @@ var CodeMirror = (function() {
84
+ readOnly: false,
85
+ onChange: null,
86
+ onCursorActivity: null,
87
+ + onGutterClick: null,
88
+ autoMatchBrackets: false,
89
+ workTime: 200,
90
+ workDelay: 300,
91
+ </textarea></form>
92
+ <script>
93
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
94
+ </script>
95
+
96
+ <p><strong>MIME types defined:</strong> <code>text/x-diff</code>.</p>
97
+
98
+ </body>
99
+ </html>
@@ -0,0 +1,242 @@
1
+ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
2
+
3
+ function switchState(source, setState, f) {
4
+ setState(f);
5
+ return f(source, setState);
6
+ }
7
+
8
+ // These should all be Unicode extended, as per the Haskell 2010 report
9
+ var smallRE = /[a-z_]/;
10
+ var largeRE = /[A-Z]/;
11
+ var digitRE = /[0-9]/;
12
+ var hexitRE = /[0-9A-Fa-f]/;
13
+ var octitRE = /[0-7]/;
14
+ var idRE = /[a-z_A-Z0-9']/;
15
+ var symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/;
16
+ var specialRE = /[(),;[\]`{}]/;
17
+ var whiteCharRE = /[ \t\v\f]/; // newlines are handled in tokenizer
18
+
19
+ function normal(source, setState) {
20
+ if (source.eatWhile(whiteCharRE)) {
21
+ return null;
22
+ }
23
+
24
+ var ch = source.next();
25
+ if (specialRE.test(ch)) {
26
+ if (ch == '{' && source.eat('-')) {
27
+ var t = "comment";
28
+ if (source.eat('#')) {
29
+ t = "meta";
30
+ }
31
+ return switchState(source, setState, ncomment(t, 1));
32
+ }
33
+ return null;
34
+ }
35
+
36
+ if (ch == '\'') {
37
+ if (source.eat('\\')) {
38
+ source.next(); // should handle other escapes here
39
+ }
40
+ else {
41
+ source.next();
42
+ }
43
+ if (source.eat('\'')) {
44
+ return "string";
45
+ }
46
+ return "error";
47
+ }
48
+
49
+ if (ch == '"') {
50
+ return switchState(source, setState, stringLiteral);
51
+ }
52
+
53
+ if (largeRE.test(ch)) {
54
+ source.eatWhile(idRE);
55
+ if (source.eat('.')) {
56
+ return "qualifier";
57
+ }
58
+ return "variable-2";
59
+ }
60
+
61
+ if (smallRE.test(ch)) {
62
+ source.eatWhile(idRE);
63
+ return "variable";
64
+ }
65
+
66
+ if (digitRE.test(ch)) {
67
+ if (ch == '0') {
68
+ if (source.eat(/[xX]/)) {
69
+ source.eatWhile(hexitRE); // should require at least 1
70
+ return "integer";
71
+ }
72
+ if (source.eat(/[oO]/)) {
73
+ source.eatWhile(octitRE); // should require at least 1
74
+ return "number";
75
+ }
76
+ }
77
+ source.eatWhile(digitRE);
78
+ var t = "number";
79
+ if (source.eat('.')) {
80
+ t = "number";
81
+ source.eatWhile(digitRE); // should require at least 1
82
+ }
83
+ if (source.eat(/[eE]/)) {
84
+ t = "number";
85
+ source.eat(/[-+]/);
86
+ source.eatWhile(digitRE); // should require at least 1
87
+ }
88
+ return t;
89
+ }
90
+
91
+ if (symbolRE.test(ch)) {
92
+ if (ch == '-' && source.eat(/-/)) {
93
+ source.eatWhile(/-/);
94
+ if (!source.eat(symbolRE)) {
95
+ source.skipToEnd();
96
+ return "comment";
97
+ }
98
+ }
99
+ var t = "variable";
100
+ if (ch == ':') {
101
+ t = "variable-2";
102
+ }
103
+ source.eatWhile(symbolRE);
104
+ return t;
105
+ }
106
+
107
+ return "error";
108
+ }
109
+
110
+ function ncomment(type, nest) {
111
+ if (nest == 0) {
112
+ return normal;
113
+ }
114
+ return function(source, setState) {
115
+ var currNest = nest;
116
+ while (!source.eol()) {
117
+ var ch = source.next();
118
+ if (ch == '{' && source.eat('-')) {
119
+ ++currNest;
120
+ }
121
+ else if (ch == '-' && source.eat('}')) {
122
+ --currNest;
123
+ if (currNest == 0) {
124
+ setState(normal);
125
+ return type;
126
+ }
127
+ }
128
+ }
129
+ setState(ncomment(type, currNest));
130
+ return type;
131
+ }
132
+ }
133
+
134
+ function stringLiteral(source, setState) {
135
+ while (!source.eol()) {
136
+ var ch = source.next();
137
+ if (ch == '"') {
138
+ setState(normal);
139
+ return "string";
140
+ }
141
+ if (ch == '\\') {
142
+ if (source.eol() || source.eat(whiteCharRE)) {
143
+ setState(stringGap);
144
+ return "string";
145
+ }
146
+ if (source.eat('&')) {
147
+ }
148
+ else {
149
+ source.next(); // should handle other escapes here
150
+ }
151
+ }
152
+ }
153
+ setState(normal);
154
+ return "error";
155
+ }
156
+
157
+ function stringGap(source, setState) {
158
+ if (source.eat('\\')) {
159
+ return switchState(source, setState, stringLiteral);
160
+ }
161
+ source.next();
162
+ setState(normal);
163
+ return "error";
164
+ }
165
+
166
+
167
+ var wellKnownWords = (function() {
168
+ var wkw = {};
169
+ function setType(t) {
170
+ return function () {
171
+ for (var i = 0; i < arguments.length; i++)
172
+ wkw[arguments[i]] = t;
173
+ }
174
+ }
175
+
176
+ setType("keyword")(
177
+ "case", "class", "data", "default", "deriving", "do", "else", "foreign",
178
+ "if", "import", "in", "infix", "infixl", "infixr", "instance", "let",
179
+ "module", "newtype", "of", "then", "type", "where", "_");
180
+
181
+ setType("keyword")(
182
+ "\.\.", ":", "::", "=", "\\", "\"", "<-", "->", "@", "~", "=>");
183
+
184
+ setType("builtin")(
185
+ "!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<=", "=<<",
186
+ "==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "**");
187
+
188
+ setType("builtin")(
189
+ "Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq",
190
+ "False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT",
191
+ "IO", "IOError", "Int", "Integer", "Integral", "Just", "LT", "Left",
192
+ "Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read",
193
+ "ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS",
194
+ "String", "True");
195
+
196
+ setType("builtin")(
197
+ "abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf",
198
+ "asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling",
199
+ "compare", "concat", "concatMap", "const", "cos", "cosh", "curry",
200
+ "cycle", "decodeFloat", "div", "divMod", "drop", "dropWhile", "either",
201
+ "elem", "encodeFloat", "enumFrom", "enumFromThen", "enumFromThenTo",
202
+ "enumFromTo", "error", "even", "exp", "exponent", "fail", "filter",
203
+ "flip", "floatDigits", "floatRadix", "floatRange", "floor", "fmap",
204
+ "foldl", "foldl1", "foldr", "foldr1", "fromEnum", "fromInteger",
205
+ "fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents",
206
+ "getLine", "head", "id", "init", "interact", "ioError", "isDenormalized",
207
+ "isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last",
208
+ "lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map",
209
+ "mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound",
210
+ "minimum", "mod", "negate", "not", "notElem", "null", "odd", "or",
211
+ "otherwise", "pi", "pred", "print", "product", "properFraction",
212
+ "putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile",
213
+ "readIO", "readList", "readLn", "readParen", "reads", "readsPrec",
214
+ "realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse",
215
+ "round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq",
216
+ "sequence", "sequence_", "show", "showChar", "showList", "showParen",
217
+ "showString", "shows", "showsPrec", "significand", "signum", "sin",
218
+ "sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum",
219
+ "tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger",
220
+ "toRational", "truncate", "uncurry", "undefined", "unlines", "until",
221
+ "unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",
222
+ "zip3", "zipWith", "zipWith3");
223
+
224
+ return wkw;
225
+ })();
226
+
227
+
228
+
229
+ return {
230
+ startState: function () { return { f: normal }; },
231
+ copyState: function (s) { return { f: s.f }; },
232
+
233
+ token: function(stream, state) {
234
+ var t = state.f(stream, function(s) { state.f = s; });
235
+ var w = stream.current();
236
+ return (w in wellKnownWords) ? wellKnownWords[w] : t;
237
+ }
238
+ };
239
+
240
+ });
241
+
242
+ CodeMirror.defineMIME("text/x-haskell", "haskell");
@@ -0,0 +1,60 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: Haskell mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="haskell.js"></script>
8
+ <link rel="stylesheet" href="../../theme/elegant.css">
9
+ <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
10
+ <link rel="stylesheet" href="../../css/docs.css">
11
+ </head>
12
+ <body>
13
+ <h1>CodeMirror 2: Haskell mode</h1>
14
+
15
+ <form><textarea id="code" name="code">
16
+ module UniquePerms (
17
+ uniquePerms
18
+ )
19
+ where
20
+
21
+ -- | Find all unique permutations of a list where there might be duplicates.
22
+ uniquePerms :: (Eq a) => [a] -> [[a]]
23
+ uniquePerms = permBag . makeBag
24
+
25
+ -- | An unordered collection where duplicate values are allowed,
26
+ -- but represented with a single value and a count.
27
+ type Bag a = [(a, Int)]
28
+
29
+ makeBag :: (Eq a) => [a] -> Bag a
30
+ makeBag [] = []
31
+ makeBag (a:as) = mix a $ makeBag as
32
+ where
33
+ mix a [] = [(a,1)]
34
+ mix a (bn@(b,n):bs) | a == b = (b,n+1):bs
35
+ | otherwise = bn : mix a bs
36
+
37
+ permBag :: Bag a -> [[a]]
38
+ permBag [] = [[]]
39
+ permBag bs = concatMap (\(f,cs) -> map (f:) $ permBag cs) . oneOfEach $ bs
40
+ where
41
+ oneOfEach [] = []
42
+ oneOfEach (an@(a,n):bs) =
43
+ let bs' = if n == 1 then bs else (a,n-1):bs
44
+ in (a,bs') : mapSnd (an:) (oneOfEach bs)
45
+
46
+ apSnd f (a,b) = (a, f b)
47
+ mapSnd = map . apSnd
48
+ </textarea></form>
49
+
50
+ <script>
51
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
52
+ lineNumbers: true,
53
+ matchBrackets: true,
54
+ theme: "elegant"
55
+ });
56
+ </script>
57
+
58
+ <p><strong>MIME types defined:</strong> <code>text/x-haskell</code>.</p>
59
+ </body>
60
+ </html>