Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for java modules related keywords. #1655

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.