[d24f17c] | 1 | /*
|
---|
| 2 | Language: Julia
|
---|
| 3 | Description: Julia is a high-level, high-performance, dynamic programming language.
|
---|
| 4 | Author: Kenta Sato <bicycle1885@gmail.com>
|
---|
| 5 | Contributors: Alex Arslan <ararslan@comcast.net>, Fredrik Ekre <ekrefredrik@gmail.com>
|
---|
| 6 | Website: https://julialang.org
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | function julia(hljs) {
|
---|
| 10 | // Since there are numerous special names in Julia, it is too much trouble
|
---|
| 11 | // to maintain them by hand. Hence these names (i.e. keywords, literals and
|
---|
| 12 | // built-ins) are automatically generated from Julia 1.5.2 itself through
|
---|
| 13 | // the following scripts for each.
|
---|
| 14 |
|
---|
| 15 | // ref: https://docs.julialang.org/en/v1/manual/variables/#Allowed-Variable-Names
|
---|
| 16 | var VARIABLE_NAME_RE = '[A-Za-z_\\u00A1-\\uFFFF][A-Za-z_0-9\\u00A1-\\uFFFF]*';
|
---|
| 17 |
|
---|
| 18 | // # keyword generator, multi-word keywords handled manually below (Julia 1.5.2)
|
---|
| 19 | // import REPL.REPLCompletions
|
---|
| 20 | // res = String["in", "isa", "where"]
|
---|
| 21 | // for kw in collect(x.keyword for x in REPLCompletions.complete_keyword(""))
|
---|
| 22 | // if !(contains(kw, " ") || kw == "struct")
|
---|
| 23 | // push!(res, kw)
|
---|
| 24 | // end
|
---|
| 25 | // end
|
---|
| 26 | // sort!(unique!(res))
|
---|
| 27 | // foreach(x -> println("\'", x, "\',"), res)
|
---|
| 28 | var KEYWORD_LIST = [
|
---|
| 29 | 'baremodule',
|
---|
| 30 | 'begin',
|
---|
| 31 | 'break',
|
---|
| 32 | 'catch',
|
---|
| 33 | 'ccall',
|
---|
| 34 | 'const',
|
---|
| 35 | 'continue',
|
---|
| 36 | 'do',
|
---|
| 37 | 'else',
|
---|
| 38 | 'elseif',
|
---|
| 39 | 'end',
|
---|
| 40 | 'export',
|
---|
| 41 | 'false',
|
---|
| 42 | 'finally',
|
---|
| 43 | 'for',
|
---|
| 44 | 'function',
|
---|
| 45 | 'global',
|
---|
| 46 | 'if',
|
---|
| 47 | 'import',
|
---|
| 48 | 'in',
|
---|
| 49 | 'isa',
|
---|
| 50 | 'let',
|
---|
| 51 | 'local',
|
---|
| 52 | 'macro',
|
---|
| 53 | 'module',
|
---|
| 54 | 'quote',
|
---|
| 55 | 'return',
|
---|
| 56 | 'true',
|
---|
| 57 | 'try',
|
---|
| 58 | 'using',
|
---|
| 59 | 'where',
|
---|
| 60 | 'while',
|
---|
| 61 | ];
|
---|
| 62 |
|
---|
| 63 | // # literal generator (Julia 1.5.2)
|
---|
| 64 | // import REPL.REPLCompletions
|
---|
| 65 | // res = String["true", "false"]
|
---|
| 66 | // for compl in filter!(x -> isa(x, REPLCompletions.ModuleCompletion) && (x.parent === Base || x.parent === Core),
|
---|
| 67 | // REPLCompletions.completions("", 0)[1])
|
---|
| 68 | // try
|
---|
| 69 | // v = eval(Symbol(compl.mod))
|
---|
| 70 | // if !(v isa Function || v isa Type || v isa TypeVar || v isa Module || v isa Colon)
|
---|
| 71 | // push!(res, compl.mod)
|
---|
| 72 | // end
|
---|
| 73 | // catch e
|
---|
| 74 | // end
|
---|
| 75 | // end
|
---|
| 76 | // sort!(unique!(res))
|
---|
| 77 | // foreach(x -> println("\'", x, "\',"), res)
|
---|
| 78 | var LITERAL_LIST = [
|
---|
| 79 | 'ARGS',
|
---|
| 80 | 'C_NULL',
|
---|
| 81 | 'DEPOT_PATH',
|
---|
| 82 | 'ENDIAN_BOM',
|
---|
| 83 | 'ENV',
|
---|
| 84 | 'Inf',
|
---|
| 85 | 'Inf16',
|
---|
| 86 | 'Inf32',
|
---|
| 87 | 'Inf64',
|
---|
| 88 | 'InsertionSort',
|
---|
| 89 | 'LOAD_PATH',
|
---|
| 90 | 'MergeSort',
|
---|
| 91 | 'NaN',
|
---|
| 92 | 'NaN16',
|
---|
| 93 | 'NaN32',
|
---|
| 94 | 'NaN64',
|
---|
| 95 | 'PROGRAM_FILE',
|
---|
| 96 | 'QuickSort',
|
---|
| 97 | 'RoundDown',
|
---|
| 98 | 'RoundFromZero',
|
---|
| 99 | 'RoundNearest',
|
---|
| 100 | 'RoundNearestTiesAway',
|
---|
| 101 | 'RoundNearestTiesUp',
|
---|
| 102 | 'RoundToZero',
|
---|
| 103 | 'RoundUp',
|
---|
| 104 | 'VERSION|0',
|
---|
| 105 | 'devnull',
|
---|
| 106 | 'false',
|
---|
| 107 | 'im',
|
---|
| 108 | 'missing',
|
---|
| 109 | 'nothing',
|
---|
| 110 | 'pi',
|
---|
| 111 | 'stderr',
|
---|
| 112 | 'stdin',
|
---|
| 113 | 'stdout',
|
---|
| 114 | 'true',
|
---|
| 115 | 'undef',
|
---|
| 116 | 'π',
|
---|
| 117 | 'ℯ',
|
---|
| 118 | ];
|
---|
| 119 |
|
---|
| 120 | // # built_in generator (Julia 1.5.2)
|
---|
| 121 | // import REPL.REPLCompletions
|
---|
| 122 | // res = String[]
|
---|
| 123 | // for compl in filter!(x -> isa(x, REPLCompletions.ModuleCompletion) && (x.parent === Base || x.parent === Core),
|
---|
| 124 | // REPLCompletions.completions("", 0)[1])
|
---|
| 125 | // try
|
---|
| 126 | // v = eval(Symbol(compl.mod))
|
---|
| 127 | // if (v isa Type || v isa TypeVar) && (compl.mod != "=>")
|
---|
| 128 | // push!(res, compl.mod)
|
---|
| 129 | // end
|
---|
| 130 | // catch e
|
---|
| 131 | // end
|
---|
| 132 | // end
|
---|
| 133 | // sort!(unique!(res))
|
---|
| 134 | // foreach(x -> println("\'", x, "\',"), res)
|
---|
| 135 | var BUILT_IN_LIST = [
|
---|
| 136 | 'AbstractArray',
|
---|
| 137 | 'AbstractChannel',
|
---|
| 138 | 'AbstractChar',
|
---|
| 139 | 'AbstractDict',
|
---|
| 140 | 'AbstractDisplay',
|
---|
| 141 | 'AbstractFloat',
|
---|
| 142 | 'AbstractIrrational',
|
---|
| 143 | 'AbstractMatrix',
|
---|
| 144 | 'AbstractRange',
|
---|
| 145 | 'AbstractSet',
|
---|
| 146 | 'AbstractString',
|
---|
| 147 | 'AbstractUnitRange',
|
---|
| 148 | 'AbstractVecOrMat',
|
---|
| 149 | 'AbstractVector',
|
---|
| 150 | 'Any',
|
---|
| 151 | 'ArgumentError',
|
---|
| 152 | 'Array',
|
---|
| 153 | 'AssertionError',
|
---|
| 154 | 'BigFloat',
|
---|
| 155 | 'BigInt',
|
---|
| 156 | 'BitArray',
|
---|
| 157 | 'BitMatrix',
|
---|
| 158 | 'BitSet',
|
---|
| 159 | 'BitVector',
|
---|
| 160 | 'Bool',
|
---|
| 161 | 'BoundsError',
|
---|
| 162 | 'CapturedException',
|
---|
| 163 | 'CartesianIndex',
|
---|
| 164 | 'CartesianIndices',
|
---|
| 165 | 'Cchar',
|
---|
| 166 | 'Cdouble',
|
---|
| 167 | 'Cfloat',
|
---|
| 168 | 'Channel',
|
---|
| 169 | 'Char',
|
---|
| 170 | 'Cint',
|
---|
| 171 | 'Cintmax_t',
|
---|
| 172 | 'Clong',
|
---|
| 173 | 'Clonglong',
|
---|
| 174 | 'Cmd',
|
---|
| 175 | 'Colon',
|
---|
| 176 | 'Complex',
|
---|
| 177 | 'ComplexF16',
|
---|
| 178 | 'ComplexF32',
|
---|
| 179 | 'ComplexF64',
|
---|
| 180 | 'CompositeException',
|
---|
| 181 | 'Condition',
|
---|
| 182 | 'Cptrdiff_t',
|
---|
| 183 | 'Cshort',
|
---|
| 184 | 'Csize_t',
|
---|
| 185 | 'Cssize_t',
|
---|
| 186 | 'Cstring',
|
---|
| 187 | 'Cuchar',
|
---|
| 188 | 'Cuint',
|
---|
| 189 | 'Cuintmax_t',
|
---|
| 190 | 'Culong',
|
---|
| 191 | 'Culonglong',
|
---|
| 192 | 'Cushort',
|
---|
| 193 | 'Cvoid',
|
---|
| 194 | 'Cwchar_t',
|
---|
| 195 | 'Cwstring',
|
---|
| 196 | 'DataType',
|
---|
| 197 | 'DenseArray',
|
---|
| 198 | 'DenseMatrix',
|
---|
| 199 | 'DenseVecOrMat',
|
---|
| 200 | 'DenseVector',
|
---|
| 201 | 'Dict',
|
---|
| 202 | 'DimensionMismatch',
|
---|
| 203 | 'Dims',
|
---|
| 204 | 'DivideError',
|
---|
| 205 | 'DomainError',
|
---|
| 206 | 'EOFError',
|
---|
| 207 | 'Enum',
|
---|
| 208 | 'ErrorException',
|
---|
| 209 | 'Exception',
|
---|
| 210 | 'ExponentialBackOff',
|
---|
| 211 | 'Expr',
|
---|
| 212 | 'Float16',
|
---|
| 213 | 'Float32',
|
---|
| 214 | 'Float64',
|
---|
| 215 | 'Function',
|
---|
| 216 | 'GlobalRef',
|
---|
| 217 | 'HTML',
|
---|
| 218 | 'IO',
|
---|
| 219 | 'IOBuffer',
|
---|
| 220 | 'IOContext',
|
---|
| 221 | 'IOStream',
|
---|
| 222 | 'IdDict',
|
---|
| 223 | 'IndexCartesian',
|
---|
| 224 | 'IndexLinear',
|
---|
| 225 | 'IndexStyle',
|
---|
| 226 | 'InexactError',
|
---|
| 227 | 'InitError',
|
---|
| 228 | 'Int',
|
---|
| 229 | 'Int128',
|
---|
| 230 | 'Int16',
|
---|
| 231 | 'Int32',
|
---|
| 232 | 'Int64',
|
---|
| 233 | 'Int8',
|
---|
| 234 | 'Integer',
|
---|
| 235 | 'InterruptException',
|
---|
| 236 | 'InvalidStateException',
|
---|
| 237 | 'Irrational',
|
---|
| 238 | 'KeyError',
|
---|
| 239 | 'LinRange',
|
---|
| 240 | 'LineNumberNode',
|
---|
| 241 | 'LinearIndices',
|
---|
| 242 | 'LoadError',
|
---|
| 243 | 'MIME',
|
---|
| 244 | 'Matrix',
|
---|
| 245 | 'Method',
|
---|
| 246 | 'MethodError',
|
---|
| 247 | 'Missing',
|
---|
| 248 | 'MissingException',
|
---|
| 249 | 'Module',
|
---|
| 250 | 'NTuple',
|
---|
| 251 | 'NamedTuple',
|
---|
| 252 | 'Nothing',
|
---|
| 253 | 'Number',
|
---|
| 254 | 'OrdinalRange',
|
---|
| 255 | 'OutOfMemoryError',
|
---|
| 256 | 'OverflowError',
|
---|
| 257 | 'Pair',
|
---|
| 258 | 'PartialQuickSort',
|
---|
| 259 | 'PermutedDimsArray',
|
---|
| 260 | 'Pipe',
|
---|
| 261 | 'ProcessFailedException',
|
---|
| 262 | 'Ptr',
|
---|
| 263 | 'QuoteNode',
|
---|
| 264 | 'Rational',
|
---|
| 265 | 'RawFD',
|
---|
| 266 | 'ReadOnlyMemoryError',
|
---|
| 267 | 'Real',
|
---|
| 268 | 'ReentrantLock',
|
---|
| 269 | 'Ref',
|
---|
| 270 | 'Regex',
|
---|
| 271 | 'RegexMatch',
|
---|
| 272 | 'RoundingMode',
|
---|
| 273 | 'SegmentationFault',
|
---|
| 274 | 'Set',
|
---|
| 275 | 'Signed',
|
---|
| 276 | 'Some',
|
---|
| 277 | 'StackOverflowError',
|
---|
| 278 | 'StepRange',
|
---|
| 279 | 'StepRangeLen',
|
---|
| 280 | 'StridedArray',
|
---|
| 281 | 'StridedMatrix',
|
---|
| 282 | 'StridedVecOrMat',
|
---|
| 283 | 'StridedVector',
|
---|
| 284 | 'String',
|
---|
| 285 | 'StringIndexError',
|
---|
| 286 | 'SubArray',
|
---|
| 287 | 'SubString',
|
---|
| 288 | 'SubstitutionString',
|
---|
| 289 | 'Symbol',
|
---|
| 290 | 'SystemError',
|
---|
| 291 | 'Task',
|
---|
| 292 | 'TaskFailedException',
|
---|
| 293 | 'Text',
|
---|
| 294 | 'TextDisplay',
|
---|
| 295 | 'Timer',
|
---|
| 296 | 'Tuple',
|
---|
| 297 | 'Type',
|
---|
| 298 | 'TypeError',
|
---|
| 299 | 'TypeVar',
|
---|
| 300 | 'UInt',
|
---|
| 301 | 'UInt128',
|
---|
| 302 | 'UInt16',
|
---|
| 303 | 'UInt32',
|
---|
| 304 | 'UInt64',
|
---|
| 305 | 'UInt8',
|
---|
| 306 | 'UndefInitializer',
|
---|
| 307 | 'UndefKeywordError',
|
---|
| 308 | 'UndefRefError',
|
---|
| 309 | 'UndefVarError',
|
---|
| 310 | 'Union',
|
---|
| 311 | 'UnionAll',
|
---|
| 312 | 'UnitRange',
|
---|
| 313 | 'Unsigned',
|
---|
| 314 | 'Val',
|
---|
| 315 | 'Vararg',
|
---|
| 316 | 'VecElement',
|
---|
| 317 | 'VecOrMat',
|
---|
| 318 | 'Vector',
|
---|
| 319 | 'VersionNumber',
|
---|
| 320 | 'WeakKeyDict',
|
---|
| 321 | 'WeakRef',
|
---|
| 322 | ];
|
---|
| 323 |
|
---|
| 324 | var KEYWORDS = {
|
---|
| 325 | $pattern: VARIABLE_NAME_RE,
|
---|
| 326 | keyword: KEYWORD_LIST,
|
---|
| 327 | literal: LITERAL_LIST,
|
---|
| 328 | built_in: BUILT_IN_LIST,
|
---|
| 329 | };
|
---|
| 330 |
|
---|
| 331 | // placeholder for recursive self-reference
|
---|
| 332 | var DEFAULT = {
|
---|
| 333 | keywords: KEYWORDS, illegal: /<\//
|
---|
| 334 | };
|
---|
| 335 |
|
---|
| 336 | // ref: https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/
|
---|
| 337 | var NUMBER = {
|
---|
| 338 | className: 'number',
|
---|
| 339 | // supported numeric literals:
|
---|
| 340 | // * binary literal (e.g. 0x10)
|
---|
| 341 | // * octal literal (e.g. 0o76543210)
|
---|
| 342 | // * hexadecimal literal (e.g. 0xfedcba876543210)
|
---|
| 343 | // * hexadecimal floating point literal (e.g. 0x1p0, 0x1.2p2)
|
---|
| 344 | // * decimal literal (e.g. 9876543210, 100_000_000)
|
---|
| 345 | // * floating pointe literal (e.g. 1.2, 1.2f, .2, 1., 1.2e10, 1.2e-10)
|
---|
| 346 | begin: /(\b0x[\d_]*(\.[\d_]*)?|0x\.\d[\d_]*)p[-+]?\d+|\b0[box][a-fA-F0-9][a-fA-F0-9_]*|(\b\d[\d_]*(\.[\d_]*)?|\.\d[\d_]*)([eEfF][-+]?\d+)?/,
|
---|
| 347 | relevance: 0
|
---|
| 348 | };
|
---|
| 349 |
|
---|
| 350 | var CHAR = {
|
---|
| 351 | className: 'string',
|
---|
| 352 | begin: /'(.|\\[xXuU][a-zA-Z0-9]+)'/
|
---|
| 353 | };
|
---|
| 354 |
|
---|
| 355 | var INTERPOLATION = {
|
---|
| 356 | className: 'subst',
|
---|
| 357 | begin: /\$\(/, end: /\)/,
|
---|
| 358 | keywords: KEYWORDS
|
---|
| 359 | };
|
---|
| 360 |
|
---|
| 361 | var INTERPOLATED_VARIABLE = {
|
---|
| 362 | className: 'variable',
|
---|
| 363 | begin: '\\$' + VARIABLE_NAME_RE
|
---|
| 364 | };
|
---|
| 365 |
|
---|
| 366 | // TODO: neatly escape normal code in string literal
|
---|
| 367 | var STRING = {
|
---|
| 368 | className: 'string',
|
---|
| 369 | contains: [hljs.BACKSLASH_ESCAPE, INTERPOLATION, INTERPOLATED_VARIABLE],
|
---|
| 370 | variants: [
|
---|
| 371 | { begin: /\w*"""/, end: /"""\w*/, relevance: 10 },
|
---|
| 372 | { begin: /\w*"/, end: /"\w*/ }
|
---|
| 373 | ]
|
---|
| 374 | };
|
---|
| 375 |
|
---|
| 376 | var COMMAND = {
|
---|
| 377 | className: 'string',
|
---|
| 378 | contains: [hljs.BACKSLASH_ESCAPE, INTERPOLATION, INTERPOLATED_VARIABLE],
|
---|
| 379 | begin: '`', end: '`'
|
---|
| 380 | };
|
---|
| 381 |
|
---|
| 382 | var MACROCALL = {
|
---|
| 383 | className: 'meta',
|
---|
| 384 | begin: '@' + VARIABLE_NAME_RE
|
---|
| 385 | };
|
---|
| 386 |
|
---|
| 387 | var COMMENT = {
|
---|
| 388 | className: 'comment',
|
---|
| 389 | variants: [
|
---|
| 390 | { begin: '#=', end: '=#', relevance: 10 },
|
---|
| 391 | { begin: '#', end: '$' }
|
---|
| 392 | ]
|
---|
| 393 | };
|
---|
| 394 |
|
---|
| 395 | DEFAULT.name = 'Julia';
|
---|
| 396 | DEFAULT.contains = [
|
---|
| 397 | NUMBER,
|
---|
| 398 | CHAR,
|
---|
| 399 | STRING,
|
---|
| 400 | COMMAND,
|
---|
| 401 | MACROCALL,
|
---|
| 402 | COMMENT,
|
---|
| 403 | hljs.HASH_COMMENT_MODE,
|
---|
| 404 | {
|
---|
| 405 | className: 'keyword',
|
---|
| 406 | begin:
|
---|
| 407 | '\\b(((abstract|primitive)\\s+)type|(mutable\\s+)?struct)\\b'
|
---|
| 408 | },
|
---|
| 409 | {begin: /<:/} // relevance booster
|
---|
| 410 | ];
|
---|
| 411 | INTERPOLATION.contains = DEFAULT.contains;
|
---|
| 412 |
|
---|
| 413 | return DEFAULT;
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | module.exports = julia;
|
---|