comparison .cms/lib/codemirror/mode/python/index.html @ 0:78edf6b517a0 draft

24.10
author Coffee CMS <info@coffee-cms.ru>
date Fri, 11 Oct 2024 22:40:23 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:78edf6b517a0
1 <!doctype html>
2
3 <title>CodeMirror: Python mode</title>
4 <meta charset="utf-8"/>
5 <link rel=stylesheet href="../../doc/docs.css">
6
7 <link rel="stylesheet" href="../../lib/codemirror.css">
8 <script src="../../lib/codemirror.js"></script>
9 <script src="../../addon/edit/matchbrackets.js"></script>
10 <script src="python.js"></script>
11 <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
12 <div id=nav>
13 <a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
14
15 <ul>
16 <li><a href="../../index.html">Home</a>
17 <li><a href="../../doc/manual.html">Manual</a>
18 <li><a href="https://github.com/codemirror/codemirror5">Code</a>
19 </ul>
20 <ul>
21 <li><a href="../index.html">Language modes</a>
22 <li><a class=active href="#">Python</a>
23 </ul>
24 </div>
25
26 <article>
27 <h2>Python mode</h2>
28
29 <div><textarea id="code" name="code">
30 # Literals
31 1234
32 0.0e101
33 .123
34 0b01010011100
35 0o01234567
36 0x0987654321abcdef
37 7
38 2147483647
39 3L
40 79228162514264337593543950336L
41 0x100000000L
42 79228162514264337593543950336
43 0xdeadbeef
44 3.14j
45 10.j
46 10j
47 .001j
48 1e100j
49 3.14e-10j
50
51
52 # String Literals
53 'For\''
54 "God\""
55 """so loved
56 the world"""
57 '''that he gave
58 his only begotten\' '''
59 'that whosoever believeth \
60 in him'
61 ''
62
63 # Identifiers
64 __a__
65 a.b
66 a.b.c
67
68 #Unicode identifiers on Python3
69 # a = x\ddot
70 a⃗ = ẍ
71 # a = v\dot
72 a⃗ = v̇
73
74 #F\vec = m \cdot a\vec
75 F⃗ = m•a⃗
76
77 # Operators
78 + - * / % & | ^ ~ < >
79 == != <= >= <> << >> // **
80 and or not in is
81
82 #infix matrix multiplication operator (PEP 465)
83 A @ B
84
85 # Delimiters
86 () [] {} , : ` = ; @ . # Note that @ and . require the proper context on Python 2.
87 += -= *= /= %= &= |= ^=
88 //= >>= <<= **=
89
90 # Keywords
91 as assert break class continue def del elif else except
92 finally for from global if import lambda pass raise
93 return try while with yield
94
95 # Python 2 Keywords (otherwise Identifiers)
96 exec print
97
98 # Python 3 Keywords (otherwise Identifiers)
99 nonlocal
100
101 # Types
102 bool classmethod complex dict enumerate float frozenset int list object
103 property reversed set slice staticmethod str super tuple type
104
105 # Python 2 Types (otherwise Identifiers)
106 basestring buffer file long unicode xrange
107
108 # Python 3 Types (otherwise Identifiers)
109 bytearray bytes filter map memoryview open range zip
110
111 # Some Example code
112 import os
113 from package import ParentClass
114
115 @nonsenseDecorator
116 def doesNothing():
117 pass
118
119 class ExampleClass(ParentClass):
120 @staticmethod
121 def example(inputStr):
122 a = list(inputStr)
123 a.reverse()
124 return ''.join(a)
125
126 def __init__(self, mixin = 'Hello'):
127 self.mixin = mixin
128
129 # Python 3.6 f-strings (https://www.python.org/dev/peps/pep-0498/)
130 f'My name is {name}, my age next year is {age+1}, my anniversary is {anniversary:%A, %B %d, %Y}.'
131 f'He said his name is {name!r}.'
132 f"""He said his name is {name!r}."""
133 f'{"quoted string"}'
134 f'{{ {4*10} }}'
135 f'This is an error }'
136 f'This is ok }}'
137 fr'x={4*10}\n'
138 </textarea></div>
139
140
141 <h2>Cython mode</h2>
142
143 <div><textarea id="code-cython" name="code-cython">
144
145 import numpy as np
146 cimport cython
147 from libc.math cimport sqrt
148
149 @cython.boundscheck(False)
150 @cython.wraparound(False)
151 def pairwise_cython(double[:, ::1] X):
152 cdef int M = X.shape[0]
153 cdef int N = X.shape[1]
154 cdef double tmp, d
155 cdef double[:, ::1] D = np.empty((M, M), dtype=np.float64)
156 for i in range(M):
157 for j in range(M):
158 d = 0.0
159 for k in range(N):
160 tmp = X[i, k] - X[j, k]
161 d += tmp * tmp
162 D[i, j] = sqrt(d)
163 return np.asarray(D)
164
165 </textarea></div>
166
167 <script>
168 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
169 mode: {name: "python",
170 version: 3,
171 singleLineStringErrors: false},
172 lineNumbers: true,
173 indentUnit: 4,
174 matchBrackets: true
175 });
176
177 CodeMirror.fromTextArea(document.getElementById("code-cython"), {
178 mode: {name: "text/x-cython",
179 version: 2,
180 singleLineStringErrors: false},
181 lineNumbers: true,
182 indentUnit: 4,
183 matchBrackets: true
184 });
185 </script>
186 <h2>Configuration Options for Python mode:</h2>
187 <ul>
188 <li>version - 2/3 - The version of Python to recognize. Default is 3.</li>
189 <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>
190 <li>hangingIndent - int - If you want to write long arguments to a function starting on a new line, how much that line should be indented. Defaults to one normal indentation unit.</li>
191 </ul>
192 <h2>Advanced Configuration Options:</h2>
193 <p>Useful for superset of python syntax like Enthought enaml, IPython magics and questionmark help</p>
194 <ul>
195 <li>singleOperators - RegEx - Regular Expression for single operator matching, default : <pre>^[\\+\\-\\*/%&amp;|\\^~&lt;&gt;!]</pre> including <pre>@</pre> on Python 3</li>
196 <li>singleDelimiters - RegEx - Regular Expression for single delimiter matching, default : <pre>^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]</pre></li>
197 <li>doubleOperators - RegEx - Regular Expression for double operators matching, default : <pre>^((==)|(!=)|(&lt;=)|(&gt;=)|(&lt;&gt;)|(&lt;&lt;)|(&gt;&gt;)|(//)|(\\*\\*))</pre></li>
198 <li>doubleDelimiters - RegEx - Regular Expression for double delimiters matching, default : <pre>^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&amp;=)|(\\|=)|(\\^=))</pre></li>
199 <li>tripleDelimiters - RegEx - Regular Expression for triple delimiters matching, default : <pre>^((//=)|(&gt;&gt;=)|(&lt;&lt;=)|(\\*\\*=))</pre></li>
200 <li>identifiers - RegEx - Regular Expression for identifier, default : <pre>^[_A-Za-z][_A-Za-z0-9]*</pre> on Python 2 and <pre>^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*</pre> on Python 3.</li>
201 <li>extra_keywords - list of string - List of extra words ton consider as keywords</li>
202 <li>extra_builtins - list of string - List of extra words ton consider as builtins</li>
203 </ul>
204
205
206 <p><strong>MIME types defined:</strong> <code>text/x-python</code> and <code>text/x-cython</code>.</p>
207 </article>