julia.js 7.0 KB

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