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,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Timothy Farrell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,123 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: Python mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="python.js"></script>
8
+ <link rel="stylesheet" href="../../theme/default.css">
9
+ <link rel="stylesheet" href="../../css/docs.css">
10
+ <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
11
+ </head>
12
+ <body>
13
+ <h1>CodeMirror 2: Python mode</h1>
14
+
15
+ <div><textarea id="code" name="code">
16
+ # Literals
17
+ 1234
18
+ 0.0e101
19
+ .123
20
+ 0b01010011100
21
+ 0o01234567
22
+ 0x0987654321abcdef
23
+ 7
24
+ 2147483647
25
+ 3L
26
+ 79228162514264337593543950336L
27
+ 0x100000000L
28
+ 79228162514264337593543950336
29
+ 0xdeadbeef
30
+ 3.14j
31
+ 10.j
32
+ 10j
33
+ .001j
34
+ 1e100j
35
+ 3.14e-10j
36
+
37
+
38
+ # String Literals
39
+ 'For\''
40
+ "God\""
41
+ """so loved
42
+ the world"""
43
+ '''that he gave
44
+ his only begotten\' '''
45
+ 'that whosoever believeth \
46
+ in him'
47
+ ''
48
+
49
+ # Identifiers
50
+ __a__
51
+ a.b
52
+ a.b.c
53
+
54
+ # Operators
55
+ + - * / % & | ^ ~ < >
56
+ == != <= >= <> << >> // **
57
+ and or not in is
58
+
59
+ # Delimiters
60
+ () [] {} , : ` = ; @ . # Note that @ and . require the proper context.
61
+ += -= *= /= %= &= |= ^=
62
+ //= >>= <<= **=
63
+
64
+ # Keywords
65
+ as assert break class continue def del elif else except
66
+ finally for from global if import lambda pass raise
67
+ return try while with yield
68
+
69
+ # Python 2 Keywords (otherwise Identifiers)
70
+ exec print
71
+
72
+ # Python 3 Keywords (otherwise Identifiers)
73
+ nonlocal
74
+
75
+ # Types
76
+ bool classmethod complex dict enumerate float frozenset int list object
77
+ property reversed set slice staticmethod str super tuple type
78
+
79
+ # Python 2 Types (otherwise Identifiers)
80
+ basestring buffer file long unicode xrange
81
+
82
+ # Python 3 Types (otherwise Identifiers)
83
+ bytearray bytes filter map memoryview open range zip
84
+
85
+ # Some Example code
86
+ import os
87
+ from package import ParentClass
88
+
89
+ @nonsenseDecorator
90
+ def doesNothing():
91
+ pass
92
+
93
+ class ExampleClass(ParentClass):
94
+ @staticmethod
95
+ def example(inputStr):
96
+ a = list(inputStr)
97
+ a.reverse()
98
+ return ''.join(a)
99
+
100
+ def __init__(self, mixin = 'Hello'):
101
+ self.mixin = mixin
102
+
103
+ </textarea></div>
104
+ <script>
105
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
106
+ mode: {name: "python",
107
+ version: 2,
108
+ singleLineStringErrors: false},
109
+ lineNumbers: true,
110
+ indentUnit: 4,
111
+ tabMode: "shift",
112
+ matchBrackets: true
113
+ });
114
+ </script>
115
+ <h2>Configuration Options:</h2>
116
+ <ul>
117
+ <li>version - 2/3 - The version of Python to recognize. Default is 2.</li>
118
+ <li>singleLineStringErrors - true/false - If you have a single-line string that is not terminated at the end of the line, this will show subsequent lines as errors if true, otherwise it will consider the newline as the end of the string. Default is false.</li>
119
+ </ul>
120
+
121
+ <p><strong>MIME types defined:</strong> <code>text/x-python</code>.</p>
122
+ </body>
123
+ </html>
@@ -0,0 +1,321 @@
1
+ CodeMirror.defineMode("python", function(conf) {
2
+ var ERRORCLASS = 'error';
3
+
4
+ function wordRegexp(words) {
5
+ return new RegExp("^((" + words.join(")|(") + "))\\b");
6
+ }
7
+
8
+ var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]");
9
+ var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
10
+ var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
11
+ var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
12
+ var tripleDelimiters = new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))");
13
+ var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
14
+
15
+ var wordOperators = wordRegexp(['and', 'or', 'not', 'is', 'in']);
16
+ var commonkeywords = ['as', 'assert', 'break', 'class', 'continue',
17
+ 'def', 'del', 'elif', 'else', 'except', 'finally',
18
+ 'for', 'from', 'global', 'if', 'import',
19
+ 'lambda', 'pass', 'raise', 'return',
20
+ 'try', 'while', 'with', 'yield'];
21
+ var commontypes = ['bool', 'classmethod', 'complex', 'dict', 'enumerate',
22
+ 'float', 'frozenset', 'int', 'list', 'object',
23
+ 'property', 'reversed', 'set', 'slice', 'staticmethod',
24
+ 'str', 'super', 'tuple', 'type'];
25
+ var py2 = {'types': ['basestring', 'buffer', 'file', 'long', 'unicode',
26
+ 'xrange'],
27
+ 'keywords': ['exec', 'print']};
28
+ var py3 = {'types': ['bytearray', 'bytes', 'filter', 'map', 'memoryview',
29
+ 'open', 'range', 'zip'],
30
+ 'keywords': ['nonlocal']};
31
+
32
+ if (!!conf.mode.version && parseInt(conf.mode.version, 10) === 3) {
33
+ commonkeywords = commonkeywords.concat(py3.keywords);
34
+ commontypes = commontypes.concat(py3.types);
35
+ var stringPrefixes = new RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))", "i");
36
+ } else {
37
+ commonkeywords = commonkeywords.concat(py2.keywords);
38
+ commontypes = commontypes.concat(py2.types);
39
+ var stringPrefixes = new RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i");
40
+ }
41
+ var keywords = wordRegexp(commonkeywords);
42
+ var types = wordRegexp(commontypes);
43
+
44
+ var indentInfo = null;
45
+
46
+ // tokenizers
47
+ function tokenBase(stream, state) {
48
+ // Handle scope changes
49
+ if (stream.sol()) {
50
+ var scopeOffset = state.scopes[0].offset;
51
+ if (stream.eatSpace()) {
52
+ var lineOffset = stream.indentation();
53
+ if (lineOffset > scopeOffset) {
54
+ indentInfo = 'indent';
55
+ } else if (lineOffset < scopeOffset) {
56
+ indentInfo = 'dedent';
57
+ }
58
+ return null;
59
+ } else {
60
+ if (scopeOffset > 0) {
61
+ dedent(stream, state);
62
+ }
63
+ }
64
+ }
65
+ if (stream.eatSpace()) {
66
+ return null;
67
+ }
68
+
69
+ var ch = stream.peek();
70
+
71
+ // Handle Comments
72
+ if (ch === '#') {
73
+ stream.skipToEnd();
74
+ return 'comment';
75
+ }
76
+
77
+ // Handle Number Literals
78
+ if (stream.match(/^[0-9\.]/, false)) {
79
+ var floatLiteral = false;
80
+ // Floats
81
+ if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
82
+ if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
83
+ if (stream.match(/^\.\d+/)) { floatLiteral = true; }
84
+ if (floatLiteral) {
85
+ // Float literals may be "imaginary"
86
+ stream.eat(/J/i);
87
+ return 'number';
88
+ }
89
+ // Integers
90
+ var intLiteral = false;
91
+ // Hex
92
+ if (stream.match(/^0x[0-9a-f]+/i)) { intLiteral = true; }
93
+ // Binary
94
+ if (stream.match(/^0b[01]+/i)) { intLiteral = true; }
95
+ // Octal
96
+ if (stream.match(/^0o[0-7]+/i)) { intLiteral = true; }
97
+ // Decimal
98
+ if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
99
+ // Decimal literals may be "imaginary"
100
+ stream.eat(/J/i);
101
+ // TODO - Can you have imaginary longs?
102
+ intLiteral = true;
103
+ }
104
+ // Zero by itself with no other piece of number.
105
+ if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
106
+ if (intLiteral) {
107
+ // Integer literals may be "long"
108
+ stream.eat(/L/i);
109
+ return 'number';
110
+ }
111
+ }
112
+
113
+ // Handle Strings
114
+ if (stream.match(stringPrefixes)) {
115
+ state.tokenize = tokenStringFactory(stream.current());
116
+ return state.tokenize(stream, state);
117
+ }
118
+
119
+ // Handle operators and Delimiters
120
+ if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
121
+ return null;
122
+ }
123
+ if (stream.match(doubleOperators)
124
+ || stream.match(singleOperators)
125
+ || stream.match(wordOperators)) {
126
+ return 'operator';
127
+ }
128
+ if (stream.match(singleDelimiters)) {
129
+ return null;
130
+ }
131
+
132
+ if (stream.match(types)) {
133
+ return 'builtin';
134
+ }
135
+
136
+ if (stream.match(keywords)) {
137
+ return 'keyword';
138
+ }
139
+
140
+ if (stream.match(identifiers)) {
141
+ return 'variable';
142
+ }
143
+
144
+ // Handle non-detected items
145
+ stream.next();
146
+ return ERRORCLASS;
147
+ }
148
+
149
+ function tokenStringFactory(delimiter) {
150
+ while ('rub'.indexOf(delimiter[0].toLowerCase()) >= 0) {
151
+ delimiter = delimiter.substr(1);
152
+ }
153
+ var delim_re = new RegExp(delimiter);
154
+ var singleline = delimiter.length == 1;
155
+ var OUTCLASS = 'string';
156
+
157
+ return function tokenString(stream, state) {
158
+ while (!stream.eol()) {
159
+ stream.eatWhile(/[^'"\\]/);
160
+ if (stream.eat('\\')) {
161
+ stream.next();
162
+ if (singleline && stream.eol()) {
163
+ return OUTCLASS;
164
+ }
165
+ } else if (stream.match(delim_re)) {
166
+ state.tokenize = tokenBase;
167
+ return OUTCLASS;
168
+ } else {
169
+ stream.eat(/['"]/);
170
+ }
171
+ }
172
+ if (singleline) {
173
+ if (conf.mode.singleLineStringErrors) {
174
+ OUTCLASS = ERRORCLASS
175
+ } else {
176
+ state.tokenize = tokenBase;
177
+ }
178
+ }
179
+ return OUTCLASS;
180
+ };
181
+ }
182
+
183
+ function indent(stream, state, type) {
184
+ type = type || 'py';
185
+ var indentUnit = 0;
186
+ if (type === 'py') {
187
+ for (var i = 0; i < state.scopes.length; ++i) {
188
+ if (state.scopes[i].type === 'py') {
189
+ indentUnit = state.scopes[i].offset + conf.indentUnit;
190
+ break;
191
+ }
192
+ }
193
+ } else {
194
+ indentUnit = stream.column() + stream.current().length;
195
+ }
196
+ state.scopes.unshift({
197
+ offset: indentUnit,
198
+ type: type
199
+ });
200
+ }
201
+
202
+ function dedent(stream, state) {
203
+ if (state.scopes.length == 1) return;
204
+ if (state.scopes[0].type === 'py') {
205
+ var _indent = stream.indentation();
206
+ var _indent_index = -1;
207
+ for (var i = 0; i < state.scopes.length; ++i) {
208
+ if (_indent === state.scopes[i].offset) {
209
+ _indent_index = i;
210
+ break;
211
+ }
212
+ }
213
+ if (_indent_index === -1) {
214
+ return true;
215
+ }
216
+ while (state.scopes[0].offset !== _indent) {
217
+ state.scopes.shift();
218
+ }
219
+ return false
220
+ } else {
221
+ state.scopes.shift();
222
+ return false;
223
+ }
224
+ }
225
+
226
+ function tokenLexer(stream, state) {
227
+ indentInfo = null;
228
+ var style = state.tokenize(stream, state);
229
+ var current = stream.current();
230
+
231
+ // Handle '.' connected identifiers
232
+ if (current === '.') {
233
+ style = state.tokenize(stream, state);
234
+ current = stream.current();
235
+ if (style === 'variable') {
236
+ return 'variable';
237
+ } else {
238
+ return ERRORCLASS;
239
+ }
240
+ }
241
+
242
+ // Handle decorators
243
+ if (current === '@') {
244
+ style = state.tokenize(stream, state);
245
+ current = stream.current();
246
+ if (style === 'variable'
247
+ || current === '@staticmethod'
248
+ || current === '@classmethod') {
249
+ return 'meta';
250
+ } else {
251
+ return ERRORCLASS;
252
+ }
253
+ }
254
+
255
+ // Handle scope changes.
256
+ if (current === 'pass' || current === 'return') {
257
+ state.dedent += 1;
258
+ }
259
+ if ((current === ':' && !state.lambda && state.scopes[0].type == 'py')
260
+ || indentInfo === 'indent') {
261
+ indent(stream, state);
262
+ }
263
+ var delimiter_index = '[({'.indexOf(current);
264
+ if (delimiter_index !== -1) {
265
+ indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1));
266
+ }
267
+ if (indentInfo === 'dedent') {
268
+ if (dedent(stream, state)) {
269
+ return ERRORCLASS;
270
+ }
271
+ }
272
+ delimiter_index = '])}'.indexOf(current);
273
+ if (delimiter_index !== -1) {
274
+ if (dedent(stream, state)) {
275
+ return ERRORCLASS;
276
+ }
277
+ }
278
+ if (state.dedent > 0 && stream.eol() && state.scopes[0].type == 'py') {
279
+ if (state.scopes.length > 1) state.scopes.shift();
280
+ state.dedent -= 1;
281
+ }
282
+
283
+ return style;
284
+ }
285
+
286
+ var external = {
287
+ startState: function(basecolumn) {
288
+ return {
289
+ tokenize: tokenBase,
290
+ scopes: [{offset:basecolumn || 0, type:'py'}],
291
+ lastToken: null,
292
+ lambda: false,
293
+ dedent: 0
294
+ };
295
+ },
296
+
297
+ token: function(stream, state) {
298
+ var style = tokenLexer(stream, state);
299
+
300
+ state.lastToken = {style:style, content: stream.current()};
301
+
302
+ if (stream.eol() && stream.lambda) {
303
+ state.lambda = false;
304
+ }
305
+
306
+ return style;
307
+ },
308
+
309
+ indent: function(state, textAfter) {
310
+ if (state.tokenize != tokenBase) {
311
+ return 0;
312
+ }
313
+
314
+ return state.scopes[0].offset;
315
+ }
316
+
317
+ };
318
+ return external;
319
+ });
320
+
321
+ CodeMirror.defineMIME("text/x-python", "python");