From cc1741ee8121be70631a54c44867e81488ea4706 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 23 Oct 2020 13:56:38 +0200 Subject: [PATCH] [julia] Update keywords, built_in and literals for julia 1.X. --- AUTHORS.txt | 1 + CHANGES.md | 5 + src/languages/julia.js | 383 +++++++++++++++++++++++++++------- test/detect/julia/default.txt | 35 ++-- 4 files changed, 334 insertions(+), 90 deletions(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 23a2efc04a..f20b549a42 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -292,3 +292,4 @@ Contributors: - Konrad Rudolph - Tom Wallace - Michael Newton +- Fredrik Ekre diff --git a/CHANGES.md b/CHANGES.md index b87d8c043c..a2a9cf0560 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,10 +1,15 @@ ## Version 10.4.0 (work in process) +Language Improvements: + +- enh(julia) Update keyword lists for Julia 1.X (#2781) [Fredrik Ekre][] + Dev Improvements: - chore(dev) add theme picker to the tools/developer tool (#2770) [Josh Goebel][] [Josh Goebel]: https://github.com/joshgoebel +[Fredrik Ekre]: https://github.com/fredrikekre ## Version 10.3.1 diff --git a/src/languages/julia.js b/src/languages/julia.js index 518284fcc6..7b0b78f78c 100644 --- a/src/languages/julia.js +++ b/src/languages/julia.js @@ -2,87 +2,330 @@ Language: Julia Description: Julia is a high-level, high-performance, dynamic programming language. Author: Kenta Sato -Contributors: Alex Arslan +Contributors: Alex Arslan , Fredrik Ekre Website: https://julialang.org */ export default function(hljs) { // Since there are numerous special names in Julia, it is too much trouble // to maintain them by hand. Hence these names (i.e. keywords, literals and - // built-ins) are automatically generated from Julia v0.6 itself through + // built-ins) are automatically generated from Julia 1.5.2 itself through // the following scripts for each. - // ref: http://julia.readthedocs.org/en/latest/manual/variables/#allowed-variable-names + // ref: https://docs.julialang.org/en/v1/manual/variables/#Allowed-Variable-Names var VARIABLE_NAME_RE = '[A-Za-z_\\u00A1-\\uFFFF][A-Za-z_0-9\\u00A1-\\uFFFF]*'; + // # keyword generator, multi-word keywords handled manually below (Julia 1.5.2) + // import REPL.REPLCompletions + // res = String["in", "isa", "where"] + // for kw in collect(x.keyword for x in REPLCompletions.complete_keyword("")) + // if !(contains(kw, " ") || kw == "struct") + // push!(res, kw) + // end + // end + // sort!(unique!(res)) + // foreach(x -> println("\'", x, "\',"), res) + var KEYWORD_LIST = [ + 'baremodule', + 'begin', + 'break', + 'catch', + 'ccall', + 'const', + 'continue', + 'do', + 'else', + 'elseif', + 'end', + 'export', + 'false', + 'finally', + 'for', + 'function', + 'global', + 'if', + 'import', + 'in', + 'isa', + 'let', + 'local', + 'macro', + 'module', + 'quote', + 'return', + 'true', + 'try', + 'using', + 'where', + 'while', + ] + + // # literal generator (Julia 1.5.2) + // import REPL.REPLCompletions + // res = String["true", "false"] + // for compl in filter!(x -> isa(x, REPLCompletions.ModuleCompletion) && (x.parent === Base || x.parent === Core), + // REPLCompletions.completions("", 0)[1]) + // try + // v = eval(Symbol(compl.mod)) + // if !(v isa Function || v isa Type || v isa TypeVar || v isa Module || v isa Colon) + // push!(res, compl.mod) + // end + // catch e + // end + // end + // sort!(unique!(res)) + // foreach(x -> println("\'", x, "\',"), res) + var LITERAL_LIST = [ + 'ARGS', + 'C_NULL', + 'DEPOT_PATH', + 'ENDIAN_BOM', + 'ENV', + 'Inf', + 'Inf16', + 'Inf32', + 'Inf64', + 'InsertionSort', + 'LOAD_PATH', + 'MergeSort', + 'NaN', + 'NaN16', + 'NaN32', + 'NaN64', + 'PROGRAM_FILE', + 'QuickSort', + 'RoundDown', + 'RoundFromZero', + 'RoundNearest', + 'RoundNearestTiesAway', + 'RoundNearestTiesUp', + 'RoundToZero', + 'RoundUp', + 'VERSION|0', + 'devnull', + 'false', + 'im', + 'missing', + 'nothing', + 'pi', + 'stderr', + 'stdin', + 'stdout', + 'true', + 'undef', + 'π', + 'ℯ', + ] + + // # built_in generator (Julia 1.5.2) + // import REPL.REPLCompletions + // res = String[] + // for compl in filter!(x -> isa(x, REPLCompletions.ModuleCompletion) && (x.parent === Base || x.parent === Core), + // REPLCompletions.completions("", 0)[1]) + // try + // v = eval(Symbol(compl.mod)) + // if (v isa Type || v isa TypeVar) && (compl.mod != "=>") + // push!(res, compl.mod) + // end + // catch e + // end + // end + // sort!(unique!(res)) + // foreach(x -> println("\'", x, "\',"), res) + var BUILT_IN_LIST = [ + 'AbstractArray', + 'AbstractChannel', + 'AbstractChar', + 'AbstractDict', + 'AbstractDisplay', + 'AbstractFloat', + 'AbstractIrrational', + 'AbstractMatrix', + 'AbstractRange', + 'AbstractSet', + 'AbstractString', + 'AbstractUnitRange', + 'AbstractVecOrMat', + 'AbstractVector', + 'Any', + 'ArgumentError', + 'Array', + 'AssertionError', + 'BigFloat', + 'BigInt', + 'BitArray', + 'BitMatrix', + 'BitSet', + 'BitVector', + 'Bool', + 'BoundsError', + 'CapturedException', + 'CartesianIndex', + 'CartesianIndices', + 'Cchar', + 'Cdouble', + 'Cfloat', + 'Channel', + 'Char', + 'Cint', + 'Cintmax_t', + 'Clong', + 'Clonglong', + 'Cmd', + 'Colon', + 'Complex', + 'ComplexF16', + 'ComplexF32', + 'ComplexF64', + 'CompositeException', + 'Condition', + 'Cptrdiff_t', + 'Cshort', + 'Csize_t', + 'Cssize_t', + 'Cstring', + 'Cuchar', + 'Cuint', + 'Cuintmax_t', + 'Culong', + 'Culonglong', + 'Cushort', + 'Cvoid', + 'Cwchar_t', + 'Cwstring', + 'DataType', + 'DenseArray', + 'DenseMatrix', + 'DenseVecOrMat', + 'DenseVector', + 'Dict', + 'DimensionMismatch', + 'Dims', + 'DivideError', + 'DomainError', + 'EOFError', + 'Enum', + 'ErrorException', + 'Exception', + 'ExponentialBackOff', + 'Expr', + 'Float16', + 'Float32', + 'Float64', + 'Function', + 'GlobalRef', + 'HTML', + 'IO', + 'IOBuffer', + 'IOContext', + 'IOStream', + 'IdDict', + 'IndexCartesian', + 'IndexLinear', + 'IndexStyle', + 'InexactError', + 'InitError', + 'Int', + 'Int128', + 'Int16', + 'Int32', + 'Int64', + 'Int8', + 'Integer', + 'InterruptException', + 'InvalidStateException', + 'Irrational', + 'KeyError', + 'LinRange', + 'LineNumberNode', + 'LinearIndices', + 'LoadError', + 'MIME', + 'Matrix', + 'Method', + 'MethodError', + 'Missing', + 'MissingException', + 'Module', + 'NTuple', + 'NamedTuple', + 'Nothing', + 'Number', + 'OrdinalRange', + 'OutOfMemoryError', + 'OverflowError', + 'Pair', + 'PartialQuickSort', + 'PermutedDimsArray', + 'Pipe', + 'ProcessFailedException', + 'Ptr', + 'QuoteNode', + 'Rational', + 'RawFD', + 'ReadOnlyMemoryError', + 'Real', + 'ReentrantLock', + 'Ref', + 'Regex', + 'RegexMatch', + 'RoundingMode', + 'SegmentationFault', + 'Set', + 'Signed', + 'Some', + 'StackOverflowError', + 'StepRange', + 'StepRangeLen', + 'StridedArray', + 'StridedMatrix', + 'StridedVecOrMat', + 'StridedVector', + 'String', + 'StringIndexError', + 'SubArray', + 'SubString', + 'SubstitutionString', + 'Symbol', + 'SystemError', + 'Task', + 'TaskFailedException', + 'Text', + 'TextDisplay', + 'Timer', + 'Tuple', + 'Type', + 'TypeError', + 'TypeVar', + 'UInt', + 'UInt128', + 'UInt16', + 'UInt32', + 'UInt64', + 'UInt8', + 'UndefInitializer', + 'UndefKeywordError', + 'UndefRefError', + 'UndefVarError', + 'Union', + 'UnionAll', + 'UnitRange', + 'Unsigned', + 'Val', + 'Vararg', + 'VecElement', + 'VecOrMat', + 'Vector', + 'VersionNumber', + 'WeakKeyDict', + 'WeakRef', + ] + var KEYWORDS = { $pattern: VARIABLE_NAME_RE, - // # keyword generator, multi-word keywords handled manually below - // foreach(println, ["in", "isa", "where"]) - // for kw in Base.REPLCompletions.complete_keyword("") - // if !(contains(kw, " ") || kw == "struct") - // println(kw) - // end - // end - keyword: - 'in isa where ' + - 'baremodule begin break catch ccall const continue do else elseif end export false finally for function ' + - 'global if import importall let local macro module quote return true try using while ' + - // legacy, to be deprecated in the next release - 'type immutable abstract bitstype typealias ', - - // # literal generator - // println("true") - // println("false") - // for name in Base.REPLCompletions.completions("", 0)[1] - // try - // v = eval(Symbol(name)) - // if !(v isa Function || v isa Type || v isa TypeVar || v isa Module || v isa Colon) - // println(name) - // end - // end - // end - literal: - 'true false ' + - 'ARGS C_NULL DevNull ENDIAN_BOM ENV I Inf Inf16 Inf32 Inf64 InsertionSort JULIA_HOME LOAD_PATH MergeSort ' + - 'NaN NaN16 NaN32 NaN64 PROGRAM_FILE QuickSort RoundDown RoundFromZero RoundNearest RoundNearestTiesAway ' + - 'RoundNearestTiesUp RoundToZero RoundUp STDERR STDIN STDOUT VERSION catalan e|0 eu|0 eulergamma golden im ' + - 'nothing pi γ π φ ', - - // # built_in generator: - // for name in Base.REPLCompletions.completions("", 0)[1] - // try - // v = eval(Symbol(name)) - // if v isa Type || v isa TypeVar - // println(name) - // end - // end - // end - built_in: - 'ANY AbstractArray AbstractChannel AbstractFloat AbstractMatrix AbstractRNG AbstractSerializer AbstractSet ' + - 'AbstractSparseArray AbstractSparseMatrix AbstractSparseVector AbstractString AbstractUnitRange AbstractVecOrMat ' + - 'AbstractVector Any ArgumentError Array AssertionError Associative Base64DecodePipe Base64EncodePipe Bidiagonal '+ - 'BigFloat BigInt BitArray BitMatrix BitVector Bool BoundsError BufferStream CachingPool CapturedException ' + - 'CartesianIndex CartesianRange Cchar Cdouble Cfloat Channel Char Cint Cintmax_t Clong Clonglong ClusterManager ' + - 'Cmd CodeInfo Colon Complex Complex128 Complex32 Complex64 CompositeException Condition ConjArray ConjMatrix ' + - 'ConjVector Cptrdiff_t Cshort Csize_t Cssize_t Cstring Cuchar Cuint Cuintmax_t Culong Culonglong Cushort Cwchar_t ' + - 'Cwstring DataType Date DateFormat DateTime DenseArray DenseMatrix DenseVecOrMat DenseVector Diagonal Dict ' + - 'DimensionMismatch Dims DirectIndexString Display DivideError DomainError EOFError EachLine Enum Enumerate ' + - 'ErrorException Exception ExponentialBackOff Expr Factorization FileMonitor Float16 Float32 Float64 Function ' + - 'Future GlobalRef GotoNode HTML Hermitian IO IOBuffer IOContext IOStream IPAddr IPv4 IPv6 IndexCartesian IndexLinear ' + - 'IndexStyle InexactError InitError Int Int128 Int16 Int32 Int64 Int8 IntSet Integer InterruptException ' + - 'InvalidStateException Irrational KeyError LabelNode LinSpace LineNumberNode LoadError LowerTriangular MIME Matrix ' + - 'MersenneTwister Method MethodError MethodTable Module NTuple NewvarNode NullException Nullable Number ObjectIdDict ' + - 'OrdinalRange OutOfMemoryError OverflowError Pair ParseError PartialQuickSort PermutedDimsArray Pipe ' + - 'PollingFileWatcher ProcessExitedException Ptr QuoteNode RandomDevice Range RangeIndex Rational RawFD ' + - 'ReadOnlyMemoryError Real ReentrantLock Ref Regex RegexMatch RemoteChannel RemoteException RevString RoundingMode ' + - 'RowVector SSAValue SegmentationFault SerializationState Set SharedArray SharedMatrix SharedVector Signed ' + - 'SimpleVector Slot SlotNumber SparseMatrixCSC SparseVector StackFrame StackOverflowError StackTrace StepRange ' + - 'StepRangeLen StridedArray StridedMatrix StridedVecOrMat StridedVector String SubArray SubString SymTridiagonal ' + - 'Symbol Symmetric SystemError TCPSocket Task Text TextDisplay Timer Tridiagonal Tuple Type TypeError TypeMapEntry ' + - 'TypeMapLevel TypeName TypeVar TypedSlot UDPSocket UInt UInt128 UInt16 UInt32 UInt64 UInt8 UndefRefError UndefVarError ' + - 'UnicodeError UniformScaling Union UnionAll UnitRange Unsigned UpperTriangular Val Vararg VecElement VecOrMat Vector ' + - 'VersionNumber Void WeakKeyDict WeakRef WorkerConfig WorkerPool ' + keyword: KEYWORD_LIST.join(" "), + literal: LITERAL_LIST.join(" "), + built_in: BUILT_IN_LIST.join(" "), }; // placeholder for recursive self-reference @@ -90,7 +333,7 @@ export default function(hljs) { keywords: KEYWORDS, illegal: /<\// }; - // ref: http://julia.readthedocs.org/en/latest/manual/integers-and-floating-point-numbers/ + // ref: https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/ var NUMBER = { className: 'number', // supported numeric literals: diff --git a/test/detect/julia/default.txt b/test/detect/julia/default.txt index 12f981460a..a20262df03 100644 --- a/test/detect/julia/default.txt +++ b/test/detect/julia/default.txt @@ -1,21 +1,5 @@ ### Types -# Old-style definitions - -immutable Point{T<:AbstractFloat} - index::Int - x::T - y::T -end - -abstract A - -type B <: A end - -typealias P Point{Float16} - -# New-style definitions - struct Plus f::typeof(+) end @@ -35,7 +19,6 @@ module M using X import Y -importall Z export a, b, c @@ -44,7 +27,21 @@ end # module baremodule Bare end -### New in 0.6 + +### Miscellaneous + +# Some things new for Julia >1.0 +function f(x::Union{String,Missing,Nothing}, y::Tuple{Float64,ComplexF64}) + if x === nothing + println(devnull, "nothing") + elseif x === missing + println(stderr, "missing") + else + println(stdout, x) + end +end + +f(x::UndefInitializer = undef) = Regex("^hello, world\$") # where, infix isa, UnionAll function F{T}(x::T) where T @@ -53,8 +50,6 @@ function F{T}(x::T) where T end end -### Miscellaneous - #= Multi Line