eric6/ThirdParty/Pygments/pygments/lexers/julia.py

changeset 7701
25f42e208e08
parent 7547
21b0534faebc
child 7983
54c5cfbb1e29
equal deleted inserted replaced
7700:a3cf077a8db3 7701:25f42e208e08
3 pygments.lexers.julia 3 pygments.lexers.julia
4 ~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for the Julia language. 6 Lexers for the Julia language.
7 7
8 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 13
14 from pygments.lexer import Lexer, RegexLexer, bygroups, do_insertions, \ 14 from pygments.lexer import Lexer, RegexLexer, bygroups, do_insertions, \
15 words, include 15 words, include
16 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 16 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
17 Number, Punctuation, Generic 17 Number, Punctuation, Generic
18 from pygments.util import shebang_matches, unirange 18 from pygments.util import shebang_matches
19 19
20 __all__ = ['JuliaLexer', 'JuliaConsoleLexer'] 20 __all__ = ['JuliaLexer', 'JuliaConsoleLexer']
21 21
22 allowed_variable = ( 22 allowed_variable = \
23 u'(?:[a-zA-Z_\u00A1-\uffff]|%s)(?:[a-zA-Z_0-9\u00A1-\uffff]|%s)*!*' % 23 '(?:[a-zA-Z_\u00A1-\U0010ffff]|%s)(?:[a-zA-Z_0-9\u00A1-\U0010ffff])*!*'
24 ((unirange(0x10000, 0x10ffff),) * 2))
25 24
26 25
27 class JuliaLexer(RegexLexer): 26 class JuliaLexer(RegexLexer):
28 """ 27 """
29 For `Julia <http://julialang.org/>`_ source code. 28 For `Julia <http://julialang.org/>`_ source code.
129 'WeakKeyDict', 'WeakRef', 'WorkerConfig', 'Zip'], suffix=r'\b'), 128 'WeakKeyDict', 'WeakRef', 'WorkerConfig', 'Zip'], suffix=r'\b'),
130 Keyword.Type), 129 Keyword.Type),
131 130
132 # builtins 131 # builtins
133 (words([ 132 (words([
134 u'ARGS', u'CPU_CORES', u'C_NULL', u'DevNull', u'ENDIAN_BOM', 133 'ARGS', 'CPU_CORES', 'C_NULL', 'DevNull', 'ENDIAN_BOM',
135 u'ENV', u'I', u'Inf', u'Inf16', u'Inf32', u'Inf64', 134 'ENV', 'I', 'Inf', 'Inf16', 'Inf32', 'Inf64',
136 u'InsertionSort', u'JULIA_HOME', u'LOAD_PATH', u'MergeSort', 135 'InsertionSort', 'JULIA_HOME', 'LOAD_PATH', 'MergeSort',
137 u'NaN', u'NaN16', u'NaN32', u'NaN64', u'OS_NAME', 136 'NaN', 'NaN16', 'NaN32', 'NaN64', 'OS_NAME',
138 u'QuickSort', u'RoundDown', u'RoundFromZero', u'RoundNearest', 137 'QuickSort', 'RoundDown', 'RoundFromZero', 'RoundNearest',
139 u'RoundNearestTiesAway', u'RoundNearestTiesUp', 138 'RoundNearestTiesAway', 'RoundNearestTiesUp',
140 u'RoundToZero', u'RoundUp', u'STDERR', u'STDIN', u'STDOUT', 139 'RoundToZero', 'RoundUp', 'STDERR', 'STDIN', 'STDOUT',
141 u'VERSION', u'WORD_SIZE', u'catalan', u'e', u'eu', 140 'VERSION', 'WORD_SIZE', 'catalan', 'e', 'eu',
142 u'eulergamma', u'golden', u'im', u'nothing', u'pi', u'γ', 141 'eulergamma', 'golden', 'im', 'nothing', 'pi', 'γ', 'π', 'φ'],
143 u'π', u'φ'],
144 suffix=r'\b'), Name.Builtin), 142 suffix=r'\b'), Name.Builtin),
145 143
146 # operators 144 # operators
147 # see: https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm 145 # see: https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm
148 (words([ 146 (words((
149 # prec-assignment 147 # prec-assignment
150 u'=', u':=', u'+=', u'-=', u'*=', u'/=', u'//=', u'.//=', u'.*=', u'./=', 148 '=', ':=', '+=', '-=', '*=', '/=', '//=', './/=', '.*=', './=',
151 u'\\=', u'.\\=', u'^=', u'.^=', u'÷=', u'.÷=', u'%=', u'.%=', u'|=', u'&=', 149 '\\=', '.\\=', '^=', '.^=', '÷=', '.÷=', '%=', '.%=', '|=', '&=',
152 u'$=', u'=>', u'<<=', u'>>=', u'>>>=', u'~', u'.+=', u'.-=', 150 '$=', '=>', '<<=', '>>=', '>>>=', '~', '.+=', '.-=',
153 # prec-conditional 151 # prec-conditional
154 u'?', 152 '?',
155 # prec-arrow 153 # prec-arrow
156 u'--', u'-->', 154 '--', '-->',
157 # prec-lazy-or 155 # prec-lazy-or
158 u'||', 156 '||',
159 # prec-lazy-and 157 # prec-lazy-and
160 u'&&', 158 '&&',
161 # prec-comparison 159 # prec-comparison
162 u'>', u'<', u'>=', u'≥', u'<=', u'≤', u'==', u'===', u'≡', u'!=', u'≠', 160 '>', '<', '>=', '≥', '<=', '≤', '==', '===', '≡', '!=', '≠',
163 u'!==', u'≢', u'.>', u'.<', u'.>=', u'.≥', u'.<=', u'.≤', u'.==', u'.!=', 161 '!==', '≢', '.>', '.<', '.>=', '.≥', '.<=', '.≤', '.==', '.!=',
164 u'.≠', u'.=', u'.!', u'<:', u'>:', u'∈', u'∉', u'∋', u'∌', u'⊆', 162 '.≠', '.=', '.!', '<:', '>:', '∈', '∉', '∋', '∌', '⊆',
165 u'⊈', u'⊂', 163 '⊈', '⊂',
166 u'⊄', u'⊊', 164 '⊄', '⊊',
167 # prec-pipe 165 # prec-pipe
168 u'|>', u'<|', 166 '|>', '<|',
169 # prec-colon 167 # prec-colon
170 u':', 168 ':',
171 # prec-plus 169 # prec-plus
172 u'+', u'-', u'.+', u'.-', u'|', u'∪', u'$', 170 '.+', '.-', '|', '∪', '$',
173 # prec-bitshift 171 # prec-bitshift
174 u'<<', u'>>', u'>>>', u'.<<', u'.>>', u'.>>>', 172 '<<', '>>', '>>>', '.<<', '.>>', '.>>>',
175 # prec-times 173 # prec-times
176 u'*', u'/', u'./', u'÷', u'.÷', u'%', u'⋅', u'.%', u'.*', u'\\', u'.\\', u'&', u'∩', 174 '*', '/', './', '÷', '.÷', '%', '⋅', '.%', '.*', '\\', '.\\', '&', '∩',
177 # prec-rational 175 # prec-rational
178 u'//', u'.//', 176 '//', './/',
179 # prec-power 177 # prec-power
180 u'^', u'.^', 178 '^', '.^',
181 # prec-decl 179 # prec-decl
182 u'::', 180 '::',
183 # prec-dot 181 # prec-dot
184 u'.', 182 '.',
185 # unary op 183 # unary op
186 u'+', u'-', u'!', u'√', u'∛', u'∜' 184 '+', '-', '!', '√', '∛', '∜',
187 ]), Operator), 185 )), Operator),
188 186
189 # chars 187 # chars
190 (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,3}|\\u[a-fA-F0-9]{1,4}|" 188 (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,3}|\\u[a-fA-F0-9]{1,4}|"
191 r"\\U[a-fA-F0-9]{1,6}|[^\\\'\n])'", String.Char), 189 r"\\U[a-fA-F0-9]{1,6}|[^\\\'\n])'", String.Char),
192 190
314 elif line.startswith(' ') and not output: 312 elif line.startswith(' ') and not output:
315 insertions.append((len(curcode), [(0, Text, line[:6])])) 313 insertions.append((len(curcode), [(0, Text, line[:6])]))
316 curcode += line[6:] 314 curcode += line[6:]
317 else: 315 else:
318 if curcode: 316 if curcode:
319 for item in do_insertions( 317 yield from do_insertions(
320 insertions, jllexer.get_tokens_unprocessed(curcode)): 318 insertions, jllexer.get_tokens_unprocessed(curcode))
321 yield item
322 curcode = '' 319 curcode = ''
323 insertions = [] 320 insertions = []
324 if line.startswith('ERROR: ') or error: 321 if line.startswith('ERROR: ') or error:
325 yield start, Generic.Error, line 322 yield start, Generic.Error, line
326 error = True 323 error = True
328 yield start, Generic.Output, line 325 yield start, Generic.Output, line
329 output = True 326 output = True
330 start += len(line) 327 start += len(line)
331 328
332 if curcode: 329 if curcode:
333 for item in do_insertions( 330 yield from do_insertions(
334 insertions, jllexer.get_tokens_unprocessed(curcode)): 331 insertions, jllexer.get_tokens_unprocessed(curcode))
335 yield item

eric ide

mercurial