julia.js 7.3 KB

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