From 62e184bba6485c228777cd8e5017925428eba78f Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Thu, 9 Apr 2020 12:50:20 +0200 Subject: [PATCH] Java: Fixed `namespace` token (#2295) --- components/prism-java.js | 4 +- components/prism-java.min.js | 2 +- tests/languages/java/module_feature.test | 269 ++++++++++----------- tests/languages/java/package_feature.test | 47 +++- tests/languages/scala/keyword_feature.test | 4 +- 5 files changed, 167 insertions(+), 159 deletions(-) diff --git a/components/prism-java.js b/components/prism-java.js index 545239539f..498b7a32f2 100644 --- a/components/prism-java.js +++ b/components/prism-java.js @@ -44,7 +44,9 @@ lookbehind: true }, 'namespace': { - pattern: /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)[a-z]\w*(?:\.[a-z]\w*)+/, + pattern: RegExp( + /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!)[a-z]\w*(?:\.[a-z]\w*)*\.?/ + .source.replace(//g, function () { return keywords.source; })), lookbehind: true, inside: { 'punctuation': /\./, diff --git a/components/prism-java.min.js b/components/prism-java.min.js index 079c8d4e7d..818fd8ec78 100644 --- a/components/prism-java.min.js +++ b/components/prism-java.min.js @@ -1 +1 @@ -!function(e){var t=/\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|null|open|opens|package|private|protected|provides|public|record|requires|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/,a=/\b[A-Z](?:\w*[a-z]\w*)?\b/;e.languages.java=e.languages.extend("clike",{"class-name":[a,/\b[A-Z]\w*(?=\s+\w+\s*[;,=())])/],keyword:t,function:[e.languages.clike.function,{pattern:/(\:\:)[a-z_]\w*/,lookbehind:!0}],number:/\b0b[01][01_]*L?\b|\b0x[\da-f_]*\.?[\da-f_p+-]+\b|(?:\b\d[\d_]*\.?[\d_]*|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,operator:{pattern:/(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,lookbehind:!0}}),e.languages.insertBefore("java","string",{"triple-quoted-string":{pattern:/"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,greedy:!0,alias:"string"}}),e.languages.insertBefore("java","class-name",{annotation:{alias:"punctuation",pattern:/(^|[^.])@\w+/,lookbehind:!0},namespace:{pattern:/(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)[a-z]\w*(?:\.[a-z]\w*)+/,lookbehind:!0,inside:{punctuation:/\./}},generics:{pattern:/<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,inside:{"class-name":a,keyword:t,punctuation:/[<>(),.:]/,operator:/[?&|]/}}})}(Prism); \ No newline at end of file +!function(e){var t=/\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|null|open|opens|package|private|protected|provides|public|record|requires|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/,a=/\b[A-Z](?:\w*[a-z]\w*)?\b/;e.languages.java=e.languages.extend("clike",{"class-name":[a,/\b[A-Z]\w*(?=\s+\w+\s*[;,=())])/],keyword:t,function:[e.languages.clike.function,{pattern:/(\:\:)[a-z_]\w*/,lookbehind:!0}],number:/\b0b[01][01_]*L?\b|\b0x[\da-f_]*\.?[\da-f_p+-]+\b|(?:\b\d[\d_]*\.?[\d_]*|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,operator:{pattern:/(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,lookbehind:!0}}),e.languages.insertBefore("java","string",{"triple-quoted-string":{pattern:/"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,greedy:!0,alias:"string"}}),e.languages.insertBefore("java","class-name",{annotation:{alias:"punctuation",pattern:/(^|[^.])@\w+/,lookbehind:!0},namespace:{pattern:RegExp("(\\b(?:exports|import(?:\\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\\s+)(?!)[a-z]\\w*(?:\\.[a-z]\\w*)*\\.?".replace(//g,function(){return t.source})),lookbehind:!0,inside:{punctuation:/\./}},generics:{pattern:/<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,inside:{"class-name":a,keyword:t,punctuation:/[<>(),.:]/,operator:/[?&|]/}}})}(Prism); \ No newline at end of file diff --git a/tests/languages/java/module_feature.test b/tests/languages/java/module_feature.test index 983f8ececb..e7db3d8072 100644 --- a/tests/languages/java/module_feature.test +++ b/tests/languages/java/module_feature.test @@ -1,156 +1,135 @@ module com.js.prism { - exports java.net.http; - exports jdk.internal.editor.spi to jdk.jshell; + exports java.net.http; + exports jdk.internal.editor.spi to jdk.jshell; - requires java.base; - requires transitive java.xml; + requires java.base; + requires transitive java.xml; - uses java.net.ContentHandlerFactory; + uses java.net.ContentHandlerFactory; - opens java.time.DateTime; - opens java.time.LocalDateTime to java.logging; - - provides com.modules.hello.HelloInterface with com.modules.hello.HelloModules; + opens java.time.DateTime; + opens java.time.LocalDateTime to java.logging; + provides com.modules.hello.HelloInterface with com.modules.hello.HelloModules; } - ---------------------------------------------------- - [ - ["keyword", "module"], - ["namespace", - ["com", - ["punctuation", "."], - "js", - ["punctuation", "."], - "prism" - ] - ], - ["punctuation", "{"], - - ["keyword", "exports"], - ["namespace", - [ - "java", - ["punctuation", "."], - "net", - ["punctuation", "."], - "http" - ] - ], - ["punctuation", ";"], - - ["keyword", "exports"], - ["namespace", - [ - "jdk", - ["punctuation", "."], - "internal", - ["punctuation", "."], - "editor", - ["punctuation", "."], - "spi" - ] - ], - ["keyword", "to"], - ["namespace", - [ - "jdk", - ["punctuation", "."], - "jshell" - ] - ], - ["punctuation", ";"], - - ["keyword", "requires"], - ["namespace", - [ - "java", - ["punctuation", "."], - "base" - ] - ], - ["punctuation", ";"], - - ["keyword", "requires"], - ["keyword", "transitive"], - ["namespace", - [ - "java", - ["punctuation", "."], - "xml" - ] - ], - ["punctuation", ";"], - - ["keyword", "uses"], - ["namespace", - [ - "java", - ["punctuation", "."], - "net" - ] - ], - ["punctuation", "."], - ["class-name", "ContentHandlerFactory"], - ["punctuation", ";"], - - ["keyword", "opens"], - ["namespace", - [ - "java", - ["punctuation", "."], - "time" - ] - ], - ["punctuation", "."], - ["class-name", "DateTime"], - ["punctuation", ";"], - ["keyword", "opens"], - ["namespace", - [ - "java", - ["punctuation", "."], - "time" - ] - ], - ["punctuation", "."], - ["class-name", "LocalDateTime"], - ["keyword", "to"], - ["namespace", - [ - "java", - ["punctuation", "."], - "logging" - ] - ], - ["punctuation", ";"], - ["keyword", "provides"], - ["namespace", - [ - "com", - ["punctuation", "."], - "modules", - ["punctuation", "."], - "hello" - ] - ], - ["punctuation", "."], - ["class-name", "HelloInterface"], - ["keyword", "with"], - ["namespace", - [ - "com", - ["punctuation", "."], - "modules", - ["punctuation", "."], - "hello" - ] - ], - ["punctuation", "."], - ["class-name", "HelloModules"], - ["punctuation", ";"], - ["punctuation", "}"] + +[ + ["keyword", "module"], + ["namespace", [ + "com", + ["punctuation", "."], + "js", + ["punctuation", "."], + "prism" + ]], + ["punctuation", "{"], + + ["keyword", "exports"], + ["namespace", [ + "java", + ["punctuation", "."], + "net", + ["punctuation", "."], + "http" + ]], + ["punctuation", ";"], + + ["keyword", "exports"], + ["namespace", [ + "jdk", + ["punctuation", "."], + "internal", + ["punctuation", "."], + "editor", + ["punctuation", "."], + "spi" + ]], + ["keyword", "to"], + ["namespace", [ + "jdk", + ["punctuation", "."], + "jshell" + ]], + ["punctuation", ";"], + + ["keyword", "requires"], + ["namespace", [ + "java", + ["punctuation", "."], + "base" + ]], + ["punctuation", ";"], + + ["keyword", "requires"], + ["keyword", "transitive"], + ["namespace", [ + "java", + ["punctuation", "."], + "xml" + ]], + ["punctuation", ";"], + + ["keyword", "uses"], + ["namespace", [ + "java", + ["punctuation", "."], + "net", + ["punctuation", "."] + ]], + ["class-name", "ContentHandlerFactory"], + ["punctuation", ";"], + + ["keyword", "opens"], + ["namespace", [ + "java", + ["punctuation", "."], + "time", + ["punctuation", "."] + ]], + ["class-name", "DateTime"], + ["punctuation", ";"], + + ["keyword", "opens"], + ["namespace", [ + "java", + ["punctuation", "."], + "time", + ["punctuation", "."] + ]], + ["class-name", "LocalDateTime"], + ["keyword", "to"], + ["namespace", [ + "java", + ["punctuation", "."], + "logging" + ]], + ["punctuation", ";"], + + ["keyword", "provides"], + ["namespace", [ + "com", + ["punctuation", "."], + "modules", + ["punctuation", "."], + "hello", + ["punctuation", "."] + ]], + ["class-name", "HelloInterface"], + ["keyword", "with"], + ["namespace", [ + "com", + ["punctuation", "."], + "modules", + ["punctuation", "."], + "hello", + ["punctuation", "."] + ]], + ["class-name", "HelloModules"], + ["punctuation", ";"], + + ["punctuation", "}"] ] ---------------------------------------------------- diff --git a/tests/languages/java/package_feature.test b/tests/languages/java/package_feature.test index 9fe6f1f353..3dcf209474 100644 --- a/tests/languages/java/package_feature.test +++ b/tests/languages/java/package_feature.test @@ -1,8 +1,11 @@ +package java; package java.lang; +import foo.Bar; import java.lang.Math; import java.lang.*; +import static foo.Bar.BAZ; import static java.lang.Math.PI; import static java.lang.Math.sin; import static java.lang.Math.*; @@ -10,6 +13,11 @@ import static java.lang.Math.*; ---------------------------------------------------- [ + ["keyword", "package"], + ["namespace", [ + "java" + ]], + ["punctuation", ";"], ["keyword", "package"], ["namespace", [ "java", @@ -18,13 +26,20 @@ import static java.lang.Math.*; ]], ["punctuation", ";"], + ["keyword", "import"], + ["namespace", [ + "foo", + ["punctuation", "."] + ]], + ["class-name", "Bar"], + ["punctuation", ";"], ["keyword", "import"], ["namespace", [ "java", ["punctuation", "."], - "lang" + "lang", + ["punctuation", "."] ]], - ["punctuation", "."], ["class-name", "Math"], ["punctuation", ";"], @@ -32,10 +47,20 @@ import static java.lang.Math.*; ["namespace", [ "java", ["punctuation", "."], - "lang" + "lang", + ["punctuation", "."] ]], + ["operator", "*"], + ["punctuation", ";"], + ["keyword", "import"], + ["keyword", "static"], + ["namespace", [ + "foo", + ["punctuation", "."] + ]], + ["class-name", "Bar"], ["punctuation", "."], - "*", + "BAZ", ["punctuation", ";"], ["keyword", "import"], @@ -43,9 +68,9 @@ import static java.lang.Math.*; ["namespace", [ "java", ["punctuation", "."], - "lang" + "lang", + ["punctuation", "."] ]], - ["punctuation", "."], ["class-name", "Math"], ["punctuation", "."], "PI", @@ -56,9 +81,9 @@ import static java.lang.Math.*; ["namespace", [ "java", ["punctuation", "."], - "lang" + "lang", + ["punctuation", "."] ]], - ["punctuation", "."], ["class-name", "Math"], ["punctuation", "."], "sin", @@ -67,8 +92,10 @@ import static java.lang.Math.*; ["keyword", "static"], ["namespace", [ "java", - ["punctuation", "."], "lang" - ]], ["punctuation", "."], + ["punctuation", "."], + "lang", + ["punctuation", "."] + ]], ["class-name", "Math"], ["punctuation", "."], "*", diff --git a/tests/languages/scala/keyword_feature.test b/tests/languages/scala/keyword_feature.test index c17e96050e..9e3cfb4d1b 100644 --- a/tests/languages/scala/keyword_feature.test +++ b/tests/languages/scala/keyword_feature.test @@ -4,7 +4,7 @@ abstract case catch class def do else extends final finally for forSome if -implicit import lazy +implicit import; lazy match new null object override package private protected return sealed @@ -21,7 +21,7 @@ var while with yield ["keyword", "class"], ["keyword", "def"], ["keyword", "do"], ["keyword", "else"], ["keyword", "extends"], ["keyword", "final"], ["keyword", "finally"], ["keyword", "for"], ["keyword", "forSome"], ["keyword", "if"], - ["keyword", "implicit"], ["keyword", "import"], ["keyword", "lazy"], + ["keyword", "implicit"], ["keyword", "import"], ["punctuation", ";"], ["keyword", "lazy"], ["keyword", "match"], ["keyword", "new"], ["keyword", "null"], ["keyword", "object"], ["keyword", "override"], ["keyword", "package"], ["keyword", "private"], ["keyword", "protected"], ["keyword", "return"], ["keyword", "sealed"],