Skip to content

Commit

Permalink
Added support for syntax in Java 13 (#2060)
Browse files Browse the repository at this point in the history
This adds support for the new `yield` keyword and text blocks (triple quoted strings) which are both introduced in Java 13.
  • Loading branch information
RunDevelopment authored Sep 24, 2019
1 parent 007c9af commit a7b95dd
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 17 deletions.
11 changes: 10 additions & 1 deletion 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|exports|module|open|opens|provides|requires|to|transitive|uses|with)\b/;
var keywords = /\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|requires|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;

// based on the java naming conventions
var className = /\b[A-Z](?:\w*[a-z]\w*)?\b/;
Expand Down Expand Up @@ -28,6 +28,15 @@
}
});

Prism.languages.insertBefore('java', 'string', {
'triple-quoted-string': {
// http://openjdk.java.net/jeps/355#Description
pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
greedy: true,
alias: 'string'
}
});

Prism.languages.insertBefore('java', 'class-name', {
'annotation': {
alias: '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.

19 changes: 9 additions & 10 deletions components/prism-scala.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Prism.languages.scala = Prism.languages.extend('java', {
'keyword': /<-|=>|\b(?:abstract|case|catch|class|def|do|else|extends|final|finally|for|forSome|if|implicit|import|lazy|match|new|null|object|override|package|private|protected|return|sealed|self|super|this|throw|trait|try|type|val|var|while|with|yield)\b/,
'string': [
{
pattern: /"""[\s\S]*?"""/,
greedy: true
},
{
pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
greedy: true
}
],
'triple-quoted-string': {
pattern: /"""[\s\S]*?"""/,
greedy: true,
alias: 'string'
},
'string': {
pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
greedy: true
},
'builtin': /\b(?:String|Int|Long|Short|Byte|Boolean|Double|Float|Char|Any|AnyRef|AnyVal|Unit|Nothing)\b/,
'number': /\b0x[\da-f]*\.?[\da-f]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e\d+)?[dfl]?/i,
'symbol': /'[^\d\s\\]\w*/
Expand Down
2 changes: 1 addition & 1 deletion components/prism-scala.min.js

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

4 changes: 3 additions & 1 deletion tests/languages/java/keyword_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var null
module requires transitive
exports uses open
opens with to provides
yield

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

Expand Down Expand Up @@ -51,7 +52,8 @@ opens with to provides
["keyword", "var"], ["keyword", "null"],
["keyword", "module"], ["keyword", "requires"], ["keyword", "transitive"],
["keyword", "exports"], ["keyword", "uses"], ["keyword", "open"],
["keyword", "opens"], ["keyword", "with"], ["keyword", "to"], ["keyword","provides"]
["keyword", "opens"], ["keyword", "with"], ["keyword", "to"], ["keyword", "provides"],
["keyword", "yield"]
]

----------------------------------------------------
Expand Down
50 changes: 50 additions & 0 deletions tests/languages/java/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"foo"
"\"foo\""

"""
foo
"""

var a = """
\"""
foo""";

"""
The quick brown fox""" + " \n" + """
jumps over the lazy dog
"""

String empty = """
""";


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

[
["string", "\"foo\""],
["string", "\"\\\"foo\\\"\""],

["triple-quoted-string", "\"\"\"\nfoo\n\"\"\""],

["keyword", "var"],
" a ",
["operator", "="],
["triple-quoted-string", "\"\"\"\n\\\"\"\"\nfoo\"\"\""],
["punctuation", ";"],

["triple-quoted-string", "\"\"\"\nThe quick brown fox\"\"\""],
["operator", "+"],
["string", "\" \\n\""],
["operator", "+"],
["triple-quoted-string", "\"\"\"\njumps over the lazy dog\n\"\"\""],

["class-name", "String"],
" empty ",
["operator", "="],
["triple-quoted-string", "\"\"\"\n\"\"\""],
["punctuation", ";"]
]

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

Checks for strings.
6 changes: 3 additions & 3 deletions tests/languages/scala/string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ bar"""
["string", "'\\t'"],
["string", "\"\""],
["string", "\"fo\\\"obar\""],
["string", "\"\"\"fo\"o\r\nbar\"\"\""],
["string", "\"\"\"fo\"o\r\n// comment\r\nbar\"\"\""],
["triple-quoted-string", "\"\"\"fo\"o\r\nbar\"\"\""],
["triple-quoted-string", "\"\"\"fo\"o\r\n// comment\r\nbar\"\"\""],
["string", "\"foo /* comment */ bar\""],
["string", "'foo // bar'"]
]

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

Checks for characters and strings.
Checks for characters and strings.

0 comments on commit a7b95dd

Please sign in to comment.