From 3c316b20ceaaa6d591e98dc2c9ea5834ef0af937 Mon Sep 17 00:00:00 2001 From: Melvic Ybanez Date: Sun, 17 Apr 2022 03:50:21 +0800 Subject: [PATCH 1/4] Update version --- build.sbt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index f1cd942..226da67 100644 --- a/build.sbt +++ b/build.sbt @@ -1,10 +1,10 @@ import Dependencies.dependencies -ThisBuild / version := "0.3.0" +ThisBuild / version := "0.4.0-SNAPSHOT" ThisBuild / scalaVersion := "2.13.8" -assemblyJarName in assembly := "chi-0.3.0.jar" +assemblyJarName in assembly := "chi-0.4.0-snapshot.jar" lazy val root = (project in file(".")) .settings( From f3b36ab403f1743ac94d8800327262be95510e19 Mon Sep 17 00:00:00 2001 From: Melvic Ybanez Date: Sun, 17 Apr 2022 05:19:06 +0800 Subject: [PATCH 2/4] Add custom color scheme --- .../melvic/chi/views/TextAreaComponent.scala | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/scala/com/melvic/chi/views/TextAreaComponent.scala b/src/main/scala/com/melvic/chi/views/TextAreaComponent.scala index b35cbba..f24f30b 100644 --- a/src/main/scala/com/melvic/chi/views/TextAreaComponent.scala +++ b/src/main/scala/com/melvic/chi/views/TextAreaComponent.scala @@ -1,11 +1,10 @@ package com.melvic.chi.views import com.melvic.chi.Config -import com.melvic.chi.config.Preferences -import org.fife.ui.rsyntaxtextarea.{RSyntaxTextArea, SyntaxConstants, Theme} +import org.fife.ui.rsyntaxtextarea.{RSyntaxTextArea, SyntaxConstants, Theme, TokenTypes} import org.fife.ui.rtextarea.RTextScrollPane -import java.awt.Font +import java.awt.{Color, Font} import java.awt.font.TextAttribute import java.io.IOException import scala.collection.mutable @@ -17,6 +16,7 @@ class TextAreaComponent extends RSyntaxTextArea(50, 50) { setAntiAliasingEnabled(true) updateStyle() + updateScheme() updateFont() private def updateStyle(): Unit = @@ -28,6 +28,17 @@ class TextAreaComponent extends RSyntaxTextArea(50, 50) { ioe.printStackTrace() } + private def updateScheme(): Unit = { + val scheme = getSyntaxScheme + + setBackground(Color.decode("#212020")) + setCurrentLineHighlightColor(Color.decode("#191819")) + scheme.getStyle(TokenTypes.RESERVED_WORD).foreground = Color.decode("#C792EA") + scheme.getStyle(TokenTypes.IDENTIFIER).foreground = Color.decode("#82AAFF") + + revalidate() + } + private def updateFont(): Unit = { val font = Font.createFont(Font.TRUETYPE_FONT, getClass.getResourceAsStream(Config.DefaultFontPath)) From 71d1d6b944b87e59a039b9c1be11b3b5631349eb Mon Sep 17 00:00:00 2001 From: Melvic Ybanez Date: Mon, 18 Apr 2022 01:54:03 +0800 Subject: [PATCH 3/4] Custom token maker for chi --- .../com/melvic/chi/views/ChiTokenMaker.scala | 75 +++++++++++++++++++ .../melvic/chi/views/TextAreaComponent.scala | 19 ++++- 2 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 src/main/scala/com/melvic/chi/views/ChiTokenMaker.scala diff --git a/src/main/scala/com/melvic/chi/views/ChiTokenMaker.scala b/src/main/scala/com/melvic/chi/views/ChiTokenMaker.scala new file mode 100644 index 0000000..d30e9d6 --- /dev/null +++ b/src/main/scala/com/melvic/chi/views/ChiTokenMaker.scala @@ -0,0 +1,75 @@ +package com.melvic.chi.views + +import com.melvic.chi.views.ChiTokenMaker.extraTokens +import org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker +import org.fife.ui.rsyntaxtextarea.{TokenMap, TokenTypes} + +class ChiTokenMaker extends CPlusPlusTokenMaker { + override def addToken(array: Array[Char], start: Int, end: Int, tokenType: Int, startOffset: Int): Unit = { + val newTokenType = + if (tokenType == TokenTypes.IDENTIFIER) { + val newType = extraTokens.get(array, start, end) + if (newType > -1) newType else tokenType + } else tokenType + super.addToken(array, start, end, newTokenType, startOffset) + } +} + +object ChiTokenMaker { + lazy val extraTokens = { + val tokens = new TokenMap(false) + + val reservedWords = List( + "def", + "case", + "match", + "if", + "while", + "for", + "class", + "public", + "protected", + "private", + "abstract", + "object", + "val", + "var", + "import", + "trait", + "lazy", + "return" + ) + val functions = List("identity", "const", "compose", "andThen") + val dataTypes = List( + "int", + "Int", + "Integer", + "float", + "Float", + "double", + "Double", + "char", + "Char", + "Character", + "String", + "List", + "byte", + "short", + "Byte", + "Short", + "long", + "Long", + "Function", + "BiFunction", + "Either", + "Left", + "Right" + ) + + reservedWords.foreach(tokens.put(_, TokenTypes.RESERVED_WORD)) + functions.foreach(tokens.put(_, TokenTypes.FUNCTION)) + dataTypes.foreach(tokens.put(_, TokenTypes.DATA_TYPE)) + + tokens + } +} diff --git a/src/main/scala/com/melvic/chi/views/TextAreaComponent.scala b/src/main/scala/com/melvic/chi/views/TextAreaComponent.scala index f24f30b..a238a1d 100644 --- a/src/main/scala/com/melvic/chi/views/TextAreaComponent.scala +++ b/src/main/scala/com/melvic/chi/views/TextAreaComponent.scala @@ -1,7 +1,7 @@ package com.melvic.chi.views import com.melvic.chi.Config -import org.fife.ui.rsyntaxtextarea.{RSyntaxTextArea, SyntaxConstants, Theme, TokenTypes} +import org.fife.ui.rsyntaxtextarea.{AbstractTokenMakerFactory, RSyntaxTextArea, SyntaxConstants, Theme, TokenMakerFactory, TokenTypes} import org.fife.ui.rtextarea.RTextScrollPane import java.awt.{Color, Font} @@ -11,14 +11,20 @@ import scala.collection.mutable import scala.jdk.CollectionConverters._ class TextAreaComponent extends RSyntaxTextArea(50, 50) { - setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SCALA) - setCodeFoldingEnabled(true) - setAntiAliasingEnabled(true) + setup() updateStyle() updateScheme() updateFont() + private def setup(): Unit = { + val atmf = TokenMakerFactory.getDefaultInstance.asInstanceOf[AbstractTokenMakerFactory] + atmf.putMapping("text/chi", "com.melvic.chi.views.ChiTokenMaker") + setSyntaxEditingStyle("text/chi") + setCodeFoldingEnabled(true) + setAntiAliasingEnabled(true) + } + private def updateStyle(): Unit = try { val theme = Theme.load(getClass.getResourceAsStream("/org/fife/ui/rsyntaxtextarea/themes/dark.xml")) @@ -34,6 +40,11 @@ class TextAreaComponent extends RSyntaxTextArea(50, 50) { setBackground(Color.decode("#212020")) setCurrentLineHighlightColor(Color.decode("#191819")) scheme.getStyle(TokenTypes.RESERVED_WORD).foreground = Color.decode("#C792EA") + scheme.getStyle(TokenTypes.RESERVED_WORD_2).foreground = Color.decode("#C792EA") + scheme.getStyle(TokenTypes.DATA_TYPE).foreground = Color.decode("#FFCB6B") + scheme.getStyle(TokenTypes.OPERATOR).foreground = Color.decode("#89DDFF") + scheme.getStyle(TokenTypes.FUNCTION).foreground = Color.decode("#89DDFF") + scheme.getStyle(TokenTypes.SEPARATOR).foreground = Color.decode("#89DDFF") scheme.getStyle(TokenTypes.IDENTIFIER).foreground = Color.decode("#82AAFF") revalidate() From 26de4c1f2110f9ba146e295a78671016c3fb9a97 Mon Sep 17 00:00:00 2001 From: Melvic Ybanez Date: Mon, 18 Apr 2022 02:19:46 +0800 Subject: [PATCH 4/4] Add more function keywords --- src/main/scala/com/melvic/chi/views/ChiTokenMaker.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/melvic/chi/views/ChiTokenMaker.scala b/src/main/scala/com/melvic/chi/views/ChiTokenMaker.scala index d30e9d6..73d5893 100644 --- a/src/main/scala/com/melvic/chi/views/ChiTokenMaker.scala +++ b/src/main/scala/com/melvic/chi/views/ChiTokenMaker.scala @@ -39,7 +39,7 @@ object ChiTokenMaker { "lazy", "return" ) - val functions = List("identity", "const", "compose", "andThen") + val functions = List("identity", "const", "compose", "andThen", "apply", "_1", "_2", "_3") val dataTypes = List( "int", "Int",