-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Java: Add Java 9 module-related keywords #3628
Java: Add Java 9 module-related keywords #3628
Conversation
Registered the ten new Java 9 restricted keywords as keywords. From Section 3.9 of http://cr.openjdk.java.net/~mr/jigsaw/spec/java-se-9-jls-diffs.pdf: > A further ten character sequences are restricted keywords: open, module, requires, transitive, exports, opens, to, uses, provides, and with. Note that these are *restricted* keywords, it means that ideally they should be highlighted as keywords only when in `module-info.java`. From the Section 3.9 referenced above: > These character sequences are tokenized as keywords solely where they appear as terminals in the ModuleDeclaration and ModuleDirective productions (§7.7). They are tokenized as identifiers everywhere else, for compatibility with programs written prior to Java SE 9. There is one exception: immediately to the right of the character sequence requires in the ModuleDirective production, the character sequence transitive is tokenized as a keyword unless it is followed by a separator, in which case it is tokenized as an identifier. It makes this change similar to ajaxorg#3467 where `var` is not a keyword, but a `reserved type name`
Codecov Report
@@ Coverage Diff @@
## master #3628 +/- ##
==========================================
- Coverage 64.86% 64.82% -0.05%
==========================================
Files 471 471
Lines 47130 47303 +173
Branches 9001 9023 +22
==========================================
+ Hits 30572 30663 +91
- Misses 16558 16640 +82
Continue to review full report at Codecov.
|
This looks good.
Do you mean we need to still modify this code to not always highlight these keywords, or this is ok to merge as is? If we need to modify the code are |
@nightwing wrote:
You can merge as is - it's a reasonable approximation with rare false positives (incorrectly highlighted
This is a much better approach, it provides more accurate highlighting.
No, a module block cannot contain nested
|
You can add rules with next for doing this. {
regex: "module(?=\\s*\\w)",
token: "keyword",
next: [{
regex: "{",
token: "paren.lparen",
next: [{
regex: "}",
token: "paren.rparen",
next: "start"
}, {
regex: "open|requires|transitive|exports|opens|to|uses|provides|with",
token: "keyword"
}]
}, {
token : "text",
regex : "\\s+"
}, {
token : "identifier",
regex : "\\w+"
}, {
token : "punctuation.operator",
regex : "."
}, {
token : "text",
regex : "\\s+"
}, {
regex: "", // exit if there is anything else
next: "start"
}]
} before the one with keywordMapper and adding |
So the "to" in "monitoba" won't be highlighted: ```java module footoo { requires monitoba; } ```
Thank you! |
Registered the ten new Java 9 restricted keywords as keywords.
From Section 3.9 of http://cr.openjdk.java.net/~mr/jigsaw/spec/java-se-9-jls-diffs.pdf:
Keywords vs restricted keywords
Note that these are restricted keywords, it means that ideally they should be highlighted as keywords only when in
module-info.java
. From the Section 3.9 referenced above:It makes this change similar to #3467 where
var
is not a keyword, but areserved type name
Screenshot
This is what
module-info.java
looks like with this change: