Skip to content

Commit

Permalink
Added module keywords to Java. (#1655)
Browse files Browse the repository at this point in the history
This adds the in Java 9 introduced module keywords to Java.
Namespaces following these keywords are also properly highlighted.
  • Loading branch information
anton-balaniuc authored and RunDevelopment committed Dec 6, 2018
1 parent 8b1bb46 commit 6e250a5
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 4 deletions.
4 changes: 2 additions & 2 deletions components/prism-java.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function (Prism) {

var keywords = /\b(?:abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while|var|null)\b/;
var keywords = /\b(?:abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while|var|null|exports|module|open|opens|provides|requires|to|transitive|uses|with)\b/;

// based on the java naming conventions
var className = /\b[A-Z](?:\w*[a-z]\w*)?\b/;
Expand Down Expand Up @@ -35,7 +35,7 @@
lookbehind: true
},
'namespace': {
pattern: /\b(package\s+|import\s+(?:static\s+)?)[a-z]\w*(\.[a-z]\w*)+/,
pattern: /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)[a-z]\w*(\.[a-z]\w*)+/,
lookbehind: true,
inside: {
'punctuation': /\./,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-java.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion tests/languages/java/keyword_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ finally long
strictfp volatile const
float native super while
var null
module requires transitive
exports uses open
opens with to provides

----------------------------------------------------

Expand All @@ -45,7 +48,10 @@ var null
["keyword", "finally"], ["keyword", "long"],
["keyword", "strictfp"], ["keyword", "volatile"], ["keyword", "const"],
["keyword", "float"], ["keyword", "native"], ["keyword", "super"], ["keyword", "while"],
["keyword", "var"], ["keyword", "null"]
["keyword", "var"], ["keyword", "null"],
["keyword", "module"], ["keyword", "requires"], ["keyword", "transitive"],
["keyword", "exports"], ["keyword", "uses"], ["keyword", "open"],
["keyword", "opens"], ["keyword", "with"], ["keyword", "to"], ["keyword","provides"]
]

----------------------------------------------------
Expand Down
158 changes: 158 additions & 0 deletions tests/languages/java/module_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
module com.js.prism {
exports java.net.http;
exports jdk.internal.editor.spi to jdk.jshell;

requires java.base;
requires transitive java.xml;

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;

}


----------------------------------------------------
[
["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", "}"]
]

----------------------------------------------------

Checks for module definition.

0 comments on commit 6e250a5

Please sign in to comment.