# -*- coding: utf-8 -*- """ pygments.lexers.julia ~~~~~~~~~~~~~~~~~~~~~ Lexers for the Julia language. :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ import re from pygments.lexer import Lexer, RegexLexer, bygroups, do_insertions, \ words, include from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Generic from pygments.util import shebang_matches, unirange __all__ = ['JuliaLexer', 'JuliaConsoleLexer'] allowed_variable = ( u'(?:[a-zA-Z_\u00A1-\uffff]|%s)(?:[a-zA-Z_0-9\u00A1-\uffff]|%s)*!*' % ((unirange(0x10000, 0x10ffff),) * 2)) class JuliaLexer(RegexLexer): """ For `Julia <http://julialang.org/>`_ source code. .. versionadded:: 1.6 """ name = 'Julia' aliases = ['julia', 'jl'] filenames = ['*.jl'] mimetypes = ['text/x-julia', 'application/x-julia'] flags = re.MULTILINE | re.UNICODE tokens = { 'root': [ (r'\n', Text), (r'[^\S\n]+', Text), (r'#=', Comment.Multiline, "blockcomment"), (r'#.*$', Comment), (r'[\[\]{}(),;]', Punctuation), # keywords (r'in\b', Keyword.Pseudo), (r'(true|false)\b', Keyword.Constant), (r'(local|global|const)\b', Keyword.Declaration), (words([ 'function', 'type', 'typealias', 'abstract', 'immutable', 'baremodule', 'begin', 'bitstype', 'break', 'catch', 'ccall', 'continue', 'do', 'else', 'elseif', 'end', 'export', 'finally', 'for', 'if', 'import', 'importall', 'let', 'macro', 'module', 'quote', 'return', 'try', 'using', 'while'], suffix=r'\b'), Keyword), # NOTE # Patterns below work only for definition sites and thus hardly reliable. # # functions # (r'(function)(\s+)(' + allowed_variable + ')', # bygroups(Keyword, Text, Name.Function)), # # types # (r'(type|typealias|abstract|immutable)(\s+)(' + allowed_variable + ')', # bygroups(Keyword, Text, Name.Class)), # type names (words([ 'ANY', 'ASCIIString', 'AbstractArray', 'AbstractChannel', 'AbstractFloat', 'AbstractMatrix', 'AbstractRNG', 'AbstractSparseArray', 'AbstractSparseMatrix', 'AbstractSparseVector', 'AbstractString', 'AbstractVecOrMat', 'AbstractVector', 'Any', 'ArgumentError', 'Array', 'AssertionError', 'Associative', 'Base64DecodePipe', 'Base64EncodePipe', 'Bidiagonal', 'BigFloat', 'BigInt', 'BitArray', 'BitMatrix', 'BitVector', 'Bool', 'BoundsError', 'Box', 'BufferStream', 'CapturedException', 'CartesianIndex', 'CartesianRange', 'Cchar', 'Cdouble', 'Cfloat', 'Channel', 'Char', 'Cint', 'Cintmax_t', 'Clong', 'Clonglong', 'ClusterManager', 'Cmd', 'Coff_t', 'Colon', 'Complex', 'Complex128', 'Complex32', 'Complex64', 'CompositeException', 'Condition', 'Cptrdiff_t', 'Cshort', 'Csize_t', 'Cssize_t', 'Cstring', 'Cuchar', 'Cuint', 'Cuintmax_t', 'Culong', 'Culonglong', 'Cushort', 'Cwchar_t', 'Cwstring', 'DataType', 'Date', 'DateTime', 'DenseArray', 'DenseMatrix', 'DenseVecOrMat', 'DenseVector', 'Diagonal', 'Dict', 'DimensionMismatch', 'Dims', 'DirectIndexString', 'Display', 'DivideError', 'DomainError', 'EOFError', 'EachLine', 'Enum', 'Enumerate', 'ErrorException', 'Exception', 'Expr', 'Factorization', 'FileMonitor', 'FileOffset', 'Filter', 'Float16', 'Float32', 'Float64', 'FloatRange', 'Function', 'GenSym', 'GlobalRef', 'GotoNode', 'HTML', 'Hermitian', 'IO', 'IOBuffer', 'IOStream', 'IPv4', 'IPv6', 'InexactError', 'InitError', 'Int', 'Int128', 'Int16', 'Int32', 'Int64', 'Int8', 'IntSet', 'Integer', 'InterruptException', 'IntrinsicFunction', 'InvalidStateException', 'Irrational', 'KeyError', 'LabelNode', 'LambdaStaticData', 'LinSpace', 'LineNumberNode', 'LoadError', 'LocalProcess', 'LowerTriangular', 'MIME', 'Matrix', 'MersenneTwister', 'Method', 'MethodError', 'MethodTable', 'Module', 'NTuple', 'NewvarNode', 'NullException', 'Nullable', 'Number', 'ObjectIdDict', 'OrdinalRange', 'OutOfMemoryError', 'OverflowError', 'Pair', 'ParseError', 'PartialQuickSort', 'Pipe', 'PollingFileWatcher', 'ProcessExitedException', 'ProcessGroup', 'Ptr', 'QuoteNode', 'RandomDevice', 'Range', 'Rational', 'RawFD', 'ReadOnlyMemoryError', 'Real', 'ReentrantLock', 'Ref', 'Regex', 'RegexMatch', 'RemoteException', 'RemoteRef', 'RepString', 'RevString', 'RopeString', 'RoundingMode', 'SegmentationFault', 'SerializationState', 'Set', 'SharedArray', 'SharedMatrix', 'SharedVector', 'Signed', 'SimpleVector', 'SparseMatrixCSC', 'StackOverflowError', 'StatStruct', 'StepRange', 'StridedArray', 'StridedMatrix', 'StridedVecOrMat', 'StridedVector', 'SubArray', 'SubString', 'SymTridiagonal', 'Symbol', 'SymbolNode', 'Symmetric', 'SystemError', 'TCPSocket', 'Task', 'Text', 'TextDisplay', 'Timer', 'TopNode', 'Tridiagonal', 'Tuple', 'Type', 'TypeConstructor', 'TypeError', 'TypeName', 'TypeVar', 'UDPSocket', 'UInt', 'UInt128', 'UInt16', 'UInt32', 'UInt64', 'UInt8', 'UTF16String', 'UTF32String', 'UTF8String', 'UndefRefError', 'UndefVarError', 'UnicodeError', 'UniformScaling', 'Union', 'UnitRange', 'Unsigned', 'UpperTriangular', 'Val', 'Vararg', 'VecOrMat', 'Vector', 'VersionNumber', 'Void', 'WString', 'WeakKeyDict', 'WeakRef', 'WorkerConfig', 'Zip'], suffix=r'\b'), Keyword.Type), # builtins (words([ u'ARGS', u'CPU_CORES', u'C_NULL', u'DevNull', u'ENDIAN_BOM', u'ENV', u'I', u'Inf', u'Inf16', u'Inf32', u'Inf64', u'InsertionSort', u'JULIA_HOME', u'LOAD_PATH', u'MergeSort', u'NaN', u'NaN16', u'NaN32', u'NaN64', u'OS_NAME', u'QuickSort', u'RoundDown', u'RoundFromZero', u'RoundNearest', u'RoundNearestTiesAway', u'RoundNearestTiesUp', u'RoundToZero', u'RoundUp', u'STDERR', u'STDIN', u'STDOUT', u'VERSION', u'WORD_SIZE', u'catalan', u'e', u'eu', u'eulergamma', u'golden', u'im', u'nothing', u'pi', u'γ', u'π', u'φ'], suffix=r'\b'), Name.Builtin), # operators # see: https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm (words([ # prec-assignment u'=', u':=', u'+=', u'-=', u'*=', u'/=', u'//=', u'.//=', u'.*=', u'./=', u'\=', u'.\=', u'^=', u'.^=', u'÷=', u'.÷=', u'%=', u'.%=', u'|=', u'&=', u'$=', u'=>', u'<<=', u'>>=', u'>>>=', u'~', u'.+=', u'.-=', # prec-conditional u'?', # prec-arrow u'--', u'-->', # prec-lazy-or u'||', # prec-lazy-and u'&&', # prec-comparison u'>', u'<', u'>=', u'≥', u'<=', u'≤', u'==', u'===', u'≡', u'!=', u'≠', u'!==', u'≢', u'.>', u'.<', u'.>=', u'.≥', u'.<=', u'.≤', u'.==', u'.!=', u'.≠', u'.=', u'.!', u'<:', u'>:', u'∈', u'∉', u'∋', u'∌', u'⊆', u'⊈', u'⊂', u'⊄', u'⊊', # prec-pipe u'|>', u'<|', # prec-colon u':', # prec-plus u'+', u'-', u'.+', u'.-', u'|', u'∪', u'$', # prec-bitshift u'<<', u'>>', u'>>>', u'.<<', u'.>>', u'.>>>', # prec-times u'*', u'/', u'./', u'÷', u'.÷', u'%', u'⋅', u'.%', u'.*', u'\\', u'.\\', u'&', u'∩', # prec-rational u'//', u'.//', # prec-power u'^', u'.^', # prec-decl u'::', # prec-dot u'.', # unary op u'+', u'-', u'!', u'~', u'√', u'∛', u'∜' ]), Operator), # chars (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,3}|\\u[a-fA-F0-9]{1,4}|" r"\\U[a-fA-F0-9]{1,6}|[^\\\'\n])'", String.Char), # try to match trailing transpose (r'(?<=[.\w)\]])\'+', Operator), # strings (r'"""', String, 'tqstring'), (r'"', String, 'string'), # regular expressions (r'r"""', String.Regex, 'tqregex'), (r'r"', String.Regex, 'regex'), # backticks (r'`', String.Backtick, 'command'), # names (allowed_variable, Name), (r'@' + allowed_variable, Name.Decorator), # numbers (r'(\d+(_\d+)+\.\d*|\d*\.\d+(_\d+)+)([eEf][+-]?[0-9]+)?', Number.Float), (r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float), (r'\d+(_\d+)+[eEf][+-]?[0-9]+', Number.Float), (r'\d+[eEf][+-]?[0-9]+', Number.Float), (r'0b[01]+(_[01]+)+', Number.Bin), (r'0b[01]+', Number.Bin), (r'0o[0-7]+(_[0-7]+)+', Number.Oct), (r'0o[0-7]+', Number.Oct), (r'0x[a-fA-F0-9]+(_[a-fA-F0-9]+)+', Number.Hex), (r'0x[a-fA-F0-9]+', Number.Hex), (r'\d+(_\d+)+', Number.Integer), (r'\d+', Number.Integer) ], "blockcomment": [ (r'[^=#]', Comment.Multiline), (r'#=', Comment.Multiline, '#push'), (r'=#', Comment.Multiline, '#pop'), (r'[=#]', Comment.Multiline), ], 'string': [ (r'"', String, '#pop'), # FIXME: This escape pattern is not perfect. (r'\\([\\"\'$nrbtfav]|(x|u|U)[a-fA-F0-9]+|\d+)', String.Escape), # Interpolation is defined as "$" followed by the shortest full # expression, which is something we can't parse. # Include the most common cases here: $word, and $(paren'd expr). (r'\$' + allowed_variable, String.Interpol), # (r'\$[a-zA-Z_]+', String.Interpol), (r'(\$)(\()', bygroups(String.Interpol, Punctuation), 'in-intp'), # @printf and @sprintf formats (r'%[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]', String.Interpol), (r'.|\s', String), ], 'tqstring': [ (r'"""', String, '#pop'), (r'\\([\\"\'$nrbtfav]|(x|u|U)[a-fA-F0-9]+|\d+)', String.Escape), (r'\$' + allowed_variable, String.Interpol), (r'(\$)(\()', bygroups(String.Interpol, Punctuation), 'in-intp'), (r'.|\s', String), ], 'regex': [ (r'"', String.Regex, '#pop'), (r'\\"', String.Regex), (r'.|\s', String.Regex), ], 'tqregex': [ (r'"""', String.Regex, '#pop'), (r'.|\s', String.Regex), ], 'command': [ (r'`', String.Backtick, '#pop'), (r'\$' + allowed_variable, String.Interpol), (r'(\$)(\()', bygroups(String.Interpol, Punctuation), 'in-intp'), (r'.|\s', String.Backtick) ], 'in-intp': [ (r'\(', Punctuation, '#push'), (r'\)', Punctuation, '#pop'), include('root'), ] } def analyse_text(text): return shebang_matches(text, r'julia') class JuliaConsoleLexer(Lexer): """ For Julia console sessions. Modeled after MatlabSessionLexer. .. versionadded:: 1.6 """ name = 'Julia console' aliases = ['jlcon'] def get_tokens_unprocessed(self, text): jllexer = JuliaLexer(**self.options) start = 0 curcode = '' insertions = [] output = False error = False for line in text.splitlines(True): if line.startswith('julia>'): insertions.append((len(curcode), [(0, Generic.Prompt, line[:6])])) curcode += line[6:] output = False error = False elif line.startswith('help?>') or line.startswith('shell>'): yield start, Generic.Prompt, line[:6] yield start + 6, Text, line[6:] output = False error = False elif line.startswith(' ') and not output: insertions.append((len(curcode), [(0, Text, line[:6])])) curcode += line[6:] else: if curcode: for item in do_insertions( insertions, jllexer.get_tokens_unprocessed(curcode)): yield item curcode = '' insertions = [] if line.startswith('ERROR: ') or error: yield start, Generic.Error, line error = True else: yield start, Generic.Output, line output = True start += len(line) if curcode: for item in do_insertions( insertions, jllexer.get_tokens_unprocessed(curcode)): yield item
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
__init__.py | File | 10.65 KB | 0644 |
|
_asy_builtins.py | File | 26.68 KB | 0644 |
|
_cl_builtins.py | File | 13.72 KB | 0644 |
|
_cocoa_builtins.py | File | 39.04 KB | 0644 |
|
_csound_builtins.py | File | 21.14 KB | 0644 |
|
_lasso_builtins.py | File | 131.38 KB | 0644 |
|
_lua_builtins.py | File | 8.14 KB | 0644 |
|
_mapping.py | File | 53.43 KB | 0644 |
|
_mql_builtins.py | File | 24.16 KB | 0644 |
|
_openedge_builtins.py | File | 47.23 KB | 0644 |
|
_php_builtins.py | File | 150.75 KB | 0644 |
|
_postgres_builtins.py | File | 10.95 KB | 0644 |
|
_scilab_builtins.py | File | 51.18 KB | 0644 |
|
_sourcemod_builtins.py | File | 26.48 KB | 0644 |
|
_stan_builtins.py | File | 9.88 KB | 0644 |
|
_stata_builtins.py | File | 24.55 KB | 0644 |
|
_tsql_builtins.py | File | 15.12 KB | 0644 |
|
_vim_builtins.py | File | 55.75 KB | 0644 |
|
actionscript.py | File | 10.92 KB | 0644 |
|
agile.py | File | 900 B | 0644 |
|
algebra.py | File | 7.03 KB | 0644 |
|
ambient.py | File | 2.5 KB | 0644 |
|
ampl.py | File | 4.02 KB | 0644 |
|
apl.py | File | 3.09 KB | 0644 |
|
archetype.py | File | 10.87 KB | 0644 |
|
asm.py | File | 24.67 KB | 0644 |
|
automation.py | File | 19.19 KB | 0644 |
|
basic.py | File | 19.83 KB | 0644 |
|
bibtex.py | File | 4.61 KB | 0644 |
|
business.py | File | 27.02 KB | 0644 |
|
c_cpp.py | File | 10.28 KB | 0644 |
|
c_like.py | File | 23.56 KB | 0644 |
|
capnproto.py | File | 2.14 KB | 0644 |
|
chapel.py | File | 3.43 KB | 0644 |
|
clean.py | File | 10.16 KB | 0644 |
|
compiled.py | File | 1.35 KB | 0644 |
|
configs.py | File | 27.6 KB | 0644 |
|
console.py | File | 4.02 KB | 0644 |
|
crystal.py | File | 16.45 KB | 0644 |
|
csound.py | File | 12.25 KB | 0644 |
|
css.py | File | 30.77 KB | 0644 |
|
d.py | File | 9.31 KB | 0644 |
|
dalvik.py | File | 4.32 KB | 0644 |
|
data.py | File | 18.33 KB | 0644 |
|
diff.py | File | 4.76 KB | 0644 |
|
dotnet.py | File | 27.02 KB | 0644 |
|
dsls.py | File | 32.55 KB | 0644 |
|
dylan.py | File | 10.18 KB | 0644 |
|
ecl.py | File | 5.74 KB | 0644 |
|
eiffel.py | File | 2.42 KB | 0644 |
|
elm.py | File | 2.93 KB | 0644 |
|
erlang.py | File | 18.49 KB | 0644 |
|
esoteric.py | File | 9.27 KB | 0644 |
|
ezhil.py | File | 2.95 KB | 0644 |
|
factor.py | File | 17.44 KB | 0644 |
|
fantom.py | File | 9.75 KB | 0644 |
|
felix.py | File | 9.19 KB | 0644 |
|
forth.py | File | 6.98 KB | 0644 |
|
fortran.py | File | 9.54 KB | 0644 |
|
foxpro.py | File | 25.62 KB | 0644 |
|
functional.py | File | 698 B | 0644 |
|
go.py | File | 3.61 KB | 0644 |
|
grammar_notation.py | File | 6.18 KB | 0644 |
|
graph.py | File | 2.31 KB | 0644 |
|
graphics.py | File | 25.23 KB | 0644 |
|
haskell.py | File | 30.49 KB | 0644 |
|
haxe.py | File | 30.23 KB | 0644 |
|
hdl.py | File | 18.26 KB | 0644 |
|
hexdump.py | File | 3.42 KB | 0644 |
|
html.py | File | 18.82 KB | 0644 |
|
idl.py | File | 14.63 KB | 0644 |
|
igor.py | File | 19.53 KB | 0644 |
|
inferno.py | File | 3.04 KB | 0644 |
|
installers.py | File | 12.56 KB | 0644 |
|
int_fiction.py | File | 54.47 KB | 0644 |
|
iolang.py | File | 1.86 KB | 0644 |
|
j.py | File | 4.42 KB | 0644 |
|
javascript.py | File | 58.72 KB | 0644 |
|
julia.py | File | 13.76 KB | 0644 |
|
jvm.py | File | 65.18 KB | 0644 |
|
lisp.py | File | 137.38 KB | 0644 |
|
make.py | File | 7.16 KB | 0644 |
|
markup.py | File | 19.97 KB | 0644 |
|
math.py | File | 700 B | 0644 |
|
matlab.py | File | 28.47 KB | 0644 |
|
ml.py | File | 27.23 KB | 0644 |
|
modeling.py | File | 12.53 KB | 0644 |
|
modula2.py | File | 51.33 KB | 0644 |
|
monte.py | File | 6.16 KB | 0644 |
|
ncl.py | File | 62.49 KB | 0644 |
|
nimrod.py | File | 5.05 KB | 0644 |
|
nit.py | File | 2.68 KB | 0644 |
|
nix.py | File | 3.94 KB | 0644 |
|
oberon.py | File | 3.65 KB | 0644 |
|
objective.py | File | 22.22 KB | 0644 |
|
ooc.py | File | 2.93 KB | 0644 |
|
other.py | File | 1.73 KB | 0644 |
|
parasail.py | File | 2.67 KB | 0644 |
|
parsers.py | File | 26.94 KB | 0644 |
|
pascal.py | File | 31.88 KB | 0644 |
|
pawn.py | File | 7.9 KB | 0644 |
|
perl.py | File | 31.26 KB | 0644 |
|
php.py | File | 10.48 KB | 0644 |
|
praat.py | File | 12.26 KB | 0644 |
|
prolog.py | File | 11.78 KB | 0644 |
|
python.py | File | 41.39 KB | 0644 |
|
qvt.py | File | 5.97 KB | 0644 |
|
r.py | File | 23.2 KB | 0644 |
|
rdf.py | File | 9.18 KB | 0644 |
|
rebol.py | File | 18.18 KB | 0644 |
|
resource.py | File | 2.86 KB | 0644 |
|
rnc.py | File | 1.94 KB | 0644 |
|
roboconf.py | File | 2.02 KB | 0644 |
|
robotframework.py | File | 18.3 KB | 0644 |
|
ruby.py | File | 21.62 KB | 0644 |
|
rust.py | File | 7.51 KB | 0644 |
|
sas.py | File | 9.23 KB | 0644 |
|
scripting.py | File | 66.17 KB | 0644 |
|
shell.py | File | 30.69 KB | 0644 |
|
smalltalk.py | File | 7.05 KB | 0644 |
|
smv.py | File | 2.74 KB | 0644 |
|
snobol.py | File | 2.69 KB | 0644 |
|
special.py | File | 3.08 KB | 0644 |
|
sql.py | File | 28.75 KB | 0644 |
|
stata.py | File | 3.54 KB | 0644 |
|
supercollider.py | File | 3.43 KB | 0644 |
|
tcl.py | File | 5.27 KB | 0644 |
|
templates.py | File | 71.73 KB | 0644 |
|
testing.py | File | 10.5 KB | 0644 |
|
text.py | File | 977 B | 0644 |
|
textedit.py | File | 5.92 KB | 0644 |
|
textfmts.py | File | 10.6 KB | 0644 |
|
theorem.py | File | 18.59 KB | 0644 |
|
trafficscript.py | File | 1.51 KB | 0644 |
|
typoscript.py | File | 8.2 KB | 0644 |
|
urbi.py | File | 5.62 KB | 0644 |
|
varnish.py | File | 7.1 KB | 0644 |
|
verification.py | File | 3.62 KB | 0644 |
|
web.py | File | 918 B | 0644 |
|
webmisc.py | File | 38.96 KB | 0644 |
|
whiley.py | File | 3.92 KB | 0644 |
|
x10.py | File | 1.92 KB | 0644 |
|