openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

index.html (5950B)


      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 type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
     12 <div id=nav>
     13   <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></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/codemirror">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 </textarea></div>
    130 
    131 
    132 <h2>Cython mode</h2>
    133 
    134 <div><textarea id="code-cython" name="code-cython">
    135 
    136 import numpy as np
    137 cimport cython
    138 from libc.math cimport sqrt
    139 
    140 @cython.boundscheck(False)
    141 @cython.wraparound(False)
    142 def pairwise_cython(double[:, ::1] X):
    143     cdef int M = X.shape[0]
    144     cdef int N = X.shape[1]
    145     cdef double tmp, d
    146     cdef double[:, ::1] D = np.empty((M, M), dtype=np.float64)
    147     for i in range(M):
    148         for j in range(M):
    149             d = 0.0
    150             for k in range(N):
    151                 tmp = X[i, k] - X[j, k]
    152                 d += tmp * tmp
    153             D[i, j] = sqrt(d)
    154     return np.asarray(D)
    155 
    156 </textarea></div>
    157 
    158     <script>
    159       var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    160         mode: {name: "python",
    161                version: 3,
    162                singleLineStringErrors: false},
    163         lineNumbers: true,
    164         indentUnit: 4,
    165         matchBrackets: true
    166     });
    167 
    168     CodeMirror.fromTextArea(document.getElementById("code-cython"), {
    169         mode: {name: "text/x-cython",
    170                version: 2,
    171                singleLineStringErrors: false},
    172         lineNumbers: true,
    173         indentUnit: 4,
    174         matchBrackets: true
    175       });
    176     </script>
    177     <h2>Configuration Options for Python mode:</h2>
    178     <ul>
    179       <li>version - 2/3 - The version of Python to recognize.  Default is 3.</li>
    180       <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>
    181       <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>
    182     </ul>
    183     <h2>Advanced Configuration Options:</h2>
    184     <p>Usefull for superset of python syntax like Enthought enaml, IPython magics and  questionmark help</p>
    185     <ul>
    186       <li>singleOperators - RegEx - Regular Expression for single operator matching,  default : <pre>^[\\+\\-\\*/%&amp;|\\^~&lt;&gt;!]</pre> including <pre>@</pre> on Python 3</li>
    187       <li>singleDelimiters - RegEx - Regular Expression for single delimiter matching, default :  <pre>^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]</pre></li>
    188       <li>doubleOperators - RegEx - Regular Expression for double operators matching, default : <pre>^((==)|(!=)|(&lt;=)|(&gt;=)|(&lt;&gt;)|(&lt;&lt;)|(&gt;&gt;)|(//)|(\\*\\*))</pre></li>
    189       <li>doubleDelimiters - RegEx - Regular Expression for double delimiters matching, default : <pre>^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&amp;=)|(\\|=)|(\\^=))</pre></li>
    190       <li>tripleDelimiters - RegEx - Regular Expression for triple delimiters matching, default : <pre>^((//=)|(&gt;&gt;=)|(&lt;&lt;=)|(\\*\\*=))</pre></li>
    191       <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>
    192       <li>extra_keywords - list of string - List of extra words ton consider as keywords</li>
    193       <li>extra_builtins - list of string - List of extra words ton consider as builtins</li>
    194     </ul>
    195 
    196 
    197     <p><strong>MIME types defined:</strong> <code>text/x-python</code> and <code>text/x-cython</code>.</p>
    198   </article>