diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/code/highlighting/JavaSyntaxHighlighter.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/code/highlighting/JavaSyntaxHighlighter.kt index 3449c97b..48cf2131 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/code/highlighting/JavaSyntaxHighlighter.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/code/highlighting/JavaSyntaxHighlighter.kt @@ -16,6 +16,9 @@ class JavaSyntaxHighlighter : SyntaxHighlighter { result.groups["BRACKET"] != null -> "bracket" result.groups["SEMICOLON"] != null -> "semicolon" result.groups["STRING"] != null -> "string" + result.groups["NUMBER"] != null -> "number" + result.groups["ANNOTATION"] != null -> "annotation" + result.groups["OPERATOR"] != null -> "operator" result.groups["COMMENT"] != null -> "comment" else -> throw IllegalStateException("Unsupported regex group") } @@ -44,28 +47,34 @@ class JavaSyntaxHighlighter : SyntaxHighlighter { "new", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", - "transient", "try", "void", "volatile", "while" + "transient", "try", "void", "volatile", "while", "null" ) private val KEYWORD_PATTERN = "\\b(" + KEYWORDS.joinToString("|") + ")\\b" + private val ANNOTATION_PATTERN = "@\\w+" private val PAREN_PATTERN = "\\(|\\)" private val BRACE_PATTERN = "\\{|\\}" private val BRACKET_PATTERN = "\\[|\\]" private val SEMICOLON_PATTERN = "\\;" private val STRING_PATTERN = "\"([^\"\\\\]|\\\\.)*\"" + private val NUMBER_PATTERN = "\\b-?([0-9]*\\.[0-9]+|[0-9]+)\\w?\\b" + private val OPERATOR_PATTERN = "[+-/*:|&?<>=!]" private val COMMENT_PATTERN = """ //[^ ]*|/\*(.|\R)*?\*/ """.trimIndent() private val PATTERN = ( - "(?" + KEYWORD_PATTERN + ")" - + "|(?" + PAREN_PATTERN + ")" - + "|(?" + BRACE_PATTERN + ")" - + "|(?" + BRACKET_PATTERN + ")" - + "|(?" + SEMICOLON_PATTERN + ")" - + "|(?" + STRING_PATTERN + ")" - + "|(?" + COMMENT_PATTERN + ")" + "(?$KEYWORD_PATTERN)" + + "|(?$ANNOTATION_PATTERN)" + + "|(?$PAREN_PATTERN)" + + "|(?$BRACE_PATTERN)" + + "|(?$BRACKET_PATTERN)" + + "|(?$SEMICOLON_PATTERN)" + + "|(?$STRING_PATTERN)" + + "|(?$NUMBER_PATTERN)" + + "|(?$OPERATOR_PATTERN)" + + "|(?$COMMENT_PATTERN)" ).toRegex() } } \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/code/stylesheet/JavaSyntaxHighlightingStylesheet.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/code/stylesheet/JavaSyntaxHighlightingStylesheet.kt index 301dc73c..130e74e8 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/code/stylesheet/JavaSyntaxHighlightingStylesheet.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/code/stylesheet/JavaSyntaxHighlightingStylesheet.kt @@ -11,6 +11,10 @@ class JavaSyntaxHighlightingStylesheet : Stylesheet() { val bracket by cssclass() val brace by cssclass() val string by cssclass() + val number by cssclass() + val annotation by cssclass() + val operator by cssclass() + val field by cssclass() val comment by cssclass() val paragraphBox by cssclass() val paragraphText by cssclass() @@ -22,7 +26,7 @@ class JavaSyntaxHighlightingStylesheet : Stylesheet() { init { keyword { - fill = c("purple") + fill = c("#000080") fontWeight = FontWeight.BOLD } @@ -31,7 +35,7 @@ class JavaSyntaxHighlightingStylesheet : Stylesheet() { } paren { - fill = c("firebrick") + fill = c("cadetblue") fontWeight = FontWeight.BOLD } @@ -46,11 +50,24 @@ class JavaSyntaxHighlightingStylesheet : Stylesheet() { } string { - fill = c("blue") + fill = c("#008000") + } + + number { + fill = c("#0000FF") + } + + operator { + fill = c("#CC7832") + } + + annotation { + fill = c("#BBB529") + fontWeight = FontWeight.BOLD } comment { - fill = c("cadetblue") + fill = c("#808080") } paragraphBox and hasCaret {