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 |