1229a8bf831cd20a9c8af3e47e5675bf00fe49eb
[myslice.git] / third-party / codemirror-3.15 / mode / python / index.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>CodeMirror: Python mode</title>
6     <link rel="stylesheet" href="../../lib/codemirror.css">
7     <script src="../../lib/codemirror.js"></script>
8     <script src="../../addon/edit/matchbrackets.js"></script>
9     <script src="python.js"></script>
10     <link rel="stylesheet" href="../../doc/docs.css">
11     <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
12   </head>
13   <body>
14     <h1>CodeMirror: Python mode</h1>
15     <h2>Python mode</h2>
16     <div><textarea id="code" name="code">
17 # Literals
18 1234
19 0.0e101
20 .123
21 0b01010011100
22 0o01234567
23 0x0987654321abcdef
24 7
25 2147483647
26 3L
27 79228162514264337593543950336L
28 0x100000000L
29 79228162514264337593543950336
30 0xdeadbeef
31 3.14j
32 10.j
33 10j
34 .001j
35 1e100j
36 3.14e-10j
37
38
39 # String Literals
40 'For\''
41 "God\""
42 """so loved
43 the world"""
44 '''that he gave
45 his only begotten\' '''
46 'that whosoever believeth \
47 in him'
48 ''
49
50 # Identifiers
51 __a__
52 a.b
53 a.b.c
54
55 # Operators
56 + - * / % & | ^ ~ < >
57 == != <= >= <> << >> // **
58 and or not in is
59
60 # Delimiters
61 () [] {} , : ` = ; @ .  # Note that @ and . require the proper context.
62 += -= *= /= %= &= |= ^=
63 //= >>= <<= **=
64
65 # Keywords
66 as assert break class continue def del elif else except
67 finally for from global if import lambda pass raise
68 return try while with yield
69
70 # Python 2 Keywords (otherwise Identifiers)
71 exec print
72
73 # Python 3 Keywords (otherwise Identifiers)
74 nonlocal
75
76 # Types
77 bool classmethod complex dict enumerate float frozenset int list object
78 property reversed set slice staticmethod str super tuple type
79
80 # Python 2 Types (otherwise Identifiers)
81 basestring buffer file long unicode xrange
82
83 # Python 3 Types (otherwise Identifiers)
84 bytearray bytes filter map memoryview open range zip
85
86 # Some Example code
87 import os
88 from package import ParentClass
89
90 @nonsenseDecorator
91 def doesNothing():
92     pass
93
94 class ExampleClass(ParentClass):
95     @staticmethod
96     def example(inputStr):
97         a = list(inputStr)
98         a.reverse()
99         return ''.join(a)
100
101     def __init__(self, mixin = 'Hello'):
102         self.mixin = mixin
103
104 </textarea></div>
105
106
107 <h2>Cython mode</h2>
108
109 <div><textarea id="code-cython" name="code-cython">
110
111 import numpy as np
112 cimport cython
113 from libc.math cimport sqrt
114
115 @cython.boundscheck(False)
116 @cython.wraparound(False)
117 def pairwise_cython(double[:, ::1] X):
118     cdef int M = X.shape[0]
119     cdef int N = X.shape[1]
120     cdef double tmp, d
121     cdef double[:, ::1] D = np.empty((M, M), dtype=np.float64)
122     for i in range(M):
123         for j in range(M):
124             d = 0.0
125             for k in range(N):
126                 tmp = X[i, k] - X[j, k]
127                 d += tmp * tmp
128             D[i, j] = sqrt(d)
129     return np.asarray(D)
130
131 </textarea></div>
132
133     <script>
134       var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
135         mode: {name: "python",
136                version: 2,
137                singleLineStringErrors: false},
138         lineNumbers: true,
139         indentUnit: 4,
140         tabMode: "shift",
141         matchBrackets: true
142     });
143
144     CodeMirror.fromTextArea(document.getElementById("code-cython"), {
145         mode: {name: "text/x-cython",
146                version: 2,
147                singleLineStringErrors: false},
148         lineNumbers: true,
149         indentUnit: 4,
150         tabMode: "shift",
151         matchBrackets: true
152       });
153     </script>
154     <h2>Configuration Options for Python mode:</h2>
155     <ul>
156       <li>version - 2/3 - The version of Python to recognize.  Default is 2.</li>
157       <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>
158     </ul>
159     <h2>Advanced Configuration Options:</h2>
160     <p>Usefull for superset of python syntax like Enthought enaml, IPython magics and  questionmark help</p>
161     <ul>
162       <li>singleOperators - RegEx - Regular Expression for single operator matching,  default : <pre>^[\\+\\-\\*/%&amp;|\\^~&lt;&gt;!]</pre></li>
163       <li>singleDelimiters - RegEx - Regular Expression for single delimiter matching, default :  <pre>^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]</pre></li>
164       <li>doubleOperators - RegEx - Regular Expression for double operators matching, default : <pre>^((==)|(!=)|(&lt;=)|(&gt;=)|(&lt;&gt;)|(&lt;&lt;)|(&gt;&gt;)|(//)|(\\*\\*))</pre></li>
165       <li>doubleDelimiters - RegEx - Regular Expressoin for double delimiters matching, default : <pre>^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&amp;=)|(\\|=)|(\\^=))</pre></li>
166       <li>tripleDelimiters - RegEx - Regular Expression for triple delimiters matching, default : <pre>^((//=)|(&gt;&gt;=)|(&lt;&lt;=)|(\\*\\*=))</pre></li>
167       <li>identifiers - RegEx - Regular Expression for identifier, default : <pre>^[_A-Za-z][_A-Za-z0-9]*</pre></li>
168       <li>extra_keywords - list of string - List of extra words ton consider as keywords</li>
169       <li>extra_builtins - list of string - List of extra words ton consider as builtins</li>
170     </ul>
171
172
173     <p><strong>MIME types defined:</strong> <code>text/x-python</code> and <code>text/x-cython</code>.</p>
174   </body>
175 </html>