Skip to content

Commit

Permalink
Java: Added char token (#3217)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Dec 5, 2021
1 parent fa55492 commit 0a9f909
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
9 changes: 9 additions & 0 deletions components/prism-java.js
Expand Up @@ -21,6 +21,11 @@
};

Prism.languages.java = Prism.languages.extend('clike', {
'string': {
pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,
lookbehind: true,
greedy: true
},
'class-name': [
className,
{
Expand Down Expand Up @@ -52,6 +57,10 @@
pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
greedy: true,
alias: 'string'
},
'char': {
pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
greedy: true
}
});

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.

11 changes: 11 additions & 0 deletions tests/languages/java/char_feature.test
@@ -0,0 +1,11 @@
'A'
'\n'
'\u0041'

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

[
["char", "'A'"],
["char", "'\\n'"],
["char", "'\\u0041'"]
]
2 changes: 1 addition & 1 deletion tests/languages/java/generics_feature.test
Expand Up @@ -83,7 +83,7 @@ if (a<6&&b>6){}
["punctuation", "("],
["number", "12.2585"],
["punctuation", ","],
["string", "'C'"],
["char", "'C'"],
["punctuation", ")"],
["punctuation", ";"],

Expand Down
2 changes: 2 additions & 0 deletions tests/languages/java/string_feature.test
@@ -1,3 +1,4 @@
""
"foo"
"\"foo\""

Expand All @@ -20,6 +21,7 @@ String empty = """
----------------------------------------------------

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

Expand Down
13 changes: 13 additions & 0 deletions tests/languages/scala/char_feature.test
@@ -0,0 +1,13 @@
'a'
'\u0041'
'\n'
'\t'

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

[
["char", "'a'"],
["char", "'\\u0041'"],
["char", "'\\n'"],
["char", "'\\t'"]
]
10 changes: 1 addition & 9 deletions tests/languages/scala/string_feature.test
@@ -1,8 +1,3 @@
'a'
'\u0041'
'\n'
'\t'

""
"fo\"obar"

Expand All @@ -17,12 +12,9 @@ bar"""
----------------------------------------------------

[
["string", "'a'"],
["string", "'\\u0041'"],
["string", "'\\n'"],
["string", "'\\t'"],
["string", "\"\""],
["string", "\"fo\\\"obar\""],

["triple-quoted-string", "\"\"\"fo\"o\r\nbar\"\"\""],
["triple-quoted-string", "\"\"\"fo\"o\r\n// comment\r\nbar\"\"\""],
["string", "\"foo /* comment */ bar\""],
Expand Down

0 comments on commit 0a9f909

Please sign in to comment.