julia.js 7.5 KB

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