l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

julia.js (7457B)


      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>
      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 v0.6 itself through
     13   // the following scripts for each.
     14 
     15   // ref: http://julia.readthedocs.org/en/latest/manual/variables/#allowed-variable-names
     16   var VARIABLE_NAME_RE = '[A-Za-z_\\u00A1-\\uFFFF][A-Za-z_0-9\\u00A1-\\uFFFF]*';
     17 
     18   var KEYWORDS = {
     19     $pattern: VARIABLE_NAME_RE,
     20     // # keyword generator, multi-word keywords handled manually below
     21     // foreach(println, ["in", "isa", "where"])
     22     // for kw in Base.REPLCompletions.complete_keyword("")
     23     //     if !(contains(kw, " ") || kw == "struct")
     24     //         println(kw)
     25     //     end
     26     // end
     27     keyword:
     28       'in isa where ' +
     29       'baremodule begin break catch ccall const continue do else elseif end export false finally for function ' +
     30       'global if import importall let local macro module quote return true try using while ' +
     31       // legacy, to be deprecated in the next release
     32       'type immutable abstract bitstype typealias ',
     33 
     34     // # literal generator
     35     // println("true")
     36     // println("false")
     37     // for name in Base.REPLCompletions.completions("", 0)[1]
     38     //     try
     39     //         v = eval(Symbol(name))
     40     //         if !(v isa Function || v isa Type || v isa TypeVar || v isa Module || v isa Colon)
     41     //             println(name)
     42     //         end
     43     //     end
     44     // end
     45     literal:
     46       'true false ' +
     47       'ARGS C_NULL DevNull ENDIAN_BOM ENV I Inf Inf16 Inf32 Inf64 InsertionSort JULIA_HOME LOAD_PATH MergeSort ' +
     48       'NaN NaN16 NaN32 NaN64 PROGRAM_FILE QuickSort RoundDown RoundFromZero RoundNearest RoundNearestTiesAway ' +
     49       'RoundNearestTiesUp RoundToZero RoundUp STDERR STDIN STDOUT VERSION catalan e|0 eu|0 eulergamma golden im ' +
     50       'nothing pi γ π φ ',
     51 
     52     // # built_in generator:
     53     // for name in Base.REPLCompletions.completions("", 0)[1]
     54     //     try
     55     //         v = eval(Symbol(name))
     56     //         if v isa Type || v isa TypeVar
     57     //             println(name)
     58     //         end
     59     //     end
     60     // end
     61     built_in:
     62       'ANY AbstractArray AbstractChannel AbstractFloat AbstractMatrix AbstractRNG AbstractSerializer AbstractSet ' +
     63       'AbstractSparseArray AbstractSparseMatrix AbstractSparseVector AbstractString AbstractUnitRange AbstractVecOrMat ' +
     64       'AbstractVector Any ArgumentError Array AssertionError Associative Base64DecodePipe Base64EncodePipe Bidiagonal '+
     65       'BigFloat BigInt BitArray BitMatrix BitVector Bool BoundsError BufferStream CachingPool CapturedException ' +
     66       'CartesianIndex CartesianRange Cchar Cdouble Cfloat Channel Char Cint Cintmax_t Clong Clonglong ClusterManager ' +
     67       'Cmd CodeInfo Colon Complex Complex128 Complex32 Complex64 CompositeException Condition ConjArray ConjMatrix ' +
     68       'ConjVector Cptrdiff_t Cshort Csize_t Cssize_t Cstring Cuchar Cuint Cuintmax_t Culong Culonglong Cushort Cwchar_t ' +
     69       'Cwstring DataType Date DateFormat DateTime DenseArray DenseMatrix DenseVecOrMat DenseVector Diagonal Dict ' +
     70       'DimensionMismatch Dims DirectIndexString Display DivideError DomainError EOFError EachLine Enum Enumerate ' +
     71       'ErrorException Exception ExponentialBackOff Expr Factorization FileMonitor Float16 Float32 Float64 Function ' +
     72       'Future GlobalRef GotoNode HTML Hermitian IO IOBuffer IOContext IOStream IPAddr IPv4 IPv6 IndexCartesian IndexLinear ' +
     73       'IndexStyle InexactError InitError Int Int128 Int16 Int32 Int64 Int8 IntSet Integer InterruptException ' +
     74       'InvalidStateException Irrational KeyError LabelNode LinSpace LineNumberNode LoadError LowerTriangular MIME Matrix ' +
     75       'MersenneTwister Method MethodError MethodTable Module NTuple NewvarNode NullException Nullable Number ObjectIdDict ' +
     76       'OrdinalRange OutOfMemoryError OverflowError Pair ParseError PartialQuickSort PermutedDimsArray Pipe ' +
     77       'PollingFileWatcher ProcessExitedException Ptr QuoteNode RandomDevice Range RangeIndex Rational RawFD ' +
     78       'ReadOnlyMemoryError Real ReentrantLock Ref Regex RegexMatch RemoteChannel RemoteException RevString RoundingMode ' +
     79       'RowVector SSAValue SegmentationFault SerializationState Set SharedArray SharedMatrix SharedVector Signed ' +
     80       'SimpleVector Slot SlotNumber SparseMatrixCSC SparseVector StackFrame StackOverflowError StackTrace StepRange ' +
     81       'StepRangeLen StridedArray StridedMatrix StridedVecOrMat StridedVector String SubArray SubString SymTridiagonal ' +
     82       'Symbol Symmetric SystemError TCPSocket Task Text TextDisplay Timer Tridiagonal Tuple Type TypeError TypeMapEntry ' +
     83       'TypeMapLevel TypeName TypeVar TypedSlot UDPSocket UInt UInt128 UInt16 UInt32 UInt64 UInt8 UndefRefError UndefVarError ' +
     84       'UnicodeError UniformScaling Union UnionAll UnitRange Unsigned UpperTriangular Val Vararg VecElement VecOrMat Vector ' +
     85       'VersionNumber Void WeakKeyDict WeakRef WorkerConfig WorkerPool '
     86   };
     87 
     88   // placeholder for recursive self-reference
     89   var DEFAULT = {
     90     keywords: KEYWORDS, illegal: /<\//
     91   };
     92 
     93   // ref: http://julia.readthedocs.org/en/latest/manual/integers-and-floating-point-numbers/
     94   var NUMBER = {
     95     className: 'number',
     96     // supported numeric literals:
     97     //  * binary literal (e.g. 0x10)
     98     //  * octal literal (e.g. 0o76543210)
     99     //  * hexadecimal literal (e.g. 0xfedcba876543210)
    100     //  * hexadecimal floating point literal (e.g. 0x1p0, 0x1.2p2)
    101     //  * decimal literal (e.g. 9876543210, 100_000_000)
    102     //  * floating pointe literal (e.g. 1.2, 1.2f, .2, 1., 1.2e10, 1.2e-10)
    103     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+)?/,
    104     relevance: 0
    105   };
    106 
    107   var CHAR = {
    108     className: 'string',
    109     begin: /'(.|\\[xXuU][a-zA-Z0-9]+)'/
    110   };
    111 
    112   var INTERPOLATION = {
    113     className: 'subst',
    114     begin: /\$\(/, end: /\)/,
    115     keywords: KEYWORDS
    116   };
    117 
    118   var INTERPOLATED_VARIABLE = {
    119     className: 'variable',
    120     begin: '\\$' + VARIABLE_NAME_RE
    121   };
    122 
    123   // TODO: neatly escape normal code in string literal
    124   var STRING = {
    125     className: 'string',
    126     contains: [hljs.BACKSLASH_ESCAPE, INTERPOLATION, INTERPOLATED_VARIABLE],
    127     variants: [
    128       { begin: /\w*"""/, end: /"""\w*/, relevance: 10 },
    129       { begin: /\w*"/, end: /"\w*/ }
    130     ]
    131   };
    132 
    133   var COMMAND = {
    134     className: 'string',
    135     contains: [hljs.BACKSLASH_ESCAPE, INTERPOLATION, INTERPOLATED_VARIABLE],
    136     begin: '`', end: '`'
    137   };
    138 
    139   var MACROCALL = {
    140     className: 'meta',
    141     begin: '@' + VARIABLE_NAME_RE
    142   };
    143 
    144   var COMMENT = {
    145     className: 'comment',
    146     variants: [
    147       { begin: '#=', end: '=#', relevance: 10 },
    148       { begin: '#', end: '$' }
    149     ]
    150   };
    151 
    152   DEFAULT.name = 'Julia';
    153   DEFAULT.contains = [
    154     NUMBER,
    155     CHAR,
    156     STRING,
    157     COMMAND,
    158     MACROCALL,
    159     COMMENT,
    160     hljs.HASH_COMMENT_MODE,
    161     {
    162       className: 'keyword',
    163       begin:
    164         '\\b(((abstract|primitive)\\s+)type|(mutable\\s+)?struct)\\b'
    165     },
    166     {begin: /<:/}  // relevance booster
    167   ];
    168   INTERPOLATION.contains = DEFAULT.contains;
    169 
    170   return DEFAULT;
    171 }
    172 
    173 module.exports = julia;