From 5d484b5fa363aec35bd1450e1f162983aa0ecde8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sat, 3 Jun 2023 20:57:37 +0200 Subject: [PATCH 01/12] fix(types): move `types` condition to the front (#3800) --- tools/build_node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_node.js b/tools/build_node.js index 3bc4486ade..aac80ced04 100644 --- a/tools/build_node.js +++ b/tools/build_node.js @@ -103,8 +103,8 @@ function dual(file) { const generatePackageExports = () => ({ ".": { - ...dual("./lib/index.js"), "types": "./types/index.d.ts", + ...dual("./lib/index.js"), }, "./package.json": "./package.json", "./lib/common": dual("./lib/common.js"), From 98be55bf6520f62c581a498509baf9387461dce0 Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Mon, 12 Jun 2023 02:02:35 +0100 Subject: [PATCH 02/12] enh(swift) support `macro` keyword (#3802) * Recognize macro as function-like entity * Macro invokation should not highlight for now * Update changes --- CHANGES.md | 3 ++- src/languages/lib/kws_swift.js | 1 + src/languages/swift.js | 7 ++++--- test/markup/swift/macro.expect.txt | 6 ++++++ test/markup/swift/macro.txt | 6 ++++++ 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 test/markup/swift/macro.expect.txt create mode 100644 test/markup/swift/macro.txt diff --git a/CHANGES.md b/CHANGES.md index 38c9af982c..ce75f719c7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Core Grammars: - fix(haxe) fixed metadata arguments and support non-colon syntax [Robert Borghese][] - fix(haxe) differentiate `abstract` declaration from keyword [Robert Borghese][] - fix(bash) do not delimit a string by an escaped apostrophe [hancar][] +- enh(swift) support `macro` keyword [Bradley Mackey][] Dev tool: @@ -21,7 +22,7 @@ Dev tool: [Shah Shabbir Ahmmed]: https://github.com/shabbir23ah [Josh Goebel]: https://github.com/joshgoebel [Checconio]: https://github.com/Checconio - +[Bradley Mackey]: https://github.com/bradleymackey ## Version 11.8.0 diff --git a/src/languages/lib/kws_swift.js b/src/languages/lib/kws_swift.js index 2671729bba..5c668e2d8d 100644 --- a/src/languages/lib/kws_swift.js +++ b/src/languages/lib/kws_swift.js @@ -79,6 +79,7 @@ export const keywords = [ 'nonisolated', // contextual 'lazy', // contextual 'let', + 'macro', 'mutating', // contextual 'nonmutating', // contextual /open\(set\)/, // contextual diff --git a/src/languages/swift.js b/src/languages/swift.js index 59d4c027b5..45a1e39d2f 100644 --- a/src/languages/swift.js +++ b/src/languages/swift.js @@ -342,9 +342,10 @@ export default function(hljs) { illegal: /["']/ }; // https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID362 - const FUNCTION = { + // https://docs.swift.org/swift-book/documentation/the-swift-programming-language/declarations/#Macro-Declaration + const FUNCTION_OR_MACRO = { match: [ - /func/, + /(func|macro)/, /\s+/, either(QUOTED_IDENTIFIER.match, Swift.identifier, Swift.operator) ], @@ -441,7 +442,7 @@ export default function(hljs) { keywords: KEYWORDS, contains: [ ...COMMENTS, - FUNCTION, + FUNCTION_OR_MACRO, INIT_SUBSCRIPT, { beginKeywords: 'struct protocol class extension enum actor', diff --git a/test/markup/swift/macro.expect.txt b/test/markup/swift/macro.expect.txt new file mode 100644 index 0000000000..ed3bcffdbd --- /dev/null +++ b/test/markup/swift/macro.expect.txt @@ -0,0 +1,6 @@ +macro warning(_ message: String) = #externalMacro(module: "MyMacros", type: "WarningMacro") + +@freestanding(declaration) +macro error(_ message: String) = #externalMacro(module: "MyMacros", type: "ErrorMacro") + +#myMacro() \ No newline at end of file diff --git a/test/markup/swift/macro.txt b/test/markup/swift/macro.txt new file mode 100644 index 0000000000..24e31aa5c1 --- /dev/null +++ b/test/markup/swift/macro.txt @@ -0,0 +1,6 @@ +macro warning(_ message: String) = #externalMacro(module: "MyMacros", type: "WarningMacro") + +@freestanding(declaration) +macro error(_ message: String) = #externalMacro(module: "MyMacros", type: "ErrorMacro") + +#myMacro() \ No newline at end of file From 4efc51c60545a50496fcac36b1c614e82f54ecda Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Wed, 14 Jun 2023 04:09:08 +0100 Subject: [PATCH 03/12] enh(swift) add parameter pack keywords (#3803) * Support parameter pack * Update changes * Merge and improve test case * Use scope * Use keywords in GENERIC_PARAMETERS --- CHANGES.md | 2 ++ src/languages/lib/kws_swift.js | 1 + src/languages/swift.js | 1 + test/markup/swift/parameterpack.expect.txt | 7 +++++++ test/markup/swift/parameterpack.txt | 7 +++++++ 5 files changed, 18 insertions(+) create mode 100644 test/markup/swift/parameterpack.expect.txt create mode 100644 test/markup/swift/parameterpack.txt diff --git a/CHANGES.md b/CHANGES.md index ce75f719c7..e67d04d14d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Core Grammars: - fix(haxe) differentiate `abstract` declaration from keyword [Robert Borghese][] - fix(bash) do not delimit a string by an escaped apostrophe [hancar][] - enh(swift) support `macro` keyword [Bradley Mackey][] +- enh(swift) support parameter pack keywords [Bradley Mackey][] Dev tool: @@ -24,6 +25,7 @@ Dev tool: [Checconio]: https://github.com/Checconio [Bradley Mackey]: https://github.com/bradleymackey + ## Version 11.8.0 Parser engine: diff --git a/src/languages/lib/kws_swift.js b/src/languages/lib/kws_swift.js index 5c668e2d8d..d7944f49af 100644 --- a/src/languages/lib/kws_swift.js +++ b/src/languages/lib/kws_swift.js @@ -53,6 +53,7 @@ export const keywords = [ 'distributed', 'do', 'dynamic', // contextual + 'each', 'else', 'enum', 'extension', diff --git a/src/languages/swift.js b/src/languages/swift.js index 45a1e39d2f..5bbdf04175 100644 --- a/src/languages/swift.js +++ b/src/languages/swift.js @@ -300,6 +300,7 @@ export default function(hljs) { const GENERIC_PARAMETERS = { begin: //, + keywords: 'repeat each', contains: [ ...COMMENTS, TYPE diff --git a/test/markup/swift/parameterpack.expect.txt b/test/markup/swift/parameterpack.expect.txt new file mode 100644 index 0000000000..c33c3f9625 --- /dev/null +++ b/test/markup/swift/parameterpack.expect.txt @@ -0,0 +1,7 @@ +func expand<each T, repeat each U>(value: (repeat each T), other: each U, another: repeat each T) -> (repeat (each T)?) { + return (repeat each value, each value) +} + +let x: (repeat each T) -> Bool = { } + +(each U, repeat each T) \ No newline at end of file diff --git a/test/markup/swift/parameterpack.txt b/test/markup/swift/parameterpack.txt new file mode 100644 index 0000000000..0d40af6a27 --- /dev/null +++ b/test/markup/swift/parameterpack.txt @@ -0,0 +1,7 @@ +func expand(value: (repeat each T), other: each U, another: repeat each T) -> (repeat (each T)?) { + return (repeat each value, each value) +} + +let x: (repeat each T) -> Bool = { } + +(each U, repeat each T) \ No newline at end of file From 88dcae86d488592563c9f49c068dc97b5c62bd7a Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Wed, 14 Jun 2023 09:49:46 +0100 Subject: [PATCH 04/12] enh(swift) regex literal support (#3804) Swift 5.7 introduced regex literals, specified in SE-0354. This includes support for bare-slash (/example/) and extended regex literals (#/example/#, ##/example/##, etc). - Bare slash literals are not enabled by default in Swift 5, but will be in Swift 6. - Bare slash literals cannot start with whitespace, but extended literals can. - Only extended regex literals support newlines. - Multiline extended literals support comments starting with #, continuing until end of line. - Follows convention of raw strings, supporting up to 3 levels of delimiting for extended literals, ensuring # delimiters match. --- CHANGES.md | 1 + src/languages/swift.js | 46 +++++++++++++ src/lib/modes.js | 34 ++++----- test/markup/swift/regex.expect.txt | 103 ++++++++++++++++++++++++++++ test/markup/swift/regex.txt | 103 ++++++++++++++++++++++++++++ test/markup/swift/tuples.expect.txt | 1 + test/markup/swift/tuples.txt | 1 + 7 files changed, 267 insertions(+), 22 deletions(-) create mode 100644 test/markup/swift/regex.expect.txt create mode 100644 test/markup/swift/regex.txt diff --git a/CHANGES.md b/CHANGES.md index e67d04d14d..e041ccf3da 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ Core Grammars: - fix(bash) do not delimit a string by an escaped apostrophe [hancar][] - enh(swift) support `macro` keyword [Bradley Mackey][] - enh(swift) support parameter pack keywords [Bradley Mackey][] +- enh(swift) regex literal support [Bradley Mackey][] Dev tool: diff --git a/src/languages/swift.js b/src/languages/swift.js index 5bbdf04175..7913eda645 100644 --- a/src/languages/swift.js +++ b/src/languages/swift.js @@ -180,6 +180,50 @@ export default function(hljs) { ] }; + const REGEXP_CONTENTS = [ + hljs.BACKSLASH_ESCAPE, + { + begin: /\[/, + end: /\]/, + relevance: 0, + contains: [ hljs.BACKSLASH_ESCAPE ] + } + ]; + + const BARE_REGEXP_LITERAL = { + begin: /\/[^\s](?=[^/\n]*\/)/, + end: /\//, + contains: REGEXP_CONTENTS + }; + + const EXTENDED_REGEXP_LITERAL = (rawDelimiter) => { + const begin = concat(rawDelimiter, /\//); + const end = concat(/\//, rawDelimiter); + return { + begin, + end, + contains: [ + ...REGEXP_CONTENTS, + { + scope: "comment", + begin: `#(?!.*${end})`, + end: /$/, + }, + ], + }; + }; + + // https://docs.swift.org/swift-book/documentation/the-swift-programming-language/lexicalstructure/#Regular-Expression-Literals + const REGEXP = { + scope: "regexp", + variants: [ + EXTENDED_REGEXP_LITERAL('###'), + EXTENDED_REGEXP_LITERAL('##'), + EXTENDED_REGEXP_LITERAL('#'), + BARE_REGEXP_LITERAL + ] + }; + // https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID412 const QUOTED_IDENTIFIER = { match: concat(/`/, Swift.identifier, /`/) }; const IMPLICIT_PARAMETER = { @@ -286,6 +330,7 @@ export default function(hljs) { 'self', TUPLE_ELEMENT_NAME, ...COMMENTS, + REGEXP, ...KEYWORD_MODES, ...BUILT_INS, ...OPERATORS, @@ -466,6 +511,7 @@ export default function(hljs) { contains: [ ...COMMENTS ], relevance: 0 }, + REGEXP, ...KEYWORD_MODES, ...BUILT_INS, ...OPERATORS, diff --git a/src/lib/modes.js b/src/lib/modes.js index 5bbff22328..c0f66ef4c5 100644 --- a/src/lib/modes.js +++ b/src/lib/modes.js @@ -150,28 +150,18 @@ export const BINARY_NUMBER_MODE = { relevance: 0 }; export const REGEXP_MODE = { - // this outer rule makes sure we actually have a WHOLE regex and not simply - // an expression such as: - // - // 3 / something - // - // (which will then blow up when regex's `illegal` sees the newline) - begin: /(?=\/[^/\n]*\/)/, - contains: [{ - scope: 'regexp', - begin: /\//, - end: /\/[gimuy]*/, - illegal: /\n/, - contains: [ - BACKSLASH_ESCAPE, - { - begin: /\[/, - end: /\]/, - relevance: 0, - contains: [BACKSLASH_ESCAPE] - } - ] - }] + scope: "regexp", + begin: /\/(?=[^/\n]*\/)/, + end: /\/[gimuy]*/, + contains: [ + BACKSLASH_ESCAPE, + { + begin: /\[/, + end: /\]/, + relevance: 0, + contains: [BACKSLASH_ESCAPE] + } + ] }; export const TITLE_MODE = { scope: 'title', diff --git a/test/markup/swift/regex.expect.txt b/test/markup/swift/regex.expect.txt new file mode 100644 index 0000000000..1c14db3699 --- /dev/null +++ b/test/markup/swift/regex.expect.txt @@ -0,0 +1,103 @@ +/escape\/slash/ +/escape \/ slash \/ / +/hello/ +/hello world/ +/\w+\s+(\d+)\s+\w+/ +/(.+?): (.+)/ +/(?<identifier>[[:alpha:]]\w*) = (?<hex>[0-9A-F]+)/ +let p = /hello/ +let n = /hello/ + /world/ - /nice/ +let q = /hello/ / 2 +(/hello/) +method(value: /hello/) +method(/hello/, world) +method(/hello/, /world/) +foo(/a, b/) // Will become regex literal '/a, b/' +qux(/, !/) // Will become regex literal '/, !/' +qux(/,/) // Will become regex literal '/,/' +let g = hasSubscript[/]/2 // Will become regex literal '/]/' +let h = /0; let f = 1/ // Will become the regex literal '/0; let y = 1/' +let i = /^x/ // Will become the regex literal '/^x/' + +// extended literals +#/raw\/slashes/# +#/raw \/ slashes \/ /# +#/hello/# +#/he/llo/# +##/hello/## +##/he/llo/## +###/hello/### +###/he/llo/### +####/hello/#### +####/he/llo/#### +#/hello world/# +#/\w+\s+(\d+)\s+\w+/# +#/(.+?): (.+)/# +let p = #/hello/# +let n = #/hello/# + /world/ - #/nice/# +let q = #/hello/# / 2 +(#/hello/#) +method(value: #/hello/#) +method(#/hello/#, world) +method(#/hello/#, #/world/#) +#/regex with #not a comment/# + +// multiline extended literals +let regex = #/ + # Match a line of the format e.g "DEBIT 03/03/2022 Totally Legit Shell Corp $2,000,000.00" + (?<kind> \w+) \s\s+ + (?<date> \S+) \s\s+ + (?<account> (?: (?!\s\s) . )+) \s\s+ # Note that account names may contain spaces. + (?<amount> .*) +/# +#/ + #regex comment + # regex comment + ## regex comment + this is another extended regex literal + /this is still in the regex/ + 123 + 12 / 2 + (/hello/) + backslash escape literal newline\ + newline explicit\n + nice +/# +##/ + #regex comment + # regex comment + #/ regex comment + multiline +/## +###/ + #regex comment + # regex comment + #/ regex comment + multiline +/### + +// whitespace +2 / 2 / 2 // not a regex +2 / 2 / 2 // not a regex +2 /2/ 2 // is a regex +2 /2 / 2 // is a regex +2 / 2/ 2 // not a regex +2 #/ 2 /# 2 // is a regex +/\ escaped leading whitespace/ // is a regex +x+/y/ // infix operator, not a regex +x + /y/ // is a regex +x+#/y/# // is a regex + +// structural +struct Planet { + var d = /test/ + var e = #/test/# + var n: Any { + /test/ + #/test/# + } +} + +// unterminated +/something +another line +/ \ No newline at end of file diff --git a/test/markup/swift/regex.txt b/test/markup/swift/regex.txt new file mode 100644 index 0000000000..98ec261767 --- /dev/null +++ b/test/markup/swift/regex.txt @@ -0,0 +1,103 @@ +/escape\/slash/ +/escape \/ slash \/ / +/hello/ +/hello world/ +/\w+\s+(\d+)\s+\w+/ +/(.+?): (.+)/ +/(?[[:alpha:]]\w*) = (?[0-9A-F]+)/ +let p = /hello/ +let n = /hello/ + /world/ - /nice/ +let q = /hello/ / 2 +(/hello/) +method(value: /hello/) +method(/hello/, world) +method(/hello/, /world/) +foo(/a, b/) // Will become regex literal '/a, b/' +qux(/, !/) // Will become regex literal '/, !/' +qux(/,/) // Will become regex literal '/,/' +let g = hasSubscript[/]/2 // Will become regex literal '/]/' +let h = /0; let f = 1/ // Will become the regex literal '/0; let y = 1/' +let i = /^x/ // Will become the regex literal '/^x/' + +// extended literals +#/raw\/slashes/# +#/raw \/ slashes \/ /# +#/hello/# +#/he/llo/# +##/hello/## +##/he/llo/## +###/hello/### +###/he/llo/### +####/hello/#### +####/he/llo/#### +#/hello world/# +#/\w+\s+(\d+)\s+\w+/# +#/(.+?): (.+)/# +let p = #/hello/# +let n = #/hello/# + /world/ - #/nice/# +let q = #/hello/# / 2 +(#/hello/#) +method(value: #/hello/#) +method(#/hello/#, world) +method(#/hello/#, #/world/#) +#/regex with #not a comment/# + +// multiline extended literals +let regex = #/ + # Match a line of the format e.g "DEBIT 03/03/2022 Totally Legit Shell Corp $2,000,000.00" + (? \w+) \s\s+ + (? \S+) \s\s+ + (? (?: (?!\s\s) . )+) \s\s+ # Note that account names may contain spaces. + (? .*) +/# +#/ + #regex comment + # regex comment + ## regex comment + this is another extended regex literal + /this is still in the regex/ + 123 + 12 / 2 + (/hello/) + backslash escape literal newline\ + newline explicit\n + nice +/# +##/ + #regex comment + # regex comment + #/ regex comment + multiline +/## +###/ + #regex comment + # regex comment + #/ regex comment + multiline +/### + +// whitespace +2 / 2 / 2 // not a regex +2 / 2 / 2 // not a regex +2 /2/ 2 // is a regex +2 /2 / 2 // is a regex +2 / 2/ 2 // not a regex +2 #/ 2 /# 2 // is a regex +/\ escaped leading whitespace/ // is a regex +x+/y/ // infix operator, not a regex +x + /y/ // is a regex +x+#/y/# // is a regex + +// structural +struct Planet { + var d = /test/ + var e = #/test/# + var n: Any { + /test/ + #/test/# + } +} + +// unterminated +/something +another line +/ \ No newline at end of file diff --git a/test/markup/swift/tuples.expect.txt b/test/markup/swift/tuples.expect.txt index 6b259a3343..6f51c24c72 100644 --- a/test/markup/swift/tuples.expect.txt +++ b/test/markup/swift/tuples.expect.txt @@ -14,3 +14,4 @@ ) (let x, var y) ([key: value, key: value]) +(/my regex/) \ No newline at end of file diff --git a/test/markup/swift/tuples.txt b/test/markup/swift/tuples.txt index c66e4bd33a..6179cd7dad 100644 --- a/test/markup/swift/tuples.txt +++ b/test/markup/swift/tuples.txt @@ -14,3 +14,4 @@ ) (let x, var y) ([key: value, key: value]) +(/my regex/) From fcefad4a6bf99b88c54b2b724ca77466e94c374d Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Fri, 16 Jun 2023 01:00:31 +0100 Subject: [PATCH 05/12] enh(swift) `@unchecked` and `@Sendable` support (#3808) * @Sendable is a keyword attribute * Add @unchecked for Sendable conformance * Use scope spelling for attribute rules * @unchecked is not actually contextual * Revert unneeded changes * Update CHANGES.md --- CHANGES.md | 1 + src/languages/lib/kws_swift.js | 2 ++ src/languages/swift.js | 6 +++--- test/markup/swift/attributes.expect.txt | 2 ++ test/markup/swift/attributes.txt | 2 ++ 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e041ccf3da..dfd6c57d9b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ Core Grammars: - enh(swift) support `macro` keyword [Bradley Mackey][] - enh(swift) support parameter pack keywords [Bradley Mackey][] - enh(swift) regex literal support [Bradley Mackey][] +- enh(swift) `@unchecked` and `@Sendable` support [Bradley Mackey][] Dev tool: diff --git a/src/languages/lib/kws_swift.js b/src/languages/lib/kws_swift.js index d7944f49af..65a13c9e60 100644 --- a/src/languages/lib/kws_swift.js +++ b/src/languages/lib/kws_swift.js @@ -305,8 +305,10 @@ export const keywordAttributes = [ 'propertyWrapper', 'requires_stored_property_inits', 'resultBuilder', + 'Sendable', 'testable', 'UIApplicationMain', + 'unchecked', 'unknown', 'usableFromInline' ]; diff --git a/src/languages/swift.js b/src/languages/swift.js index 7913eda645..d68503ea6c 100644 --- a/src/languages/swift.js +++ b/src/languages/swift.js @@ -243,7 +243,7 @@ export default function(hljs) { // https://docs.swift.org/swift-book/ReferenceManual/Attributes.html const AVAILABLE_ATTRIBUTE = { match: /(@|#(un)?)available/, - className: "keyword", + scope: 'keyword', starts: { contains: [ { begin: /\(/, @@ -258,11 +258,11 @@ export default function(hljs) { ] } }; const KEYWORD_ATTRIBUTE = { - className: 'keyword', + scope: 'keyword', match: concat(/@/, either(...Swift.keywordAttributes)) }; const USER_DEFINED_ATTRIBUTE = { - className: 'meta', + scope: 'meta', match: concat(/@/, Swift.identifier) }; const ATTRIBUTES = [ diff --git a/test/markup/swift/attributes.expect.txt b/test/markup/swift/attributes.expect.txt index 22d4e60978..8f0811f603 100644 --- a/test/markup/swift/attributes.expect.txt +++ b/test/markup/swift/attributes.expect.txt @@ -5,5 +5,7 @@ @propertyWrapper @SomeWrapper(value: 1.0, other: "string", bool: false) @resultBuilder +@Sendable +@unchecked @ notAnAttribute diff --git a/test/markup/swift/attributes.txt b/test/markup/swift/attributes.txt index 8628043613..37bffdffb6 100644 --- a/test/markup/swift/attributes.txt +++ b/test/markup/swift/attributes.txt @@ -5,5 +5,7 @@ @propertyWrapper @SomeWrapper(value: 1.0, other: "string", bool: false) @resultBuilder +@Sendable +@unchecked @ notAnAttribute From 9467c5c6af61b73b5035686fd1ed0c2c1fbfdb9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gr=C3=BCn?= Date: Wed, 28 Jun 2023 08:34:57 +0200 Subject: [PATCH 06/12] XQuery: common .xqm suffix added (#3811) --- SUPPORTED_LANGUAGES.md | 2 +- src/languages/xquery.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index 48d6c8796b..6eda4cf286 100644 --- a/SUPPORTED_LANGUAGES.md +++ b/SUPPORTED_LANGUAGES.md @@ -237,7 +237,7 @@ The table below shows the full list of languages (and corresponding classes/alia | X++ | axapta, x++ | | | x86 Assembly | x86asm | | | XL | xl, tao | | -| XQuery | xquery, xpath, xq | | +| XQuery | xquery, xpath, xq, xqm | | | YAML | yml, yaml | | | ZenScript | zenscript, zs |[highlightjs-zenscript](https://github.com/highlightjs/highlightjs-zenscript) | | Zephir | zephir, zep | | diff --git a/src/languages/xquery.js b/src/languages/xquery.js index f05ea6784f..f854837f15 100644 --- a/src/languages/xquery.js +++ b/src/languages/xquery.js @@ -348,7 +348,8 @@ export default function(_hljs) { name: 'XQuery', aliases: [ 'xpath', - 'xq' + 'xq', + 'xqm' ], case_insensitive: false, illegal: /(proc)|(abstract)|(extends)|(until)|(#)/, From 700626f10a6acb4f4eb6bdcbe3bf618d4b8e0fa7 Mon Sep 17 00:00:00 2001 From: "Jan T. Sott" Date: Mon, 3 Jul 2023 02:09:57 +0200 Subject: [PATCH 07/12] enh(nsis) Add !assert compiler flag (#3813) --- CHANGES.md | 1 + src/languages/nsis.js | 1 + test/markup/nsis/default.expect.txt | 2 ++ test/markup/nsis/default.txt | 2 ++ 4 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index dfd6c57d9b..52f7c7056e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ Core Grammars: - enh(swift) support parameter pack keywords [Bradley Mackey][] - enh(swift) regex literal support [Bradley Mackey][] - enh(swift) `@unchecked` and `@Sendable` support [Bradley Mackey][] +- enh(nsis) Add `!assert` compiler flag [idleberg][] Dev tool: diff --git a/src/languages/nsis.js b/src/languages/nsis.js index cf2eaca0e7..19021043dd 100644 --- a/src/languages/nsis.js +++ b/src/languages/nsis.js @@ -114,6 +114,7 @@ export default function(hljs) { "addincludedir", "addplugindir", "appendfile", + "assert", "cd", "define", "delfile", diff --git a/test/markup/nsis/default.expect.txt b/test/markup/nsis/default.expect.txt index 24c8e434a1..a67e76f04c 100644 --- a/test/markup/nsis/default.expect.txt +++ b/test/markup/nsis/default.expect.txt @@ -3,6 +3,8 @@ for highlight.js */ +!assert ${NSIS_CHAR_SIZE} = 2 "Unicode required" + ; Includes !include MUI2.nsh diff --git a/test/markup/nsis/default.txt b/test/markup/nsis/default.txt index b6e228cf3d..01655ba227 100644 --- a/test/markup/nsis/default.txt +++ b/test/markup/nsis/default.txt @@ -3,6 +3,8 @@ for highlight.js */ +!assert ${NSIS_CHAR_SIZE} = 2 "Unicode required" + ; Includes !include MUI2.nsh From ab4dff78315359de221fd0696557defdd2f4a97a Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Mon, 3 Jul 2023 01:18:18 +0100 Subject: [PATCH 08/12] (chore) drop support for Node.js 14 (#3814) * Slide build window to 16...20 --- .github/workflows/tests.js.yml | 2 +- CHANGES.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.js.yml b/.github/workflows/tests.js.yml index e83995697c..1eaed1cd8b 100644 --- a/.github/workflows/tests.js.yml +++ b/.github/workflows/tests.js.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: - node-version: [14.x, 16.x, 18.x] + node-version: [16.x, 18.x, 20.x] build-how: ["node", "browser", "browser -n", "cdn :common"] steps: diff --git a/CHANGES.md b/CHANGES.md index 52f7c7056e..10fd17bcc0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ ## Version 11.9.0 (next release) +Supported Node.js versions: + +- (chore) Drops support for Node 14.x, which is no longer supported by Node.js. + Parser: - (enh) prevent rehighlighting of an element [joshgoebel][] From 8eafa32fb26bb1a47645471b60b55b9502e72977 Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Mon, 3 Jul 2023 03:50:48 +0100 Subject: [PATCH 09/12] enh(swift) ownership modifiers support (#3812) * Add consume keyword * Non-copyable highlights as expected * Parameter ownership and copies --- CHANGES.md | 1 + src/languages/lib/kws_swift.js | 4 ++++ test/markup/swift/ownership.expect.txt | 23 +++++++++++++++++++++++ test/markup/swift/ownership.txt | 23 +++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 test/markup/swift/ownership.expect.txt create mode 100644 test/markup/swift/ownership.txt diff --git a/CHANGES.md b/CHANGES.md index 10fd17bcc0..8074916086 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ Core Grammars: - enh(swift) support parameter pack keywords [Bradley Mackey][] - enh(swift) regex literal support [Bradley Mackey][] - enh(swift) `@unchecked` and `@Sendable` support [Bradley Mackey][] +- enh(swift) ownership modifiers support [Bradley Mackey][] - enh(nsis) Add `!assert` compiler flag [idleberg][] Dev tool: diff --git a/src/languages/lib/kws_swift.js b/src/languages/lib/kws_swift.js index 65a13c9e60..9d854bccb5 100644 --- a/src/languages/lib/kws_swift.js +++ b/src/languages/lib/kws_swift.js @@ -40,12 +40,16 @@ export const keywords = [ /as\?/, // operator /as!/, // operator 'as', // operator + 'borrowing', // contextual 'break', 'case', 'catch', 'class', + 'consume', // contextual + 'consuming', // contextual 'continue', 'convenience', // contextual + 'copy', // contextual 'default', 'defer', 'deinit', diff --git a/test/markup/swift/ownership.expect.txt b/test/markup/swift/ownership.expect.txt new file mode 100644 index 0000000000..af5aae9d16 --- /dev/null +++ b/test/markup/swift/ownership.expect.txt @@ -0,0 +1,23 @@ +consume x +_ = consume y +doStuffUniquely(with: consume x) +copy x +_ = copy x +doStuff(with: copy x) + +struct MoveOnly: ~Copyable {} + +struct B: P { + func foo(x: borrowing Foo, y: consuming Foo) +} +func foo(_: borrowing Foo) +func foo(_: consuming Foo) +func foo(_: inout Foo) +let f: (borrowing Foo) -> Void = { a in a.foo() } +let f: (consuming Foo) -> Void = { a in a.foo() } +let f: (inout Foo) -> Void = { a in a.foo() } +struct Foo { + consuming func foo() + borrowing func foo() + mutating func foo() +} \ No newline at end of file diff --git a/test/markup/swift/ownership.txt b/test/markup/swift/ownership.txt new file mode 100644 index 0000000000..7621dd153a --- /dev/null +++ b/test/markup/swift/ownership.txt @@ -0,0 +1,23 @@ +consume x +_ = consume y +doStuffUniquely(with: consume x) +copy x +_ = copy x +doStuff(with: copy x) + +struct MoveOnly: ~Copyable {} + +struct B: P { + func foo(x: borrowing Foo, y: consuming Foo) +} +func foo(_: borrowing Foo) +func foo(_: consuming Foo) +func foo(_: inout Foo) +let f: (borrowing Foo) -> Void = { a in a.foo() } +let f: (consuming Foo) -> Void = { a in a.foo() } +let f: (inout Foo) -> Void = { a in a.foo() } +struct Foo { + consuming func foo() + borrowing func foo() + mutating func foo() +} \ No newline at end of file From be9297ec815963da98e00010a8ed6e35caec2706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Jano=C5=A1=C3=ADk?= <5196749+zlondrej@users.noreply.github.com> Date: Mon, 3 Jul 2023 20:57:18 +0300 Subject: [PATCH 10/12] fix(haskell) Do not treat dashes inside infix operators as comments (#3799) * fix(haskell) do not treat dashes inside infix operators as comments This fixes cases where operators like `$--` or `-->` are treated as comment. * Fix the comments using no-markup rule to avoid negavive lookbehind --- CHANGES.md | 4 +- src/languages/haskell.js | 42 +++++--- .../markup/haskell/inline-comments.expect.txt | 97 +++++++++++++++++++ test/markup/haskell/inline-comments.txt | 97 +++++++++++++++++++ 4 files changed, 225 insertions(+), 15 deletions(-) create mode 100644 test/markup/haskell/inline-comments.expect.txt create mode 100644 test/markup/haskell/inline-comments.txt diff --git a/CHANGES.md b/CHANGES.md index 8074916086..2fa3a6a859 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,8 +21,9 @@ Core Grammars: - enh(swift) `@unchecked` and `@Sendable` support [Bradley Mackey][] - enh(swift) ownership modifiers support [Bradley Mackey][] - enh(nsis) Add `!assert` compiler flag [idleberg][] +- fix(haskell) do not treat double dashes inside infix operators as comments [Zlondrej][] -Dev tool: +Dev tool: - (chore) Update dev tool to use the new `highlight` API. [Shah Shabbir Ahmmed][] - (enh) Auto-update the highlighted output when the language dropdown changes. [Shah Shabbir Ahmmed][] @@ -83,6 +84,7 @@ Core Grammars: [Keyacom]: https://github.com/Keyacom [Boris Verkhovskiy]: https://github.com/verhovsky [Cyrus Kao]: https://github.com/CyrusKao +[Zlondrej]: https://github.com/zlondrej ## Version 11.7.0 diff --git a/src/languages/haskell.js b/src/languages/haskell.js index 13d1ac826a..f9c0cf336b 100644 --- a/src/languages/haskell.js +++ b/src/languages/haskell.js @@ -7,8 +7,32 @@ Category: functional */ export default function(hljs) { + + /* See: + - https://www.haskell.org/onlinereport/lexemes.html + - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/binary_literals.html + - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/numeric_underscores.html + - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/hex_float_literals.html + */ + const decimalDigits = '([0-9]_*)+'; + const hexDigits = '([0-9a-fA-F]_*)+'; + const binaryDigits = '([01]_*)+'; + const octalDigits = '([0-7]_*)+'; + const ascSymbol = '[!#$%&*+.\\/<=>?@\\\\^~-]'; + const uniSymbol = '(\\p{S}|\\p{P})' // Symbol or Punctuation + const special = '[(),;\\[\\]`|{}]'; + const symbol = `(${ascSymbol}|(?!(${special}|[_:"']))${uniSymbol})`; + const COMMENT = { variants: [ - hljs.COMMENT('--', '$'), + // Double dash forms a valid comment only if it's not part of legal lexeme. + // See: Haskell 98 report: https://www.haskell.org/onlinereport/lexemes.html + // + // The commented code does the job, but we can't use negative lookbehind, + // due to poor support by Safari browser. + // > hljs.COMMENT(`(?|<-' } diff --git a/test/markup/haskell/inline-comments.expect.txt b/test/markup/haskell/inline-comments.expect.txt new file mode 100644 index 0000000000..cac1b79c6d --- /dev/null +++ b/test/markup/haskell/inline-comments.expect.txt @@ -0,0 +1,97 @@ + -- These are not comments, as the symbols, together with double dashes, form a legal lexemes. + + -- Using ascii symbols + --! + !--! + !-- + #--- + ---# + #---# + $---- + ----$ + $----$ + %-- + --% + %--% + &--- + ---& + &--& + --* + *-- + *--* + --+ + +-- + +--+ + --. + .-- + .--. + --/ + /-- + /--/ + --< + <-- + <--< + --= + =-- + =--= + --> + >-- + >--> + --? + ?--? + ?-- + --@ + @--@ + @-- + \-- + --\ + \--\ + ^-- + --^ + ^--^ + ~-- + --~ + ~--~ + -- Using unicode symbols + ⅀-- + --¬ + ⅄--± + -- Using unicode punctuation + §-- + --؉ + ܅--๏ + + -- However these are comments as they consist of `special` symbols or `_`, `:`, `"`, `'` + -- or otherwise don't form a legal lexeme together with the dashes. + --undefined + --( + ---) + ----_ + --: + --" + --' + --, + --; + --[ + --] + --` + --| + --{ + --} + undefined-- + (-- + )--- + _---- + :-- + ""-- + ''-- + ,-- + ;-- + [-- + ]-- + `-- + |-- + {-- Well, this one is a block comment, so we have to terminate it -} + }-- + --- + ---- \ No newline at end of file diff --git a/test/markup/haskell/inline-comments.txt b/test/markup/haskell/inline-comments.txt new file mode 100644 index 0000000000..4493da36c7 --- /dev/null +++ b/test/markup/haskell/inline-comments.txt @@ -0,0 +1,97 @@ + -- These are not comments, as the symbols, together with double dashes, form a legal lexemes. + + -- Using ascii symbols + --! + !--! + !-- + #--- + ---# + #---# + $---- + ----$ + $----$ + %-- + --% + %--% + &--- + ---& + &--& + --* + *-- + *--* + --+ + +-- + +--+ + --. + .-- + .--. + --/ + /-- + /--/ + --< + <-- + <--< + --= + =-- + =--= + --> + >-- + >--> + --? + ?--? + ?-- + --@ + @--@ + @-- + \-- + --\ + \--\ + ^-- + --^ + ^--^ + ~-- + --~ + ~--~ + -- Using unicode symbols + ⅀-- + --¬ + ⅄--± + -- Using unicode punctuation + §-- + --؉ + ܅--๏ + + -- However these are comments as they consist of `special` symbols or `_`, `:`, `"`, `'` + -- or otherwise don't form a legal lexeme together with the dashes. + --undefined + --( + ---) + ----_ + --: + --" + --' + --, + --; + --[ + --] + --` + --| + --{ + --} + undefined-- + (-- + )--- + _---- + :-- + ""-- + ''-- + ,-- + ;-- + [-- + ]-- + `-- + |-- + {-- Well, this one is a block comment, so we have to terminate it -} + }-- + --- + ---- \ No newline at end of file From a3e401ec4e47eccc8e2ebc38e8ebfd436affd20e Mon Sep 17 00:00:00 2001 From: qoheniac <29815186+qoheniac@users.noreply.github.com> Date: Sat, 8 Jul 2023 00:58:53 +0200 Subject: [PATCH 11/12] enh(rust): add `eprintln!` macro (#3816) --- CHANGES.md | 2 ++ src/languages/rust.js | 1 + 2 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2fa3a6a859..0d2f0cd5f4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ Core Grammars: - enh(swift) ownership modifiers support [Bradley Mackey][] - enh(nsis) Add `!assert` compiler flag [idleberg][] - fix(haskell) do not treat double dashes inside infix operators as comments [Zlondrej][] +- enh(rust) added `eprintln!` macro [qoheniac][] Dev tool: @@ -33,6 +34,7 @@ Dev tool: [Josh Goebel]: https://github.com/joshgoebel [Checconio]: https://github.com/Checconio [Bradley Mackey]: https://github.com/bradleymackey +[qoheniac]: https://github.com/qoheniac ## Version 11.8.0 diff --git a/src/languages/rust.js b/src/languages/rust.js index 3f43aeb478..54b59a1423 100644 --- a/src/languages/rust.js +++ b/src/languages/rust.js @@ -123,6 +123,7 @@ export default function(hljs) { "debug_assert!", "debug_assert_eq!", "env!", + "eprintln!", "panic!", "file!", "format!", From e5e0220052bcf778fa93efcd007d47fb1dffab6b Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Sat, 8 Jul 2023 01:02:09 +0200 Subject: [PATCH 12/12] enh(scala) - add `using` directive support (#3810) --- CHANGES.md | 1 + src/languages/scala.js | 29 +++++++++++++++++++ test/markup/scala/using-directives.expect.txt | 4 +++ test/markup/scala/using-directives.txt | 4 +++ 4 files changed, 38 insertions(+) create mode 100644 test/markup/scala/using-directives.expect.txt create mode 100644 test/markup/scala/using-directives.txt diff --git a/CHANGES.md b/CHANGES.md index 0d2f0cd5f4..e7d5c718c8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ Core Grammars: - enh(swift) support parameter pack keywords [Bradley Mackey][] - enh(swift) regex literal support [Bradley Mackey][] - enh(swift) `@unchecked` and `@Sendable` support [Bradley Mackey][] +- enh(scala) add using directives support `//> using foo bar` [Jamie Thompson][] - enh(swift) ownership modifiers support [Bradley Mackey][] - enh(nsis) Add `!assert` compiler flag [idleberg][] - fix(haskell) do not treat double dashes inside infix operators as comments [Zlondrej][] diff --git a/src/languages/scala.js b/src/languages/scala.js index 41d64e6d9c..3dac04e9a2 100644 --- a/src/languages/scala.js +++ b/src/languages/scala.js @@ -151,6 +151,34 @@ export default function(hljs) { beginScope: { 2: "keyword", } }; + // glob all non-whitespace characters as a "string" + // sourced from https://github.com/scala/docs.scala-lang/pull/2845 + const DIRECTIVE_VALUE = { + className: 'string', + begin: /\S+/, + } + + // directives + // sourced from https://github.com/scala/docs.scala-lang/pull/2845 + const USING_DIRECTIVE = { + begin: [ + '//>', + /\s+/, + /using/, + /\s+/, + /\S+/ + ], + beginScope: { + 1: "comment", + 3: "keyword", + 5: "type" + }, + end: /$/, + contains: [ + DIRECTIVE_VALUE, + ] + } + return { name: 'Scala', keywords: { @@ -158,6 +186,7 @@ export default function(hljs) { keyword: 'type yield lazy override def with val var sealed abstract private trait object if then forSome for while do throw finally protected extends import final return else break new catch super class case package default try this match continue throws implicit export enum given transparent' }, contains: [ + USING_DIRECTIVE, hljs.C_LINE_COMMENT_MODE, hljs.C_BLOCK_COMMENT_MODE, STRING, diff --git a/test/markup/scala/using-directives.expect.txt b/test/markup/scala/using-directives.expect.txt new file mode 100644 index 0000000000..4b065e8592 --- /dev/null +++ b/test/markup/scala/using-directives.expect.txt @@ -0,0 +1,4 @@ +//> using scala 3.3.0 +//> using options -source:future -Xfatal-warnings +//> using test.resourceDir ./resources +// using foo bar <-- this should not be highlighted diff --git a/test/markup/scala/using-directives.txt b/test/markup/scala/using-directives.txt new file mode 100644 index 0000000000..335d348b57 --- /dev/null +++ b/test/markup/scala/using-directives.txt @@ -0,0 +1,4 @@ +//> using scala 3.3.0 +//> using options -source:future -Xfatal-warnings +//> using test.resourceDir ./resources +// using foo bar <-- this should not be highlighted