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