From c515530eedea70d470be74be39e0cbc3ea054ff4 Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Tue, 28 Jul 2020 12:53:23 +0300 Subject: [PATCH 1/6] Kotlin: add failing tests for backticks --- tests/languages/kotlin/function_feature.test | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/languages/kotlin/function_feature.test b/tests/languages/kotlin/function_feature.test index 8bfd2b2261..0966ad4d89 100644 --- a/tests/languages/kotlin/function_feature.test +++ b/tests/languages/kotlin/function_feature.test @@ -1,6 +1,9 @@ foo() foo_Bar_42() list.filter {} +`function 1`() +` !"#$%^&()*+,=?@{|}~-_`() +list.`take 1` {} ---------------------------------------------------- @@ -8,7 +11,11 @@ list.filter {} ["function", "foo"], ["punctuation", "("], ["punctuation", ")"], ["function", "foo_Bar_42"], ["punctuation", "("], ["punctuation", ")"], "\r\nlist", ["punctuation", "."], - ["function", "filter"], ["punctuation", "{"], ["punctuation", "}"] + ["function", "filter"], ["punctuation", "{"], ["punctuation", "}"], + ["function", "`function 1`"], ["punctuation", "("], ["punctuation", ")"], + ["function", "` !\"#$%^&()*+,=?@{|}~-_`"], ["punctuation", "("], ["punctuation", ")"], + "\r\nlist", ["punctuation", "."], + ["function", "`take 1`"], ["punctuation", "{"], ["punctuation", "}"] ] ---------------------------------------------------- From e623acb02b3269472a59a173e3df11fe4a8bf0af Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Tue, 28 Jul 2020 13:55:16 +0300 Subject: [PATCH 2/6] Kotlin: add backticks support --- components/prism-kotlin.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/prism-kotlin.js b/components/prism-kotlin.js index ae1a864e7d..1405ade6ce 100644 --- a/components/prism-kotlin.js +++ b/components/prism-kotlin.js @@ -1,4 +1,7 @@ (function (Prism) { + + var functionName = /(?:`[\w !"#$%^&()*+,=?@{|}~\-]+`|\w+)/.source; + Prism.languages.kotlin = Prism.languages.extend('clike', { 'keyword': { // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get @@ -6,9 +9,9 @@ lookbehind: true }, 'function': [ - /\w+(?=\s*\()/, + RegExp(/(?=\s*\()/.source.replace('', functionName)), { - pattern: /(\.)\w+(?=\s*\{)/, + pattern: RegExp(/(\.)(?=\s*\{)/.source.replace('', functionName)), lookbehind: true } ], From 13f881465cb65b37a7644ee0d81b136e072e3123 Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Tue, 28 Jul 2020 14:03:52 +0300 Subject: [PATCH 3/6] Kotlin: make function greedy --- components/prism-kotlin.js | 8 ++++++-- tests/languages/kotlin/function_feature.test | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/components/prism-kotlin.js b/components/prism-kotlin.js index 1405ade6ce..6b1813c19c 100644 --- a/components/prism-kotlin.js +++ b/components/prism-kotlin.js @@ -9,10 +9,14 @@ lookbehind: true }, 'function': [ - RegExp(/(?=\s*\()/.source.replace('', functionName)), + { + pattern: RegExp(/(?=\s*\()/.source.replace('', functionName)), + greedy: true + }, { pattern: RegExp(/(\.)(?=\s*\{)/.source.replace('', functionName)), - lookbehind: true + lookbehind: true, + greedy: true } ], 'number': /\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/, diff --git a/tests/languages/kotlin/function_feature.test b/tests/languages/kotlin/function_feature.test index 0966ad4d89..29222ecf0c 100644 --- a/tests/languages/kotlin/function_feature.test +++ b/tests/languages/kotlin/function_feature.test @@ -4,6 +4,7 @@ list.filter {} `function 1`() ` !"#$%^&()*+,=?@{|}~-_`() list.`take 1` {} +`make fun`() ---------------------------------------------------- @@ -15,7 +16,8 @@ list.`take 1` {} ["function", "`function 1`"], ["punctuation", "("], ["punctuation", ")"], ["function", "` !\"#$%^&()*+,=?@{|}~-_`"], ["punctuation", "("], ["punctuation", ")"], "\r\nlist", ["punctuation", "."], - ["function", "`take 1`"], ["punctuation", "{"], ["punctuation", "}"] + ["function", "`take 1`"], ["punctuation", "{"], ["punctuation", "}"], + ["function", "`make fun`"], ["punctuation", "("], ["punctuation", ")"] ] ---------------------------------------------------- From 9eedae76391186fdaa616d4de52c6997bde8bcac Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Tue, 28 Jul 2020 14:05:41 +0300 Subject: [PATCH 4/6] Kotlin: rebuild --- components/prism-kotlin.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/prism-kotlin.min.js b/components/prism-kotlin.min.js index 45b197e7a0..c8675ac0f8 100644 --- a/components/prism-kotlin.min.js +++ b/components/prism-kotlin.min.js @@ -1 +1 @@ -!function(n){n.languages.kotlin=n.languages.extend("clike",{keyword:{pattern:/(^|[^.])\b(?:abstract|actual|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|dynamic|else|enum|expect|external|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|operator|out|override|package|private|protected|public|reified|return|sealed|set|super|suspend|tailrec|this|throw|to|try|typealias|val|var|vararg|when|where|while)\b/,lookbehind:!0},function:[/\w+(?=\s*\()/,{pattern:/(\.)\w+(?=\s*\{)/,lookbehind:!0}],number:/\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,operator:/\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/}),delete n.languages.kotlin["class-name"],n.languages.insertBefore("kotlin","string",{"raw-string":{pattern:/("""|''')[\s\S]*?\1/,alias:"string"}}),n.languages.insertBefore("kotlin","keyword",{annotation:{pattern:/\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,alias:"builtin"}}),n.languages.insertBefore("kotlin","function",{label:{pattern:/\w+@|@\w+/,alias:"symbol"}});var e=[{pattern:/\$\{[^}]+\}/,inside:{delimiter:{pattern:/^\$\{|\}$/,alias:"variable"},rest:n.languages.kotlin}},{pattern:/\$\w+/,alias:"variable"}];n.languages.kotlin.string.inside=n.languages.kotlin["raw-string"].inside={interpolation:e},n.languages.kt=n.languages.kotlin,n.languages.kts=n.languages.kotlin}(Prism); \ No newline at end of file +!function(e){var n='(?:`[\\w !"#$%^&()*+,=?@{|}~\\-]+`|\\w+)';e.languages.kotlin=e.languages.extend("clike",{keyword:{pattern:/(^|[^.])\b(?:abstract|actual|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|dynamic|else|enum|expect|external|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|operator|out|override|package|private|protected|public|reified|return|sealed|set|super|suspend|tailrec|this|throw|to|try|typealias|val|var|vararg|when|where|while)\b/,lookbehind:!0},function:[{pattern:RegExp("(?=\\s*\\()".replace("",n)),greedy:!0},{pattern:RegExp("(\\.)(?=\\s*\\{)".replace("",n)),lookbehind:!0,greedy:!0}],number:/\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,operator:/\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/}),delete e.languages.kotlin["class-name"],e.languages.insertBefore("kotlin","string",{"raw-string":{pattern:/("""|''')[\s\S]*?\1/,alias:"string"}}),e.languages.insertBefore("kotlin","keyword",{annotation:{pattern:/\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,alias:"builtin"}}),e.languages.insertBefore("kotlin","function",{label:{pattern:/\w+@|@\w+/,alias:"symbol"}});var a=[{pattern:/\$\{[^}]+\}/,inside:{delimiter:{pattern:/^\$\{|\}$/,alias:"variable"},rest:e.languages.kotlin}},{pattern:/\$\w+/,alias:"variable"}];e.languages.kotlin.string.inside=e.languages.kotlin["raw-string"].inside={interpolation:a},e.languages.kt=e.languages.kotlin,e.languages.kts=e.languages.kotlin}(Prism); \ No newline at end of file From d92ddb97cfcb76f6264b2d47c3ecce666105b2c7 Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Sun, 15 Nov 2020 17:57:56 +0300 Subject: [PATCH 5/6] Kotlin: simplify backticks pattern --- components/prism-kotlin.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/components/prism-kotlin.js b/components/prism-kotlin.js index 6b1813c19c..3ade990144 100644 --- a/components/prism-kotlin.js +++ b/components/prism-kotlin.js @@ -1,7 +1,4 @@ (function (Prism) { - - var functionName = /(?:`[\w !"#$%^&()*+,=?@{|}~\-]+`|\w+)/.source; - Prism.languages.kotlin = Prism.languages.extend('clike', { 'keyword': { // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get @@ -10,11 +7,11 @@ }, 'function': [ { - pattern: RegExp(/(?=\s*\()/.source.replace('', functionName)), + pattern: /(?:`[^\r\n`]+`|\w+)(?=\s*\()/, greedy: true }, { - pattern: RegExp(/(\.)(?=\s*\{)/.source.replace('', functionName)), + pattern: /(\.)(?:`[^\r\n`]+`|\w+)(?=\s*\{)/, lookbehind: true, greedy: true } From d62cfc046c49ed1d99b39418d718820ce3dd7ea8 Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Sun, 15 Nov 2020 18:00:48 +0300 Subject: [PATCH 6/6] Kotlin: build --- components/prism-kotlin.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/prism-kotlin.min.js b/components/prism-kotlin.min.js index c8675ac0f8..c6e788a3b2 100644 --- a/components/prism-kotlin.min.js +++ b/components/prism-kotlin.min.js @@ -1 +1 @@ -!function(e){var n='(?:`[\\w !"#$%^&()*+,=?@{|}~\\-]+`|\\w+)';e.languages.kotlin=e.languages.extend("clike",{keyword:{pattern:/(^|[^.])\b(?:abstract|actual|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|dynamic|else|enum|expect|external|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|operator|out|override|package|private|protected|public|reified|return|sealed|set|super|suspend|tailrec|this|throw|to|try|typealias|val|var|vararg|when|where|while)\b/,lookbehind:!0},function:[{pattern:RegExp("(?=\\s*\\()".replace("",n)),greedy:!0},{pattern:RegExp("(\\.)(?=\\s*\\{)".replace("",n)),lookbehind:!0,greedy:!0}],number:/\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,operator:/\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/}),delete e.languages.kotlin["class-name"],e.languages.insertBefore("kotlin","string",{"raw-string":{pattern:/("""|''')[\s\S]*?\1/,alias:"string"}}),e.languages.insertBefore("kotlin","keyword",{annotation:{pattern:/\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,alias:"builtin"}}),e.languages.insertBefore("kotlin","function",{label:{pattern:/\w+@|@\w+/,alias:"symbol"}});var a=[{pattern:/\$\{[^}]+\}/,inside:{delimiter:{pattern:/^\$\{|\}$/,alias:"variable"},rest:e.languages.kotlin}},{pattern:/\$\w+/,alias:"variable"}];e.languages.kotlin.string.inside=e.languages.kotlin["raw-string"].inside={interpolation:a},e.languages.kt=e.languages.kotlin,e.languages.kts=e.languages.kotlin}(Prism); \ No newline at end of file +!function(e){e.languages.kotlin=e.languages.extend("clike",{keyword:{pattern:/(^|[^.])\b(?:abstract|actual|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|dynamic|else|enum|expect|external|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|operator|out|override|package|private|protected|public|reified|return|sealed|set|super|suspend|tailrec|this|throw|to|try|typealias|val|var|vararg|when|where|while)\b/,lookbehind:!0},function:[{pattern:/(?:`[^\r\n`]+`|\w+)(?=\s*\()/,greedy:!0},{pattern:/(\.)(?:`[^\r\n`]+`|\w+)(?=\s*\{)/,lookbehind:!0,greedy:!0}],number:/\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,operator:/\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/}),delete e.languages.kotlin["class-name"],e.languages.insertBefore("kotlin","string",{"raw-string":{pattern:/("""|''')[\s\S]*?\1/,alias:"string"}}),e.languages.insertBefore("kotlin","keyword",{annotation:{pattern:/\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,alias:"builtin"}}),e.languages.insertBefore("kotlin","function",{label:{pattern:/\w+@|@\w+/,alias:"symbol"}});var n=[{pattern:/\$\{[^}]+\}/,inside:{delimiter:{pattern:/^\$\{|\}$/,alias:"variable"},rest:e.languages.kotlin}},{pattern:/\$\w+/,alias:"variable"}];e.languages.kotlin.string.inside=e.languages.kotlin["raw-string"].inside={interpolation:n},e.languages.kt=e.languages.kotlin,e.languages.kts=e.languages.kotlin}(Prism); \ No newline at end of file