[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Some love for Java syntax highlighting
From: |
Benno Schulenberg |
Subject: |
[PATCH] Some love for Java syntax highlighting |
Date: |
Tue, 16 Jun 2020 17:16:59 +0200 |
From: Devin Hussey <husseydevin@gmail.com>
[Does anyone here use Java? Are these changes an improvement
over the current Java syntax? -- Benno]
This is much better than the unsightly highlighting we had before.
- I changed the colors to fit in with the nanorc style, which I happen to like
a lot. No more red strings.
- It supports current keywords such as enum and module
- It supports number/character literals, and no longer chokes on escapes
- Colors are easier to read, and there are fewer clashes (e.g. string switching)
- CONSTANTS_ARE_HIGHLIGHTED_LIKE_C
- @Annotations and @javadoc keywords are also highlighted now.
- It recognizes .aidl files and files starting with "^package foo.*;" as Java.
Signed-off-by: Devin Hussey <husseydevin@gmail.com>
---
syntax/java.nanorc | 40 ++++++++++++++++++++++++++++------------
1 file changed, 28 insertions(+), 12 deletions(-)
diff --git a/syntax/java.nanorc b/syntax/java.nanorc
index 5bb294f4..312e14a7 100644
--- a/syntax/java.nanorc
+++ b/syntax/java.nanorc
@@ -1,16 +1,32 @@
## Here is an example for Java.
-
-syntax java "\.java$"
-magic "Java "
+syntax java "\.(aidl|java)$"
+# package foo.(...);
+header "^[[:space:]]*package[[:space:]]+[a-zA-Z][a-zA-Z0-9]*\..+;$"
+# XXX: Don't Java files identify as "C source, ASCII text"?
+magic ".*Java[^S].*"
comment "//"
-color green
"\<(boolean|byte|char|double|float|int|long|new|short|this|transient|void)\>"
-color red
"\<(break|case|catch|continue|default|do|else|finally|for|if|return|switch|throw|try|while)\>"
-color cyan
"\<(abstract|class|extends|final|implements|import|instanceof|interface|native)\>"
-color cyan
"\<(package|private|protected|public|static|strictfp|super|synchronized|throws|volatile)\>"
-color red ""[^"]*""
-color yellow "\<(true|false|null)\>"
-color blue "//.*"
-color blue start="/\*" end="\*/"
-color brightblue start="/\*\*" end="\*/"
+# Constants
+color brightred "\<[A-Z_][A-Z0-9_]+\>"
+# Keywords
+color yellow
"\<(boolean|byte|char|double|float|int|long|new|short|transient|var|void)\>"
+color magenta
"\<(assert|break|case|catch|continue|default|do|else|finally|for|if|return|switch|throw|try|while)\>"
+color green
"\<(abstract|class|enum|exports|extends|final|implements|import|instanceof|interface|module|native|requires)\>"
+color green
"\<(package|private|protected|public|static|strictfp|super|synchronized|throws|volatile)\>"
+# Weird unused keywords
+color brightwhite,red "\<(const|goto)\>"
+
+# Quotes and literals
+color brightmagenta ""(\\"|[^"])*""
+color brightmagenta "'([^'\]|(\\["'abfnrtv\\]))'" "'\\(([0-3]?[0-7]{1,2}))'"
"'\\x[0-9A-Fa-f]{1,2}'"
+# Number literals
+color brightmagenta
"\<(0b[01][01_]*|0[0-7][0-7_]*|[[:digit:]]+(\.[[:digit:]_]*)?|\.[[:digit:]_]+)[lLFfDd]?\>|(-?)(\<0[xX][[:xdigit:]_]+|(\<[[:digit:]_]+(\.[[:digit:]_]*)?|\.[[:digit:]_]+)([eE][-+]?[[:digit:]_]+)?)\>"
+color brightmagenta "\<(true|false|null)\>"
+
+# Comments
+color brightblue "//.*"
+color brightblue start="/\*" end="\*/"
+# Annotations or Javadoc keywords
+color cyan "@[[:space:]]*\<[A-Za-z][A-Za-z0-9_]*\>"
+
color ,green "[[:space:]]+$"
--
2.19.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Some love for Java syntax highlighting,
Benno Schulenberg <=