diff --git a/components/prism-julia.js b/components/prism-julia.js index 8fa770f3b1..a71b785064 100644 --- a/components/prism-julia.js +++ b/components/prism-julia.js @@ -1,13 +1,31 @@ -Prism.languages.julia= { +Prism.languages.julia = { 'comment': { - pattern: /(^|[^\\])#.*/, + // support one level of nested comments + // https://github.com/JuliaLang/julia/pull/6128 + pattern: /(^|[^\\])(?:#=(?:[^#=]|=(?!#)|#(?!=)|#=(?:[^#=]|=(?!#)|#(?!=))*=#)*=#|#.*)/, lookbehind: true }, - 'string': /("""|''')[\s\S]+?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2/, - 'keyword' : /\b(?:abstract|baremodule|begin|bitstype|break|catch|ccall|const|continue|do|else|elseif|end|export|finally|for|function|global|if|immutable|import|importall|in|let|local|macro|module|print|println|quote|return|struct|try|type|typealias|using|while)\b/, - 'boolean' : /\b(?:true|false)\b/, - 'number' : /(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+\.?\d*|\.\d+)(?:[efp][+-]?\d+)?j?/i, - 'operator': /[-+*^%÷&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥]/, - 'punctuation' : /[{}[\];(),.:]/, - 'constant': /\b(?:(?:NaN|Inf)(?:16|32|64)?)\b/ + 'regex': { + // https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1 + pattern: /r"(?:\\.|[^"\\\r\n])*"[imsx]{0,4}/, + greedy: true + }, + 'string': { + // https://docs.julialang.org/en/v1/manual/strings/#man-characters-1 + // https://docs.julialang.org/en/v1/manual/strings/#String-Basics-1 + // https://docs.julialang.org/en/v1/manual/strings/#non-standard-string-literals-1 + // https://docs.julialang.org/en/v1/manual/running-external-programs/#Running-External-Programs-1 + pattern: /"""[\s\S]+?"""|\w*"(?:\\.|[^"\\\r\n])*"|(^|[^\w'])'(?:\\[^\r\n][^'\r\n]*|[^\\\r\n])'|`(?:[^\\`\r\n]|\\.)*`/, + lookbehind: true, + greedy: true + }, + 'keyword': /\b(?:abstract|baremodule|begin|bitstype|break|catch|ccall|const|continue|do|else|elseif|end|export|finally|for|function|global|if|immutable|import|importall|in|let|local|macro|module|print|println|quote|return|struct|try|type|typealias|using|while)\b/, + 'boolean': /\b(?:true|false)\b/, + 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+(?:_[\da-f]+)*\.?(?:\d+(?:_\d+)*)?|\.\d+(?:_\d+)*)(?:[efp][+-]?\d+(?:_\d+)*)?j?/i, + // https://docs.julialang.org/en/v1/manual/mathematical-operations/ + // https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity-1 + 'operator': /&&|\|\||[-+*^%÷⊻&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:|])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥'√∛]/, + 'punctuation': /::?|[{}[\]();,.?]/, + // https://docs.julialang.org/en/v1/base/numbers/#Base.im + 'constant': /\b(?:(?:NaN|Inf)(?:16|32|64)?|im|pi|e|catalan|eulergamma|golden)\b|[πℯγφ]/ }; diff --git a/components/prism-julia.min.js b/components/prism-julia.min.js index b47d12c34a..7bed6d84a3 100644 --- a/components/prism-julia.min.js +++ b/components/prism-julia.min.js @@ -1 +1 @@ -Prism.languages.julia={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0},string:/("""|''')[\s\S]+?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2/,keyword:/\b(?:abstract|baremodule|begin|bitstype|break|catch|ccall|const|continue|do|else|elseif|end|export|finally|for|function|global|if|immutable|import|importall|in|let|local|macro|module|print|println|quote|return|struct|try|type|typealias|using|while)\b/,boolean:/\b(?:true|false)\b/,number:/(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+\.?\d*|\.\d+)(?:[efp][+-]?\d+)?j?/i,operator:/[-+*^%÷&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥]/,punctuation:/[{}[\];(),.:]/,constant:/\b(?:(?:NaN|Inf)(?:16|32|64)?)\b/}; \ No newline at end of file +Prism.languages.julia={comment:{pattern:/(^|[^\\])(?:#=(?:[^#=]|=(?!#)|#(?!=)|#=(?:[^#=]|=(?!#)|#(?!=))*=#)*=#|#.*)/,lookbehind:!0},regex:{pattern:/r"(?:\\.|[^"\\\r\n])*"[imsx]{0,4}/,greedy:!0},string:{pattern:/"""[\s\S]+?"""|\w*"(?:\\.|[^"\\\r\n])*"|(^|[^\w'])'(?:\\[^\r\n][^'\r\n]*|[^\\\r\n])'|`(?:[^\\`\r\n]|\\.)*`/,lookbehind:!0,greedy:!0},keyword:/\b(?:abstract|baremodule|begin|bitstype|break|catch|ccall|const|continue|do|else|elseif|end|export|finally|for|function|global|if|immutable|import|importall|in|let|local|macro|module|print|println|quote|return|struct|try|type|typealias|using|while)\b/,boolean:/\b(?:true|false)\b/,number:/(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+(?:_[\da-f]+)*\.?(?:\d+(?:_\d+)*)?|\.\d+(?:_\d+)*)(?:[efp][+-]?\d+(?:_\d+)*)?j?/i,operator:/&&|\|\||[-+*^%÷⊻&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:|])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥'√∛]/,punctuation:/::?|[{}[\]();,.?]/,constant:/\b(?:(?:NaN|Inf)(?:16|32|64)?|im|pi|e|catalan|eulergamma|golden)\b|[πℯγφ]/}; \ No newline at end of file diff --git a/tests/languages/julia/comment_feature.test b/tests/languages/julia/comment_feature.test index 054d6023d1..559c6bf70a 100644 --- a/tests/languages/julia/comment_feature.test +++ b/tests/languages/julia/comment_feature.test @@ -1,13 +1,22 @@ # # foobar +#=# +#= + multi line + =# + +#= #= nested =# =# ---------------------------------------------------- [ ["comment", "#"], - ["comment", "# foobar"] + ["comment", "# foobar"], + ["comment", "#=#"], + ["comment", "#=\r\n multi line\r\n =#"], + ["comment", "#= #= nested =# =#"] ] ---------------------------------------------------- -Checks for comments. \ No newline at end of file +Checks for comments. diff --git a/tests/languages/julia/constant_feature.test b/tests/languages/julia/constant_feature.test index 402418ad3f..a79bbd0215 100644 --- a/tests/languages/julia/constant_feature.test +++ b/tests/languages/julia/constant_feature.test @@ -1,6 +1,13 @@ NaN NaN16 NaN32 NaN64 Inf Inf16 Inf32 Inf64 +im +pi π +e ℯ +catalan +eulergamma γ +golden φ + ---------------------------------------------------- [ @@ -11,9 +18,20 @@ Inf Inf16 Inf32 Inf64 ["constant", "Inf"], ["constant", "Inf16"], ["constant", "Inf32"], - ["constant", "Inf64"] + ["constant", "Inf64"], + + ["constant", "im"], + ["constant", "pi"], + ["constant", "π"], + ["constant", "e"], + ["constant", "ℯ"], + ["constant", "catalan"], + ["constant", "eulergamma"], + ["constant", "γ"], + ["constant", "golden"], + ["constant", "φ"] ] ---------------------------------------------------- -Checks for all constants. \ No newline at end of file +Checks for all constants. diff --git a/tests/languages/julia/issue2360.test b/tests/languages/julia/issue2360.test new file mode 100644 index 0000000000..f796996916 --- /dev/null +++ b/tests/languages/julia/issue2360.test @@ -0,0 +1,39 @@ +""" + count_consecutive(str::AbstractString, start::Int) + +Counts the number of identical characters in a given string `str` starting from index `start`. + +# Examples + +```julia-repl +julia> count_consecutive("AAAB", 3) +('A', 3) + +julia> count_consecutive("x y z", 3) +('y', 1) +``` +""" +function count_consecutive(str, start) + ... +end + +---------------------------------------------------- + +[ + ["string", "\"\"\"\r\n\tcount_consecutive(str::AbstractString, start::Int)\r\n\r\nCounts the number of identical characters in a given string `str` starting from index `start`.\r\n\r\n# Examples\r\n\r\n```julia-repl\r\njulia> count_consecutive(\"AAAB\", 3)\r\n('A', 3)\r\n\r\njulia> count_consecutive(\"x y z\", 3)\r\n('y', 1)\r\n```\r\n\"\"\""], + ["keyword", "function"], + " count_consecutive", + ["punctuation", "("], + "str", + ["punctuation", ","], + " start", + ["punctuation", ")"], + ["punctuation", "."], + ["punctuation", "."], + ["punctuation", "."], + ["keyword", "end"] +] + +---------------------------------------------------- + +Multi-line strings didn't work correctly. diff --git a/tests/languages/julia/number_feature.test b/tests/languages/julia/number_feature.test index 72fc7a48e5..5c8e2d5969 100644 --- a/tests/languages/julia/number_feature.test +++ b/tests/languages/julia/number_feature.test @@ -1,7 +1,10 @@ 0b0011 0o274 0xBadFace +0x123456789abcdef 42 +1. +.5 1.23 1e10 2.5e-4 @@ -10,6 +13,10 @@ 0x1p0 0x1.8p3 0x.4p-1 +10_000 +0.000_000_005 +0xdead_beef +0b1011_0010 ---------------------------------------------------- @@ -17,7 +24,10 @@ ["number", "0b0011"], ["number", "0o274"], ["number", "0xBadFace"], + ["number", "0x123456789abcdef"], ["number", "42"], + ["number", "1."], + ["number", ".5"], ["number", "1.23"], ["number", "1e10"], ["number", "2.5e-4"], @@ -25,9 +35,13 @@ ["number", "2.5f-4"], ["number", "0x1p0"], ["number", "0x1.8p3"], - ["number", "0x.4p-1"] + ["number", "0x.4p-1"], + ["number", "10_000"], + ["number", "0.000_000_005"], + ["number", "0xdead_beef"], + ["number", "0b1011_0010"] ] ---------------------------------------------------- -Checks for binary, octal, hexadecimal and decimal numbers. \ No newline at end of file +Checks for binary, octal, hexadecimal and decimal numbers. diff --git a/tests/languages/julia/operator_feature.test b/tests/languages/julia/operator_feature.test index 57f0d68c8b..70c611d98d 100644 --- a/tests/languages/julia/operator_feature.test +++ b/tests/languages/julia/operator_feature.test @@ -7,13 +7,18 @@ % %= ÷ ÷= ! != !== -& &= -| |= |> +& &= && +⊻ ⊻= +| |= || +|> <| $ $= < <= <: << <<= > >= >> >>= >>> >>>= = == === -~ ≠ ≤ ≥ +~ ≠ ≤ ≥ √ ∛ + +A'b +A'b'' ---------------------------------------------------- @@ -27,15 +32,24 @@ $ $= ["operator", "%"], ["operator", "%="], ["operator", "÷"], ["operator", "÷="], ["operator", "!"], ["operator", "!="], ["operator", "!=="], - ["operator", "&"], ["operator", "&="], - ["operator", "|"], ["operator", "|="], ["operator", "|>"], + ["operator", "&"], ["operator", "&="], ["operator", "&&"], + ["operator", "⊻"], ["operator", "⊻="], + ["operator", "|"], ["operator", "|="], ["operator", "||"], + ["operator", "|>"], ["operator", "<|"], ["operator", "$"], ["operator", "$="], ["operator", "<"], ["operator", "<="], ["operator", "<:"], ["operator", "<<"], ["operator", "<<="], ["operator", ">"], ["operator", ">="], ["operator", ">>"], ["operator", ">>="], ["operator", ">>>"], ["operator", ">>>="], ["operator", "="], ["operator", "=="], ["operator", "==="], - ["operator", "~"], ["operator", "≠"], ["operator", "≤"], ["operator", "≥"] + ["operator", "~"], ["operator", "≠"], ["operator", "≤"], ["operator", "≥"], ["operator", "√"], ["operator", "∛"], + "\r\n\r\nA", + ["operator", "'"], + "b\r\nA", + ["operator", "'"], + "b", + ["operator", "'"], + ["operator", "'"] ] ---------------------------------------------------- -Checks for operators. \ No newline at end of file +Checks for operators. diff --git a/tests/languages/julia/punctuation_feature.test b/tests/languages/julia/punctuation_feature.test new file mode 100644 index 0000000000..c550aec6a2 --- /dev/null +++ b/tests/languages/julia/punctuation_feature.test @@ -0,0 +1,26 @@ +{ } [ ] ( ) +; , +. +:: +? : + +---------------------------------------------------- + +[ + ["punctuation", "{"], + ["punctuation", "}"], + ["punctuation", "["], + ["punctuation", "]"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ";"], + ["punctuation", ","], + ["punctuation", "."], + ["punctuation", "::"], + ["punctuation", "?"], + ["punctuation", ":"] +] + +---------------------------------------------------- + +Checks for punctuation. diff --git a/tests/languages/julia/regex_feature.test b/tests/languages/julia/regex_feature.test new file mode 100644 index 0000000000..664196cd16 --- /dev/null +++ b/tests/languages/julia/regex_feature.test @@ -0,0 +1,17 @@ +r"foo"i +r"(a|b)(c)?(d)" +r"^\s*(?:#\s*(.*?)\s*$|$)" +r"a+.*b+.*?d$"ism + +---------------------------------------------------- + +[ + ["regex", "r\"foo\"i"], + ["regex", "r\"(a|b)(c)?(d)\""], + ["regex", "r\"^\\s*(?:#\\s*(.*?)\\s*$|$)\""], + ["regex", "r\"a+.*b+.*?d$\"ism"] +] + +---------------------------------------------------- + +Checks for regular expressions. diff --git a/tests/languages/julia/string_feature.test b/tests/languages/julia/string_feature.test index 207b3f4425..b88864a6e3 100644 --- a/tests/languages/julia/string_feature.test +++ b/tests/languages/julia/string_feature.test @@ -1,29 +1,67 @@ "" "fo\"o" +"\xe2\x88" + 'x' '\'' '\u2200' +'\x80' +'\xe2\x88' +'∀' + """foo""" """fo"o bar""" -'''foo''' -'''fo'o -bar''' + +`echo hello` +`echo "foo bar"` + +# non-standard string +s"\g<0>1" +b"DATA\xff\u2200" +v"0.3-" +raw"\\ \\\"" + +# not a character +A'b +A'b'' ---------------------------------------------------- [ ["string", "\"\""], ["string", "\"fo\\\"o\""], + ["string", "\"\\xe2\\x88\""], + ["string", "'x'"], ["string", "'\\''"], ["string", "'\\u2200'"], + ["string", "'\\x80'"], + ["string", "'\\xe2\\x88'"], + ["string", "'∀'"], + ["string", "\"\"\"foo\"\"\""], ["string", "\"\"\"fo\"o\r\nbar\"\"\""], - ["string", "'''foo'''"], - ["string", "'''fo'o\r\nbar'''"] + + ["string", "`echo hello`"], + ["string", "`echo \"foo bar\"`"], + + ["comment", "# non-standard string"], + ["string", "s\"\\g<0>1\""], + ["string", "b\"DATA\\xff\\u2200\""], + ["string", "v\"0.3-\""], + ["string", "raw\"\\\\ \\\\\\\"\""], + + ["comment", "# not a character"], + "\r\nA", + ["operator", "'"], + "b\r\nA", + ["operator", "'"], + "b", + ["operator", "'"], + ["operator", "'"] ] ---------------------------------------------------- -Checks for strings and characters. \ No newline at end of file +Checks for strings and characters.