diff options
author | Jose Antonio Marquez | 2012-01-27 12:05:17 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-01-27 12:05:17 -0800 |
commit | 3a754133dbc138390503341fd2e9beba3e43aa4b (patch) | |
tree | cdeae7d7dd9a30d7b4fab5afb7efad68d4ec7508 /imports/codemirror/mode/python | |
parent | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (diff) | |
download | ninja-3a754133dbc138390503341fd2e9beba3e43aa4b.tar.gz |
Merged old FileIO
Diffstat (limited to 'imports/codemirror/mode/python')
-rwxr-xr-x | imports/codemirror/mode/python/LICENSE.txt | 21 | ||||
-rwxr-xr-x | imports/codemirror/mode/python/index.html | 122 | ||||
-rwxr-xr-x | imports/codemirror/mode/python/python.js | 333 |
3 files changed, 476 insertions, 0 deletions
diff --git a/imports/codemirror/mode/python/LICENSE.txt b/imports/codemirror/mode/python/LICENSE.txt new file mode 100755 index 00000000..918866b4 --- /dev/null +++ b/imports/codemirror/mode/python/LICENSE.txt | |||
@@ -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. \ No newline at end of file | ||
diff --git a/imports/codemirror/mode/python/index.html b/imports/codemirror/mode/python/index.html new file mode 100755 index 00000000..47e0e9d0 --- /dev/null +++ b/imports/codemirror/mode/python/index.html | |||
@@ -0,0 +1,122 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: 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="../../doc/docs.css"> | ||
9 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | ||
10 | </head> | ||
11 | <body> | ||
12 | <h1>CodeMirror: Python mode</h1> | ||
13 | |||
14 | <div><textarea id="code" name="code"> | ||
15 | # Literals | ||
16 | 1234 | ||
17 | 0.0e101 | ||
18 | .123 | ||
19 | 0b01010011100 | ||
20 | 0o01234567 | ||
21 | 0x0987654321abcdef | ||
22 | 7 | ||
23 | 2147483647 | ||
24 | 3L | ||
25 | 79228162514264337593543950336L | ||
26 | 0x100000000L | ||
27 | 79228162514264337593543950336 | ||
28 | 0xdeadbeef | ||
29 | 3.14j | ||
30 | 10.j | ||
31 | 10j | ||
32 | .001j | ||
33 | 1e100j | ||
34 | 3.14e-10j | ||
35 | |||
36 | |||
37 | # String Literals | ||
38 | 'For\'' | ||
39 | "God\"" | ||
40 | """so loved | ||
41 | the world""" | ||
42 | '''that he gave | ||
43 | his only begotten\' ''' | ||
44 | 'that whosoever believeth \ | ||
45 | in him' | ||
46 | '' | ||
47 | |||
48 | # Identifiers | ||
49 | __a__ | ||
50 | a.b | ||
51 | a.b.c | ||
52 | |||
53 | # Operators | ||
54 | + - * / % & | ^ ~ < > | ||
55 | == != <= >= <> << >> // ** | ||
56 | and or not in is | ||
57 | |||
58 | # Delimiters | ||
59 | () [] {} , : ` = ; @ . # Note that @ and . require the proper context. | ||
60 | += -= *= /= %= &= |= ^= | ||
61 | //= >>= <<= **= | ||
62 | |||
63 | # Keywords | ||
64 | as assert break class continue def del elif else except | ||
65 | finally for from global if import lambda pass raise | ||
66 | return try while with yield | ||
67 | |||
68 | # Python 2 Keywords (otherwise Identifiers) | ||
69 | exec print | ||
70 | |||
71 | # Python 3 Keywords (otherwise Identifiers) | ||
72 | nonlocal | ||
73 | |||
74 | # Types | ||
75 | bool classmethod complex dict enumerate float frozenset int list object | ||
76 | property reversed set slice staticmethod str super tuple type | ||
77 | |||
78 | # Python 2 Types (otherwise Identifiers) | ||
79 | basestring buffer file long unicode xrange | ||
80 | |||
81 | # Python 3 Types (otherwise Identifiers) | ||
82 | bytearray bytes filter map memoryview open range zip | ||
83 | |||
84 | # Some Example code | ||
85 | import os | ||
86 | from package import ParentClass | ||
87 | |||
88 | @nonsenseDecorator | ||
89 | def doesNothing(): | ||
90 | pass | ||
91 | |||
92 | class ExampleClass(ParentClass): | ||
93 | @staticmethod | ||
94 | def example(inputStr): | ||
95 | a = list(inputStr) | ||
96 | a.reverse() | ||
97 | return ''.join(a) | ||
98 | |||
99 | def __init__(self, mixin = 'Hello'): | ||
100 | self.mixin = mixin | ||
101 | |||
102 | </textarea></div> | ||
103 | <script> | ||
104 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
105 | mode: {name: "python", | ||
106 | version: 2, | ||
107 | singleLineStringErrors: false}, | ||
108 | lineNumbers: true, | ||
109 | indentUnit: 4, | ||
110 | tabMode: "shift", | ||
111 | matchBrackets: true | ||
112 | }); | ||
113 | </script> | ||
114 | <h2>Configuration Options:</h2> | ||
115 | <ul> | ||
116 | <li>version - 2/3 - The version of Python to recognize. Default is 2.</li> | ||
117 | <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> | ||
118 | </ul> | ||
119 | |||
120 | <p><strong>MIME types defined:</strong> <code>text/x-python</code>.</p> | ||
121 | </body> | ||
122 | </html> | ||
diff --git a/imports/codemirror/mode/python/python.js b/imports/codemirror/mode/python/python.js new file mode 100755 index 00000000..382052ba --- /dev/null +++ b/imports/codemirror/mode/python/python.js | |||
@@ -0,0 +1,333 @@ | |||
1 | CodeMirror.defineMode("python", function(conf, parserConf) { | ||
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 (!!parserConf.version && parseInt(parserConf.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 | |||