diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 9ab8024..2557e40 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -12,6 +12,7 @@
+
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 3849390..c9ca3a1 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -4,10 +4,10 @@ plugins {
}
android {
- namespace = "com.naulian.glow"
+ namespace = "com.example.glow"
compileSdk = 34
defaultConfig {
- applicationId = "com.naulian.glow"
+ applicationId = "com.example.glow"
minSdk = 26
targetSdk = 34
versionCode = 1
@@ -49,31 +49,27 @@ android {
}
dependencies {
- implementation("androidx.core:core-ktx:1.12.0")
- implementation("androidx.appcompat:appcompat:1.6.1")
- implementation("com.google.android.material:material:1.11.0")
- implementation("androidx.constraintlayout:constraintlayout:2.1.4")
+ implementation(libs.androidx.core.ktx)
+ implementation(libs.androidx.appcompat)
+ implementation(libs.material)
+ implementation(libs.androidx.constraintlayout)
//compose
- implementation(platform("androidx.compose:compose-bom:2024.02.02"))
- implementation("androidx.compose.ui:ui")
- implementation("androidx.compose.ui:ui-graphics")
- implementation("androidx.compose.ui:ui-tooling-preview")
- implementation("androidx.compose.material3:material3")
+ implementation(platform(libs.androidx.compose.bom))
+ implementation(libs.androidx.compose.ui)
+ implementation(libs.androidx.compose.ui.graphic)
+ implementation(libs.androidx.compose.ui.tooling.preview)
+ implementation(libs.androidx.compose.material3)
- implementation("com.naulian:anhance:2024.1.16")
- //implementation("com.naulian:glow:1.3.1")
- //implementation("com.naulian.glow:glow_compose:1.3.0")
+ //test
+ testImplementation(libs.junit)
+ androidTestImplementation(libs.androidx.junit)
+ androidTestImplementation(libs.androidx.espresso.core)
+ androidTestImplementation(platform(libs.androidx.compose.bom))
+ debugImplementation(libs.androidx.compose.ui.tooling)
+ debugImplementation(libs.androidx.compose.ui.tooling.preview)
- testImplementation("junit:junit:4.13.2")
- androidTestImplementation("androidx.test.ext:junit:1.1.5")
- androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
- androidTestImplementation(platform("androidx.compose:compose-bom:2024.02.02"))
- androidTestImplementation("androidx.compose.ui:ui-test-junit4")
-
- //debug
- debugImplementation("androidx.compose.ui:ui-tooling")
- debugImplementation("androidx.compose.ui:ui-test-manifest")
+ implementation(libs.anhance)
implementation(fileTree("libs") {
include("*.jar")
diff --git a/app/src/main/assets/sample.kt b/app/src/main/assets/sample.kt
index 0a60b0a..3803b2f 100644
--- a/app/src/main/assets/sample.kt
+++ b/app/src/main/assets/sample.kt
@@ -1,6 +1,8 @@
+import java.util.Locale
import kotlin.random.Random
fun main() {
+ val map = hashMapOf()
println("Welcome to the $Coin Flipping Game!")
println("I will flip a ${coin}, and you have to guess the outcome.")
println("Enter 'H' for Heads \n or 'T' for Tails.")
@@ -16,7 +18,7 @@ fun main() {
do {
print("Enter your guess (H/T): ")
- playerGuess = readLine()?.trim()?.toUpperCase() ?: ""
+ playerGuess = readlnOrNull()?.trim()?.uppercase(Locale.getDefault()) ?: ""
validInput = playerGuess == "H" || playerGuess == "T"
if (!validInput) {
println("Invalid input. Please enter 'H' for Heads or 'T' for Tails.")
diff --git a/app/src/main/java/com/naulian/glow/MainActivity.kt b/app/src/main/java/com/example/glow/MainActivity.kt
similarity index 85%
rename from app/src/main/java/com/naulian/glow/MainActivity.kt
rename to app/src/main/java/com/example/glow/MainActivity.kt
index ff5285e..44fd14b 100644
--- a/app/src/main/java/com/naulian/glow/MainActivity.kt
+++ b/app/src/main/java/com/example/glow/MainActivity.kt
@@ -1,4 +1,4 @@
-package com.naulian.glow
+package com.example.glow
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
@@ -9,8 +9,11 @@ import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.core.widget.doAfterTextChanged
+import com.example.glow.databinding.ActivityMainBinding
import com.naulian.anhance.readStringAsset
-import com.naulian.glow.databinding.ActivityMainBinding
+import com.naulian.glow.CodeTheme
+import com.naulian.glow.glowSyntax
+import com.naulian.glow.setCodeTheme
import com.naulian.glow_compose.Glow
import com.naulian.glow_compose.toComposeColor
@@ -40,7 +43,9 @@ class MainActivity : AppCompatActivity() {
val highLightedCompose = Glow.highlight(source, language, theme)
composeView.setContent {
- LazyRow(modifier = Modifier.background(theme.background.toComposeColor()).padding(16.dp)) {
+ LazyRow(modifier = Modifier
+ .background(theme.background.toComposeColor())
+ .padding(16.dp)) {
item { Text(text = highLightedCompose.value) }
}
}
diff --git a/glow-compose/build.gradle.kts b/glow-compose/build.gradle.kts
index 6616849..53aef37 100644
--- a/glow-compose/build.gradle.kts
+++ b/glow-compose/build.gradle.kts
@@ -49,28 +49,26 @@ android {
dependencies {
- implementation("androidx.core:core-ktx:1.12.0")
- implementation("androidx.appcompat:appcompat:1.6.1")
- implementation("com.google.android.material:material:1.11.0")
+ implementation(libs.androidx.core.ktx)
+ implementation(libs.androidx.appcompat)
+ implementation(libs.material)
//compose
- implementation(platform("androidx.compose:compose-bom:2024.02.02"))
- implementation("androidx.compose.ui:ui")
- implementation("androidx.compose.ui:ui-graphics")
- implementation("androidx.compose.ui:ui-tooling-preview")
- implementation("androidx.compose.material3:material3")
+ implementation(platform(libs.androidx.compose.bom))
+ implementation(libs.androidx.compose.ui)
+ implementation(libs.androidx.compose.ui.graphic)
+ implementation(libs.androidx.compose.ui.tooling.preview)
+ implementation(libs.androidx.compose.material3)
- testImplementation("junit:junit:4.13.2")
- androidTestImplementation("androidx.test.ext:junit:1.1.5")
- androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
- androidTestImplementation(platform("androidx.compose:compose-bom:2024.02.02"))
- androidTestImplementation("androidx.compose.ui:ui-test-junit4")
+ //test
+ testImplementation(libs.junit)
+ androidTestImplementation(libs.androidx.junit)
+ androidTestImplementation(libs.androidx.espresso.core)
+ androidTestImplementation(platform(libs.androidx.compose.bom))
+ debugImplementation(libs.androidx.compose.ui.tooling)
+ debugImplementation(libs.androidx.compose.ui.tooling.preview)
- //debug
- debugImplementation("androidx.compose.ui:ui-tooling")
- debugImplementation("androidx.compose.ui:ui-test-manifest")
-
- implementation("com.naulian:anhance:2024.1.16")
+ implementation(libs.anhance)
implementation(fileTree("libs") {
include("*.jar")
})
@@ -94,7 +92,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.naulian"
artifactId = "glow-compose"
- version = "1.3.9"
+ version = "1.4.1"
}
}
}
diff --git a/glow-compose/src/main/java/com/naulian/glow_compose/Glow.kt b/glow-compose/src/main/java/com/naulian/glow_compose/Glow.kt
index 1bfb169..b3acdd8 100644
--- a/glow-compose/src/main/java/com/naulian/glow_compose/Glow.kt
+++ b/glow-compose/src/main/java/com/naulian/glow_compose/Glow.kt
@@ -77,8 +77,8 @@ object Glow {
com.naulian.glow_core.Type.CHAR -> theme.string
com.naulian.glow_core.Type.STRING -> theme.string
com.naulian.glow_core.Type.ASSIGNMENT -> theme.normal
- com.naulian.glow_core.Type.COMMENT_MULTI -> theme.comment
- com.naulian.glow_core.Type.COMMENT_SINGLE -> theme.comment
+ com.naulian.glow_core.Type.MCOMMENT -> theme.comment
+ com.naulian.glow_core.Type.SCOMMENT -> theme.comment
else -> theme.normal
}.toComposeColor()
@@ -112,8 +112,8 @@ object Glow {
com.naulian.glow_core.Type.CHAR -> theme.string
com.naulian.glow_core.Type.STRING -> theme.string
com.naulian.glow_core.Type.ASSIGNMENT -> theme.normal
- com.naulian.glow_core.Type.COMMENT_MULTI -> theme.comment
- com.naulian.glow_core.Type.COMMENT_SINGLE -> theme.comment
+ com.naulian.glow_core.Type.MCOMMENT -> theme.comment
+ com.naulian.glow_core.Type.SCOMMENT -> theme.comment
else -> theme.normal
}.toComposeColor()
@@ -147,7 +147,7 @@ object Glow {
com.naulian.glow_core.Type.VALUE_FLOAT -> theme.number
com.naulian.glow_core.Type.STRING -> theme.string
com.naulian.glow_core.Type.ASSIGNMENT -> theme.normal
- com.naulian.glow_core.Type.COMMENT_SINGLE -> theme.comment
+ com.naulian.glow_core.Type.SCOMMENT -> theme.comment
else -> theme.normal
}.toComposeColor()
@@ -186,8 +186,8 @@ object Glow {
com.naulian.glow_core.Type.INTERPOLATION -> theme.property
com.naulian.glow_core.Type.ASSIGNMENT -> theme.normal
com.naulian.glow_core.Type.ESCAPE -> theme.keyword
- com.naulian.glow_core.Type.COMMENT_MULTI -> theme.comment
- com.naulian.glow_core.Type.COMMENT_SINGLE -> theme.comment
+ com.naulian.glow_core.Type.MCOMMENT -> theme.comment
+ com.naulian.glow_core.Type.SCOMMENT -> theme.comment
else -> theme.normal
}.toComposeColor()
diff --git a/glow-compose/src/main/java/com/naulian/glow_compose/GlowJob.kt b/glow-compose/src/main/java/com/naulian/glow_compose/GlowJob.kt
index 9cac863..3d9bc16 100644
--- a/glow-compose/src/main/java/com/naulian/glow_compose/GlowJob.kt
+++ b/glow-compose/src/main/java/com/naulian/glow_compose/GlowJob.kt
@@ -10,13 +10,15 @@ import com.naulian.glow.tokens.JsTokens
import com.naulian.glow.tokens.PTokens
import com.naulian.glow.tokens.TxtTokens
import com.naulian.glow_compose.kotlin.tokenizeKt
+import com.naulian.glow_core.Token
+import com.naulian.glow_core.Type
fun launchGlowJob(source: String, language: String, theme: Theme): GlowJob {
return GlowJob().launch(source, language, theme)
}
class GlowJob {
- private var _tokens = emptyList()
+ private var _tokens = emptyList()
val tokens get() = _tokens
private var _highLight = HighLight(value = buildAnnotatedString { })
@@ -50,24 +52,24 @@ class GlowJob {
val builder = buildAnnotatedString {
tokens.forEach {
val hlColor = when (it.type) {
- com.naulian.glow_core.Type.LT, com.naulian.glow_core.Type.GT -> theme.normal
- com.naulian.glow_core.Type.KEYWORD -> theme.keyword
- com.naulian.glow_core.Type.PROPERTY -> theme.property
- com.naulian.glow_core.Type.VARIABLE -> theme.keyword
- com.naulian.glow_core.Type.VAR_NAME -> theme.variable
- com.naulian.glow_core.Type.CLASS -> theme.keyword
- com.naulian.glow_core.Type.FUNCTION -> theme.keyword
- com.naulian.glow_core.Type.FUNC_NAME -> theme.method
- com.naulian.glow_core.Type.FUNC_CALL -> theme.method
- com.naulian.glow_core.Type.NUMBER -> theme.number
- com.naulian.glow_core.Type.VALUE_INT -> theme.number
- com.naulian.glow_core.Type.VALUE_LONG -> theme.number
- com.naulian.glow_core.Type.VALUE_FLOAT -> theme.number
- com.naulian.glow_core.Type.CHAR -> theme.string
- com.naulian.glow_core.Type.STRING -> theme.string
- com.naulian.glow_core.Type.ASSIGNMENT -> theme.normal
- com.naulian.glow_core.Type.COMMENT_MULTI -> theme.comment
- com.naulian.glow_core.Type.COMMENT_SINGLE -> theme.comment
+ Type.LT, Type.GT -> theme.normal
+ Type.KEYWORD -> theme.keyword
+ Type.PROPERTY -> theme.property
+ Type.VARIABLE -> theme.keyword
+ Type.VAR_NAME -> theme.variable
+ Type.CLASS -> theme.keyword
+ Type.FUNCTION -> theme.keyword
+ Type.FUNC_NAME -> theme.method
+ Type.FUNC_CALL -> theme.method
+ Type.NUMBER -> theme.number
+ Type.VALUE_INT -> theme.number
+ Type.VALUE_LONG -> theme.number
+ Type.VALUE_FLOAT -> theme.number
+ Type.CHAR -> theme.string
+ Type.STRING -> theme.string
+ Type.ASSIGNMENT -> theme.normal
+ Type.MCOMMENT -> theme.comment
+ Type.SCOMMENT -> theme.comment
else -> theme.normal
}.toComposeColor()
@@ -85,22 +87,22 @@ class GlowJob {
val builder = buildAnnotatedString {
tokens.forEach {
val hlColor = when (it.type) {
- com.naulian.glow_core.Type.LT, com.naulian.glow_core.Type.GT -> theme.normal
- com.naulian.glow_core.Type.KEYWORD -> theme.keyword
- com.naulian.glow_core.Type.VARIABLE -> theme.keyword
- com.naulian.glow_core.Type.VAR_NAME -> theme.variable
- com.naulian.glow_core.Type.CLASS -> theme.keyword
- com.naulian.glow_core.Type.FUNCTION -> theme.keyword
- com.naulian.glow_core.Type.FUNC_NAME -> theme.method
- com.naulian.glow_core.Type.NUMBER -> theme.number
- com.naulian.glow_core.Type.VALUE_INT -> theme.number
- com.naulian.glow_core.Type.VALUE_LONG -> theme.number
- com.naulian.glow_core.Type.VALUE_FLOAT -> theme.number
- com.naulian.glow_core.Type.CHAR -> theme.string
- com.naulian.glow_core.Type.STRING -> theme.string
- com.naulian.glow_core.Type.ASSIGNMENT -> theme.normal
- com.naulian.glow_core.Type.COMMENT_MULTI -> theme.comment
- com.naulian.glow_core.Type.COMMENT_SINGLE -> theme.comment
+ Type.LT, Type.GT -> theme.normal
+ Type.KEYWORD -> theme.keyword
+ Type.VARIABLE -> theme.keyword
+ Type.VAR_NAME -> theme.variable
+ Type.CLASS -> theme.keyword
+ Type.FUNCTION -> theme.keyword
+ Type.FUNC_NAME -> theme.method
+ Type.NUMBER -> theme.number
+ Type.VALUE_INT -> theme.number
+ Type.VALUE_LONG -> theme.number
+ Type.VALUE_FLOAT -> theme.number
+ Type.CHAR -> theme.string
+ Type.STRING -> theme.string
+ Type.ASSIGNMENT -> theme.normal
+ Type.MCOMMENT -> theme.comment
+ Type.SCOMMENT -> theme.comment
else -> theme.normal
}.toComposeColor()
@@ -119,20 +121,20 @@ class GlowJob {
val builder = buildAnnotatedString {
tokens.forEach {
val hlColor = when (it.type) {
- com.naulian.glow_core.Type.LT, com.naulian.glow_core.Type.GT -> theme.normal
- com.naulian.glow_core.Type.KEYWORD -> theme.keyword
- com.naulian.glow_core.Type.PROPERTY -> theme.property
- com.naulian.glow_core.Type.CLASS -> theme.keyword
- com.naulian.glow_core.Type.FUNCTION -> theme.keyword
- com.naulian.glow_core.Type.FUNC_NAME -> theme.method
- com.naulian.glow_core.Type.FUNC_CALL -> theme.method
- com.naulian.glow_core.Type.NUMBER -> theme.number
- com.naulian.glow_core.Type.VALUE_INT -> theme.number
- com.naulian.glow_core.Type.VALUE_LONG -> theme.number
- com.naulian.glow_core.Type.VALUE_FLOAT -> theme.number
- com.naulian.glow_core.Type.STRING -> theme.string
- com.naulian.glow_core.Type.ASSIGNMENT -> theme.normal
- com.naulian.glow_core.Type.COMMENT_SINGLE -> theme.comment
+ Type.LT, Type.GT -> theme.normal
+ Type.KEYWORD -> theme.keyword
+ Type.PROPERTY -> theme.property
+ Type.CLASS -> theme.keyword
+ Type.FUNCTION -> theme.keyword
+ Type.FUNC_NAME -> theme.method
+ Type.FUNC_CALL -> theme.method
+ Type.NUMBER -> theme.number
+ Type.VALUE_INT -> theme.number
+ Type.VALUE_LONG -> theme.number
+ Type.VALUE_FLOAT -> theme.number
+ Type.STRING -> theme.string
+ Type.ASSIGNMENT -> theme.normal
+ Type.SCOMMENT -> theme.comment
else -> theme.normal
}.toComposeColor()
@@ -150,27 +152,27 @@ class GlowJob {
val builder = buildAnnotatedString {
tokens.forEach {
val hlColor = when (it.type) {
- com.naulian.glow_core.Type.LT, com.naulian.glow_core.Type.GT -> theme.normal
- com.naulian.glow_core.Type.KEYWORD -> theme.keyword
- com.naulian.glow_core.Type.VARIABLE -> theme.keyword
- com.naulian.glow_core.Type.VAR_NAME -> theme.variable
- com.naulian.glow_core.Type.CLASS -> theme.keyword
- com.naulian.glow_core.Type.FUNCTION -> theme.keyword
- com.naulian.glow_core.Type.FUNC_NAME -> theme.method
- com.naulian.glow_core.Type.FUNC_CALL -> theme.method
- com.naulian.glow_core.Type.NUMBER -> theme.number
- com.naulian.glow_core.Type.VALUE_INT -> theme.number
- com.naulian.glow_core.Type.VALUE_LONG -> theme.number
- com.naulian.glow_core.Type.VALUE_FLOAT -> theme.number
- com.naulian.glow_core.Type.CHAR -> theme.string
- com.naulian.glow_core.Type.PROPERTY -> theme.property
- com.naulian.glow_core.Type.STRING -> theme.string
- com.naulian.glow_core.Type.STRING_BRACE -> theme.keyword
- com.naulian.glow_core.Type.INTERPOLATION -> theme.property
- com.naulian.glow_core.Type.ASSIGNMENT -> theme.normal
- com.naulian.glow_core.Type.ESCAPE -> theme.keyword
- com.naulian.glow_core.Type.COMMENT_MULTI -> theme.comment
- com.naulian.glow_core.Type.COMMENT_SINGLE -> theme.comment
+ Type.LT, Type.GT -> theme.normal
+ Type.KEYWORD -> theme.keyword
+ Type.VARIABLE -> theme.keyword
+ Type.VAR_NAME -> theme.variable
+ Type.CLASS -> theme.keyword
+ Type.FUNCTION -> theme.keyword
+ Type.FUNC_NAME -> theme.method
+ Type.FUNC_CALL -> theme.method
+ Type.NUMBER -> theme.number
+ Type.VALUE_INT -> theme.number
+ Type.VALUE_LONG -> theme.number
+ Type.VALUE_FLOAT -> theme.number
+ Type.CHAR -> theme.string
+ Type.PROPERTY -> theme.property
+ Type.STRING -> theme.string
+ Type.STRING_BRACE -> theme.keyword
+ Type.INTERPOLATION -> theme.property
+ Type.ASSIGNMENT -> theme.normal
+ Type.ESCAPE -> theme.keyword
+ Type.MCOMMENT -> theme.comment
+ Type.SCOMMENT -> theme.comment
else -> theme.normal
}.toComposeColor()
diff --git a/glow-compose/src/main/java/com/naulian/glow_compose/kotlin/KtLexer.kt b/glow-compose/src/main/java/com/naulian/glow_compose/kotlin/KtLexer.kt
index 094af3f..500d68d 100644
--- a/glow-compose/src/main/java/com/naulian/glow_compose/kotlin/KtLexer.kt
+++ b/glow-compose/src/main/java/com/naulian/glow_compose/kotlin/KtLexer.kt
@@ -31,14 +31,14 @@ class KtLexer(private val input: String) {
'%' -> createToken(Type.MODULO, char)
'^' -> createToken(Type.POW, char)
'&' -> createToken(Type.AND, char)
- '?' -> createToken(Type.QUESTION_MARK, char)
+ '?' -> createToken(Type.QMARK, char)
'|' -> createToken(Type.OR, char)
'\\' -> createToken(Type.ESCAPE, char)
'!' -> createToken(Type.BANG, char)
- '{' -> createToken(Type.LEFT_BRACE, char)
- '}' -> createToken(Type.RIGHT_BRACE, char)
- '(' -> createToken(Type.LEFT_PARENTHESES, char)
- ')' -> createToken(Type.RIGHT_PARENTHESES, char)
+ '{' -> createToken(Type.LBRACE, char)
+ '}' -> createToken(Type.RBRACE, char)
+ '(' -> createToken(Type.LPAREN, char)
+ ')' -> createToken(Type.RPAREN, char)
',' -> createToken(Type.COMMA, char)
':' -> createToken(Type.COLON, char)
'>' -> createToken(Type.GT, char)
@@ -46,13 +46,13 @@ class KtLexer(private val input: String) {
';' -> createToken(Type.SEMICOLON, char)
'+' -> createToken(Type.PLUS, char)
'=' -> createToken(Type.ASSIGNMENT, char)
- '[' -> createToken(Type.LEFT_BRACKET, char)
- ']' -> createToken(Type.RIGHT_BRACKET, char)
+ '[' -> createToken(Type.LBRACK, char)
+ ']' -> createToken(Type.RBRACKET, char)
'/' -> {
when (input[position + 1]) {
'/' -> lexSingleLineComment()
'*' -> lexMultiLineComment()
- else -> createToken(Type.FORWARD_SLASH, char)
+ else -> createToken(Type.FSLASH, char)
}
}
@@ -72,7 +72,7 @@ class KtLexer(private val input: String) {
} while (currentChar() != '\n' && currentChar() != Char.MIN_VALUE)
val identifier = input.substring(start, position)
- return Token(Type.COMMENT_SINGLE, identifier)
+ return Token(Type.SCOMMENT, identifier)
}
private fun lexMultiLineComment(): Token {
@@ -83,7 +83,7 @@ class KtLexer(private val input: String) {
position++
val identifier = input.substring(start, position)
- return Token(Type.COMMENT_MULTI, identifier)
+ return Token(Type.MCOMMENT, identifier)
}
private fun createToken(type: Type, char: Char) = createToken(type, char.toString())
diff --git a/glow-compose/src/main/java/com/naulian/glow_compose/kotlin/KtTokens.kt b/glow-compose/src/main/java/com/naulian/glow_compose/kotlin/KtTokens.kt
index 3b59321..9806247 100644
--- a/glow-compose/src/main/java/com/naulian/glow_compose/kotlin/KtTokens.kt
+++ b/glow-compose/src/main/java/com/naulian/glow_compose/kotlin/KtTokens.kt
@@ -15,7 +15,7 @@ fun tokenizeKt(input: String): List {
while (token.type != Type.EOF && token.type != Type.ILLEGAL) {
//logDebug(TAG, token)
- if (token.type == Type.WHITE_SPACE) {
+ if (token.type == Type.SPACE) {
tokens.add(token)
token = lexer.nextToken()
continue
@@ -24,7 +24,7 @@ fun tokenizeKt(input: String): List {
//based on previous
val modified = when (prevToken.type) {
Type.ASSIGNMENT -> numberToken(token)
- Type.LEFT_PARENTHESES -> argumentToken(token)
+ Type.LPAREN -> argumentToken(token)
Type.FUNCTION -> token.copy(type = Type.FUNC_NAME)
Type.CLASS -> token.copy(type = Type.CLASS_NAME)
Type.COLON -> token.copy(type = Type.DATA_TYPE)
@@ -41,7 +41,7 @@ fun tokenizeKt(input: String): List {
}
}
- Type.LEFT_PARENTHESES -> {
+ Type.LPAREN -> {
tokens.getOrNull(prevIndex - 1)?.let {
if (it.type == Type.DOT) {
tokens[prevIndex] = prevToken.copy(type = Type.FUNC_CALL)
diff --git a/glow-core/build.gradle.kts b/glow-core/build.gradle.kts
index cb5f4e7..f648fa6 100644
--- a/glow-core/build.gradle.kts
+++ b/glow-core/build.gradle.kts
@@ -35,12 +35,12 @@ android {
dependencies {
- implementation("androidx.core:core-ktx:1.12.0")
- implementation("androidx.appcompat:appcompat:1.6.1")
- implementation("com.google.android.material:material:1.11.0")
- testImplementation("junit:junit:4.13.2")
- androidTestImplementation("androidx.test.ext:junit:1.1.5")
- androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
+ implementation(libs.androidx.core.ktx)
+ implementation(libs.androidx.appcompat)
+ implementation(libs.material)
+ testImplementation(libs.junit)
+ androidTestImplementation(libs.androidx.junit)
+ androidTestImplementation(libs.androidx.espresso.core)
}
android {
@@ -59,7 +59,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.naulian"
artifactId = "glow-core"
- version = "1.3.9"
+ version = "1.4.1"
}
}
}
diff --git a/glow-core/src/main/java/com/naulian/glow_core/TokenFile.kt b/glow-core/src/main/java/com/naulian/glow_core/SourceFile.kt
similarity index 100%
rename from glow-core/src/main/java/com/naulian/glow_core/TokenFile.kt
rename to glow-core/src/main/java/com/naulian/glow_core/SourceFile.kt
diff --git a/glow-core/src/main/java/com/naulian/glow_core/Type.kt b/glow-core/src/main/java/com/naulian/glow_core/Type.kt
index baf317d..aaaf211 100644
--- a/glow-core/src/main/java/com/naulian/glow_core/Type.kt
+++ b/glow-core/src/main/java/com/naulian/glow_core/Type.kt
@@ -5,7 +5,6 @@ enum class Type {
//White space
NEWLINE,
- SPACE,
WORD,
@@ -16,8 +15,8 @@ enum class Type {
//PUNCTUATION
AT,
DOT,
- SINGLE_QUOTE,
- DOUBLE_QUOTE,
+ SQUOTE,
+ DQUOTE,
VARIABLE,
EOF, //End of file
@@ -29,7 +28,7 @@ enum class Type {
HASH,
DOLLAR,
MODULO,
- QUESTION_MARK,
+ QMARK,
POW,
AND,
OR,
@@ -37,7 +36,7 @@ enum class Type {
PARAM,
ASTERISK,
ARGUMENT,
- WHITE_SPACE,
+ SPACE,
ASSIGNMENT,
PROPERTY,
CLASS,
@@ -61,16 +60,16 @@ enum class Type {
DATA_TYPE,
CLASS_NAME,
IDENTIFIER,
- LEFT_BRACE,
- RIGHT_BRACE,
- LEFT_PARENTHESES,
- RIGHT_PARENTHESES,
- LEFT_BRACKET,
- RIGHT_BRACKET,
- COMMENT_SINGLE,
- COMMENT_MULTI,
- FORWARD_SLASH,
- BACK_SLASH,
+ LBRACE,
+ RBRACE,
+ LPAREN,
+ RPAREN,
+ LBRACK,
+ RBRACKET,
+ SCOMMENT,
+ MCOMMENT,
+ FSLASH,
+ BSLASH,
INTERPOLATION,
STRING_BRACE
}
\ No newline at end of file
diff --git a/glow-core/src/main/java/com/naulian/glow_core/lang/kotlin/KotlinLexer.kt b/glow-core/src/main/java/com/naulian/glow_core/lang/kotlin/KotlinLexer.kt
new file mode 100644
index 0000000..6c32e29
--- /dev/null
+++ b/glow-core/src/main/java/com/naulian/glow_core/lang/kotlin/KotlinLexer.kt
@@ -0,0 +1,159 @@
+package com.naulian.glow_core.lang.kotlin
+
+import com.naulian.glow_core.Token
+import com.naulian.glow_core.Type
+import kotlin.math.min
+
+class KotlinLexer(private val source: CharSequence) {
+ private var position: Int = 0
+
+ private val keywords = listOf(
+ "abstract", "annotation", "as", "break", "by", "catch", "class", "companion", "const",
+ "constructor", "continue", "crossinline", "data", "do", "else", "enum", "external", "false",
+ "final", "finally", "for", "fun", "if", "in", "infix", "init", "inline", "inner",
+ "interface", "internal", "is", "it", "lateinit", "noinline", "null", "object", "open",
+ "operator", "out", "import", "override", "package", "private", "protected", "public",
+ "reified", "return", "sealed", "super", "suspend", "this", "throw", "to", "true", "try",
+ "typealias", "typeof", "val", "var", "when", "where", "while"
+ )
+
+ private fun currentChar() = if (position < source.length) source[position] else Char.MIN_VALUE
+
+ fun nextToken(): Token {
+ return when (val char = currentChar()) {
+ ' ' -> whitespaceToken()
+ '\n' -> createToken(Type.NEWLINE, "\n")
+ '*' -> createToken(Type.ASTERISK, char.toString())
+ '.' -> createToken(Type.DOT, char.toString())
+ '-' -> createToken(Type.DASH, char.toString())
+ '@' -> createToken(Type.AT, char.toString())
+ '#' -> createToken(Type.HASH, char.toString())
+ '$' -> createToken(Type.DOLLAR, char.toString())
+ '%' -> createToken(Type.MODULO, char.toString())
+ '^' -> createToken(Type.POW, char.toString())
+ '&' -> createToken(Type.AND, char.toString())
+ '?' -> createToken(Type.QMARK, char.toString())
+ '|' -> createToken(Type.OR, char.toString())
+ '\\' -> createToken(Type.ESCAPE, char.toString())
+ '!' -> createToken(Type.BANG, char.toString())
+ '{' -> createToken(Type.LBRACE, char.toString())
+ '}' -> createToken(Type.RBRACE, char.toString())
+ '(' -> createToken(Type.LPAREN, char.toString())
+ ')' -> createToken(Type.RPAREN, char.toString())
+ ',' -> createToken(Type.COMMA, char.toString())
+ ':' -> createToken(Type.COLON, char.toString())
+ '>' -> createToken(Type.GT, ">")
+ '<' -> createToken(Type.LT, "<")
+ ';' -> createToken(Type.SEMICOLON, char.toString())
+ '+' -> createToken(Type.PLUS, char.toString())
+ '=' -> createToken(Type.ASSIGNMENT, char.toString())
+ '[' -> createToken(Type.LBRACK, char.toString())
+ ']' -> createToken(Type.RBRACKET, char.toString())
+ '/' -> {
+ when (source[position + 1]) {
+ '/' -> lexSingleLineComment()
+ '*' -> lexMultiLineComment()
+ else -> createToken(Type.FSLASH, char.toString())
+ }
+ }
+
+ '\'' -> readChar()
+ '\"' -> readString()
+ in 'a'..'z', in 'A'..'Z', '_' -> readIdentifier()
+ in '0'..'9' -> readNumber()
+ Char.MIN_VALUE -> createToken(Type.EOF, char.toString())
+ else -> createToken(Type.ILLEGAL, char.toString())
+ }
+ }
+
+ private fun lexSingleLineComment(): Token {
+ val start = position
+ do {
+ position++
+ } while (currentChar() != '\n' && currentChar() != Char.MIN_VALUE)
+
+ val identifier = source.substring(start, position)
+ return Token(Type.SCOMMENT, identifier)
+ }
+
+ private fun lexMultiLineComment(): Token {
+ val start = position
+ do {
+ position++
+ } while (currentChar() != '/' && currentChar() != Char.MIN_VALUE)
+ position++
+
+ val identifier = source.substring(start, position)
+ return Token(Type.MCOMMENT, identifier)
+ }
+
+
+ private fun createToken(type: Type, value: String): Token {
+ position++
+ return Token(type, value)
+ }
+
+ private fun whitespaceToken(): Token {
+ val start = position
+ while (currentChar() == ' ') {
+ position++
+ }
+
+ val identifier = source.substring(start, position)
+ return Token(Type.SPACE, identifier)
+ }
+
+ private fun readIdentifier(): Token {
+ val start = position
+ while (currentChar().isLetter() || currentChar() == '_' || currentChar().isDigit()) {
+ position++
+ }
+
+ return when (val identifier = source.substring(start, position)) {
+ "var", "val" -> Token(Type.VARIABLE, identifier)
+ "fun" -> Token(Type.FUNCTION, identifier)
+ "class" -> Token(Type.CLASS, identifier)
+ in keywords -> Token(Type.KEYWORD, identifier)
+ else -> Token(Type.IDENTIFIER, identifier)
+ }
+ }
+
+ private fun readString(): Token {
+ val start = position
+ position++
+ while (currentChar() != '\"' && currentChar() != Char.MIN_VALUE) {
+ position++
+ }
+ position++
+
+ position = min(position, source.length)
+ val identifier = source.substring(start, position)
+ return Token(Type.STRING, identifier)
+ }
+
+ private fun readChar(): Token {
+ val start = position
+ position++
+ while (currentChar() != '\'' && currentChar() != Char.MIN_VALUE) {
+ position++
+ }
+ position++
+
+ position = min(position, source.length)
+ val identifier = source.substring(start, position)
+ return Token(Type.CHAR, identifier)
+ }
+
+ private fun readNumber(): Token {
+ val start = position
+
+ while (
+ currentChar().isDigit() || currentChar() == '_' ||
+ currentChar() == 'L' || currentChar() == 'f' ||
+ currentChar() == '.'
+ ) {
+ position++
+ }
+ return Token(Type.NUMBER, source.substring(start, position))
+ }
+}
\ No newline at end of file
diff --git a/glow/build.gradle.kts b/glow/build.gradle.kts
index 03741b1..53e4db4 100644
--- a/glow/build.gradle.kts
+++ b/glow/build.gradle.kts
@@ -35,14 +35,14 @@ android {
}
dependencies {
- implementation("androidx.core:core-ktx:1.12.0")
- implementation("androidx.appcompat:appcompat:1.6.1")
- implementation("com.google.android.material:material:1.11.0")
- testImplementation("junit:junit:4.13.2")
- androidTestImplementation("androidx.test.ext:junit:1.1.5")
- androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
+ implementation(libs.androidx.core.ktx)
+ implementation(libs.androidx.appcompat)
+ implementation(libs.material)
+ testImplementation(libs.junit)
+ androidTestImplementation(libs.androidx.junit)
+ androidTestImplementation(libs.androidx.espresso.core)
- implementation("com.naulian:anhance:2024.1.16")
+ implementation(libs.anhance)
implementation(project(":glow-core"))
}
@@ -63,7 +63,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.naulian"
artifactId = "glow"
- version = "1.3.9"
+ version = "1.4.1"
}
}
}
diff --git a/glow/src/main/java/com/naulian/glow/CharacterLexer.kt b/glow/src/main/java/com/naulian/glow/CharacterLexer.kt
index 8a4969b..c0d8063 100644
--- a/glow/src/main/java/com/naulian/glow/CharacterLexer.kt
+++ b/glow/src/main/java/com/naulian/glow/CharacterLexer.kt
@@ -34,14 +34,14 @@ abstract class CharacterLexer(private val input: String) {
'%' -> createToken(Type.MODULO, char)
'^' -> createToken(Type.POW, char)
'&' -> createToken(Type.AND, char)
- '?' -> createToken(Type.QUESTION_MARK, char)
+ '?' -> createToken(Type.QMARK, char)
'|' -> createToken(Type.OR, char)
- '\\' -> createToken(Type.FORWARD_SLASH, char)
+ '\\' -> createToken(Type.FSLASH, char)
'!' -> createToken(Type.BANG, char)
- '{' -> createToken(Type.LEFT_BRACE, char)
- '}' -> createToken(Type.RIGHT_BRACE, char)
- '(' -> createToken(Type.LEFT_PARENTHESES, char)
- ')' -> createToken(Type.RIGHT_PARENTHESES, char)
+ '{' -> createToken(Type.LBRACE, char)
+ '}' -> createToken(Type.RBRACE, char)
+ '(' -> createToken(Type.LPAREN, char)
+ ')' -> createToken(Type.RPAREN, char)
',' -> createToken(Type.COMMA, char)
':' -> createToken(Type.COLON, char)
'>' -> createToken(Type.GT, char)
@@ -49,11 +49,11 @@ abstract class CharacterLexer(private val input: String) {
';' -> createToken(Type.SEMICOLON, char)
'+' -> createToken(Type.PLUS, char)
'=' -> createToken(Type.ASSIGNMENT, char)
- '[' -> createToken(Type.LEFT_BRACKET, char)
- ']' -> createToken(Type.RIGHT_BRACKET, char)
- '/' -> createToken(Type.BACK_SLASH, char)
- '\'' -> createToken(Type.SINGLE_QUOTE, char)
- '\"' -> createToken(Type.DOUBLE_QUOTE, char)
+ '[' -> createToken(Type.LBRACK, char)
+ ']' -> createToken(Type.RBRACKET, char)
+ '/' -> createToken(Type.BSLASH, char)
+ '\'' -> createToken(Type.SQUOTE, char)
+ '\"' -> createToken(Type.DQUOTE, char)
in 'a'..'z', in 'A'..'Z', '_' -> readIdentifier()
in '0'..'9' -> readNumber()
Char.MIN_VALUE -> createToken(Type.EOF, char)
diff --git a/glow/src/main/java/com/naulian/glow/Glow.kt b/glow/src/main/java/com/naulian/glow/Glow.kt
index cd8b663..782b603 100644
--- a/glow/src/main/java/com/naulian/glow/Glow.kt
+++ b/glow/src/main/java/com/naulian/glow/Glow.kt
@@ -84,8 +84,8 @@ object Glow {
Type.CHAR -> it.value.color(theme.string)
Type.STRING -> it.value.color(theme.string)
Type.ASSIGNMENT -> it.value.color(theme.normal)
- Type.COMMENT_MULTI -> it.value.color(theme.comment)
- Type.COMMENT_SINGLE -> it.value.color(theme.comment)
+ Type.MCOMMENT -> it.value.color(theme.comment)
+ Type.SCOMMENT -> it.value.color(theme.comment)
else -> it.value
}
builder.append(code)
@@ -119,8 +119,8 @@ object Glow {
Type.CHAR -> it.value.color(theme.string)
Type.STRING -> it.value.color(theme.string)
Type.ASSIGNMENT -> it.value.color(theme.normal)
- Type.COMMENT_MULTI -> it.value.color(theme.comment)
- Type.COMMENT_SINGLE -> it.value.color(theme.comment)
+ Type.MCOMMENT -> it.value.color(theme.comment)
+ Type.SCOMMENT -> it.value.color(theme.comment)
else -> it.value
}
builder.append(code)
@@ -153,7 +153,7 @@ object Glow {
Type.VALUE_FLOAT -> it.value.color(theme.number)
Type.STRING -> it.value.color(theme.string)
Type.ASSIGNMENT -> it.value.color(theme.normal)
- Type.COMMENT_SINGLE -> it.value.color(theme.comment)
+ Type.SCOMMENT -> it.value.color(theme.comment)
else -> it.value
}
builder.append(code)
@@ -192,8 +192,8 @@ object Glow {
Type.INTERPOLATION -> it.value.color(theme.property)
Type.ASSIGNMENT -> it.value.color(theme.normal)
Type.ESCAPE -> it.value.color(theme.keyword)
- Type.COMMENT_MULTI -> it.value.color(theme.comment)
- Type.COMMENT_SINGLE -> it.value.color(theme.comment)
+ Type.MCOMMENT -> it.value.color(theme.comment)
+ Type.SCOMMENT -> it.value.color(theme.comment)
else -> it.value
}
builder.append(code)
diff --git a/glow/src/main/java/com/naulian/glow/language/kotlin/KtLexer.kt b/glow/src/main/java/com/naulian/glow/language/kotlin/KtLexer.kt
index 76f3886..96db7a8 100644
--- a/glow/src/main/java/com/naulian/glow/language/kotlin/KtLexer.kt
+++ b/glow/src/main/java/com/naulian/glow/language/kotlin/KtLexer.kt
@@ -31,14 +31,14 @@ class KtLexer(private val input: String) {
'%' -> createToken(Type.MODULO, char.toString())
'^' -> createToken(Type.POW, char.toString())
'&' -> createToken(Type.AND, char.toString())
- '?' -> createToken(Type.QUESTION_MARK, char.toString())
+ '?' -> createToken(Type.QMARK, char.toString())
'|' -> createToken(Type.OR, char.toString())
'\\' -> createToken(Type.ESCAPE, char.toString())
'!' -> createToken(Type.BANG, char.toString())
- '{' -> createToken(Type.LEFT_BRACE, char.toString())
- '}' -> createToken(Type.RIGHT_BRACE, char.toString())
- '(' -> createToken(Type.LEFT_PARENTHESES, char.toString())
- ')' -> createToken(Type.RIGHT_PARENTHESES, char.toString())
+ '{' -> createToken(Type.LBRACE, char.toString())
+ '}' -> createToken(Type.RBRACE, char.toString())
+ '(' -> createToken(Type.LPAREN, char.toString())
+ ')' -> createToken(Type.RPAREN, char.toString())
',' -> createToken(Type.COMMA, char.toString())
':' -> createToken(Type.COLON, char.toString())
'>' -> createToken(Type.GT, ">")
@@ -46,13 +46,13 @@ class KtLexer(private val input: String) {
';' -> createToken(Type.SEMICOLON, char.toString())
'+' -> createToken(Type.PLUS, char.toString())
'=' -> createToken(Type.ASSIGNMENT, char.toString())
- '[' -> createToken(Type.LEFT_BRACKET, char.toString())
- ']' -> createToken(Type.RIGHT_BRACKET, char.toString())
+ '[' -> createToken(Type.LBRACK, char.toString())
+ ']' -> createToken(Type.RBRACKET, char.toString())
'/' -> {
when (input[position + 1]) {
'/' -> lexSingleLineComment()
'*' -> lexMultiLineComment()
- else -> createToken(Type.FORWARD_SLASH, char.toString())
+ else -> createToken(Type.FSLASH, char.toString())
}
}
@@ -72,7 +72,7 @@ class KtLexer(private val input: String) {
} while (currentChar() != '\n' && currentChar() != Char.MIN_VALUE)
val identifier = input.substring(start, position)
- return Token(Type.COMMENT_SINGLE, identifier)
+ return Token(Type.SCOMMENT, identifier)
}
private fun lexMultiLineComment(): Token {
@@ -83,7 +83,7 @@ class KtLexer(private val input: String) {
position++
val identifier = input.substring(start, position)
- return Token(Type.COMMENT_MULTI, identifier)
+ return Token(Type.MCOMMENT, identifier)
}
diff --git a/glow/src/main/java/com/naulian/glow/language/kotlin/KtTokens.kt b/glow/src/main/java/com/naulian/glow/language/kotlin/KtTokens.kt
index 7416697..83a21b3 100644
--- a/glow/src/main/java/com/naulian/glow/language/kotlin/KtTokens.kt
+++ b/glow/src/main/java/com/naulian/glow/language/kotlin/KtTokens.kt
@@ -15,7 +15,7 @@ fun tokenizeKt(input: String): List {
while (token.type != Type.EOF && token.type != Type.ILLEGAL) {
//logDebug(TAG, token)
- if (token.type == Type.WHITE_SPACE) {
+ if (token.type == Type.SPACE) {
tokens.add(token)
token = lexer.nextToken()
continue
@@ -24,7 +24,7 @@ fun tokenizeKt(input: String): List {
//based on previous
val modified = when (prevToken.type) {
Type.ASSIGNMENT -> numberToken(token)
- Type.LEFT_PARENTHESES -> argumentToken(token)
+ Type.LPAREN -> argumentToken(token)
Type.FUNCTION -> token.copy(type = Type.FUNC_NAME)
Type.CLASS -> token.copy(type = Type.CLASS_NAME)
Type.COLON -> token.copy(type = Type.DATA_TYPE)
@@ -41,7 +41,7 @@ fun tokenizeKt(input: String): List {
}
}
- Type.LEFT_PARENTHESES -> {
+ Type.LPAREN -> {
tokens.getOrNull(prevIndex - 1)?.let {
if (it.type == Type.DOT) {
tokens[prevIndex] = prevToken.copy(type = Type.FUNC_CALL)
diff --git a/glow/src/main/java/com/naulian/glow/tokens/JTokens.kt b/glow/src/main/java/com/naulian/glow/tokens/JTokens.kt
index a0e6301..af43a27 100644
--- a/glow/src/main/java/com/naulian/glow/tokens/JTokens.kt
+++ b/glow/src/main/java/com/naulian/glow/tokens/JTokens.kt
@@ -20,7 +20,7 @@ object JTokens {
while (token.type != Type.EOF && token.type != Type.ILLEGAL) {
//logDebug(TAG, token)
- if (token.type == Type.WHITE_SPACE) {
+ if (token.type == Type.SPACE) {
tokens.add(token)
token = lexer.nextToken()
continue
@@ -29,7 +29,7 @@ object JTokens {
//based on previous
val modified = when (prevToken.type) {
Type.ASSIGNMENT -> numberToken(token)
- Type.LEFT_PARENTHESES -> argumentToken(token)
+ Type.LPAREN -> argumentToken(token)
Type.FUNCTION -> token.copy(type = Type.FUNC_NAME)
Type.CLASS -> token.copy(type = Type.CLASS_NAME)
Type.COLON -> token.copy(type = Type.DATA_TYPE)
@@ -46,7 +46,7 @@ object JTokens {
}
}
- Type.LEFT_PARENTHESES -> {
+ Type.LPAREN -> {
if (prevToken.type == Type.VAR_NAME) {
tokens[prevIndex] = prevToken.copy(type = Type.FUNC_NAME)
}
@@ -58,9 +58,9 @@ object JTokens {
}
}
- Type.RIGHT_BRACKET -> {
+ Type.RBRACKET -> {
if (prevToken.type == Type.VAR_NAME) {
- tokens[prevIndex] = prevToken.copy(type = Type.LEFT_BRACKET)
+ tokens[prevIndex] = prevToken.copy(type = Type.LBRACK)
}
}
@@ -119,14 +119,14 @@ private class JLexer(private val input: String) {
'%' -> createToken(Type.MODULO, c.toString())
'^' -> createToken(Type.POW, c.toString())
'&' -> createToken(Type.AND, c.toString())
- '?' -> createToken(Type.QUESTION_MARK, c.toString())
+ '?' -> createToken(Type.QMARK, c.toString())
'|' -> createToken(Type.OR, c.toString())
'\\' -> createToken(Type.ESCAPE, c.toString())
'!' -> createToken(Type.BANG, c.toString())
- '{' -> createToken(Type.LEFT_BRACE, c.toString())
- '}' -> createToken(Type.RIGHT_BRACE, c.toString())
- '(' -> createToken(Type.LEFT_PARENTHESES, c.toString())
- ')' -> createToken(Type.RIGHT_PARENTHESES, c.toString())
+ '{' -> createToken(Type.LBRACE, c.toString())
+ '}' -> createToken(Type.RBRACE, c.toString())
+ '(' -> createToken(Type.LPAREN, c.toString())
+ ')' -> createToken(Type.RPAREN, c.toString())
',' -> createToken(Type.COMMA, c.toString())
':' -> createToken(Type.COLON, c.toString())
'>' -> createToken(Type.GT, ">")
@@ -134,13 +134,13 @@ private class JLexer(private val input: String) {
';' -> createToken(Type.SEMICOLON, c.toString())
'+' -> createToken(Type.PLUS, c.toString())
'=' -> createToken(Type.ASSIGNMENT, c.toString())
- '[' -> createToken(Type.LEFT_BRACKET, c.toString())
- ']' -> createToken(Type.RIGHT_BRACKET, c.toString())
+ '[' -> createToken(Type.LBRACK, c.toString())
+ ']' -> createToken(Type.RBRACKET, c.toString())
'/' -> {
when (input[position + 1]) {
'/' -> lexSingleLineComment()
'*' -> lexMultiLineComment()
- else -> createToken(Type.FORWARD_SLASH, c.toString())
+ else -> createToken(Type.FSLASH, c.toString())
}
}
@@ -160,7 +160,7 @@ private class JLexer(private val input: String) {
} while (char != '\n' && char != Char.MIN_VALUE)
val identifier = input.substring(start, position)
- return Token(Type.COMMENT_SINGLE, identifier)
+ return Token(Type.SCOMMENT, identifier)
}
private fun lexMultiLineComment(): Token {
@@ -173,7 +173,7 @@ private class JLexer(private val input: String) {
val identifier = input.substring(start, position)
logDebug(identifier)
- return Token(Type.COMMENT_MULTI, identifier)
+ return Token(Type.MCOMMENT, identifier)
}
@@ -189,7 +189,7 @@ private class JLexer(private val input: String) {
}
val indentifier = input.substring(start, position)
- return Token(Type.WHITE_SPACE, indentifier)
+ return Token(Type.SPACE, indentifier)
}
private fun readIdentifier(): Token {
diff --git a/glow/src/main/java/com/naulian/glow/tokens/JsTokens.kt b/glow/src/main/java/com/naulian/glow/tokens/JsTokens.kt
index 12c6ead..6897e75 100644
--- a/glow/src/main/java/com/naulian/glow/tokens/JsTokens.kt
+++ b/glow/src/main/java/com/naulian/glow/tokens/JsTokens.kt
@@ -19,7 +19,7 @@ object JsTokens {
while (token.type != Type.EOF && token.type != Type.ILLEGAL) {
//logDebug(TAG, token)
- if (token.type == Type.WHITE_SPACE) {
+ if (token.type == Type.SPACE) {
tokens.add(token)
token = lexer.nextToken()
continue
@@ -28,7 +28,7 @@ object JsTokens {
//based on previous
val modified = when (prevToken.type) {
Type.ASSIGNMENT -> numberToken(token)
- Type.LEFT_PARENTHESES -> argumentToken(token)
+ Type.LPAREN -> argumentToken(token)
Type.FUNCTION -> token.copy(type = Type.FUNC_NAME)
Type.CLASS -> token.copy(type = Type.CLASS_NAME)
Type.COLON -> token.copy(type = Type.DATA_TYPE)
@@ -44,7 +44,7 @@ object JsTokens {
}
}
- Type.LEFT_PARENTHESES -> {
+ Type.LPAREN -> {
tokens.getOrNull(prevIndex - 1)?.let {
if (it.type == Type.DOT) {
tokens[prevIndex] = prevToken.copy(type = Type.FUNC_CALL)
@@ -105,14 +105,14 @@ private class JsLexer(private val input: String) {
'%' -> createToken(Type.MODULO, char.toString())
'^' -> createToken(Type.POW, char.toString())
'&' -> createToken(Type.AND, char.toString())
- '?' -> createToken(Type.QUESTION_MARK, char.toString())
+ '?' -> createToken(Type.QMARK, char.toString())
'|' -> createToken(Type.OR, char.toString())
'\\' -> createToken(Type.ESCAPE, char.toString())
'!' -> createToken(Type.BANG, char.toString())
- '{' -> createToken(Type.LEFT_BRACE, char.toString())
- '}' -> createToken(Type.RIGHT_BRACE, char.toString())
- '(' -> createToken(Type.LEFT_PARENTHESES, char.toString())
- ')' -> createToken(Type.RIGHT_PARENTHESES, char.toString())
+ '{' -> createToken(Type.LBRACE, char.toString())
+ '}' -> createToken(Type.RBRACE, char.toString())
+ '(' -> createToken(Type.LPAREN, char.toString())
+ ')' -> createToken(Type.RPAREN, char.toString())
',' -> createToken(Type.COMMA, char.toString())
':' -> createToken(Type.COLON, char.toString())
'>' -> createToken(Type.GT, ">")
@@ -120,13 +120,13 @@ private class JsLexer(private val input: String) {
';' -> createToken(Type.SEMICOLON, char.toString())
'+' -> createToken(Type.PLUS, char.toString())
'=' -> createToken(Type.ASSIGNMENT, char.toString())
- '[' -> createToken(Type.LEFT_BRACKET, char.toString())
- ']' -> createToken(Type.RIGHT_BRACKET, char.toString())
+ '[' -> createToken(Type.LBRACK, char.toString())
+ ']' -> createToken(Type.RBRACKET, char.toString())
'/' -> {
when (input[position + 1]) {
'/' -> lexSingleLineComment()
'*' -> lexMultiLineComment()
- else -> createToken(Type.FORWARD_SLASH, char.toString())
+ else -> createToken(Type.FSLASH, char.toString())
}
}
@@ -147,7 +147,7 @@ private class JsLexer(private val input: String) {
} while (currentChar() != '\n' && currentChar() != Char.MIN_VALUE)
val identifier = input.substring(start, position)
- return Token(Type.COMMENT_SINGLE, identifier)
+ return Token(Type.SCOMMENT, identifier)
}
private fun lexMultiLineComment(): Token {
@@ -158,7 +158,7 @@ private class JsLexer(private val input: String) {
position++
val identifier = input.substring(start, position)
- return Token(Type.COMMENT_MULTI, identifier)
+ return Token(Type.MCOMMENT, identifier)
}
@@ -174,7 +174,7 @@ private class JsLexer(private val input: String) {
}
val indentifier = input.substring(start, position)
- return Token(Type.WHITE_SPACE, indentifier)
+ return Token(Type.SPACE, indentifier)
}
private fun readIdentifier(): Token {
diff --git a/glow/src/main/java/com/naulian/glow/tokens/PTokens.kt b/glow/src/main/java/com/naulian/glow/tokens/PTokens.kt
index c47a7fb..3ce3956 100644
--- a/glow/src/main/java/com/naulian/glow/tokens/PTokens.kt
+++ b/glow/src/main/java/com/naulian/glow/tokens/PTokens.kt
@@ -30,7 +30,7 @@ object PTokens {
while (token.type != Type.EOF && token.type != Type.ILLEGAL) {
//logDebug(TAG, token)
- if (token.type == Type.WHITE_SPACE) {
+ if (token.type == Type.SPACE) {
tokens.add(token)
token = lexer.nextToken()
continue
@@ -39,7 +39,7 @@ object PTokens {
//based on previous
val modified = when (prevToken.type) {
Type.ASSIGNMENT -> numberToken(token)
- Type.LEFT_PARENTHESES -> argumentToken(token)
+ Type.LPAREN -> argumentToken(token)
Type.FUNCTION -> token.copy(type = Type.FUNC_NAME)
Type.CLASS -> token.copy(type = Type.CLASS_NAME)
Type.COLON -> token.copy(type = Type.DATA_TYPE)
@@ -55,7 +55,7 @@ object PTokens {
tokens[prevIndex] = prevToken.copy(type = Type.PARAM)
}
}
- Type.LEFT_PARENTHESES -> {
+ Type.LPAREN -> {
tokens.getOrNull(prevIndex - 1)?.let {
if(it.type == Type.DOT){
tokens[prevIndex] = prevToken.copy(type = Type.FUNC_CALL)
@@ -116,14 +116,14 @@ private class PLexer(private val input: String) {
'%' -> createToken(Type.MODULO, char.toString())
'^' -> createToken(Type.POW, char.toString())
'&' -> createToken(Type.AND, char.toString())
- '?' -> createToken(Type.QUESTION_MARK, char.toString())
+ '?' -> createToken(Type.QMARK, char.toString())
'|' -> createToken(Type.OR, char.toString())
'\\' -> createToken(Type.ESCAPE, char.toString())
'!' -> createToken(Type.BANG, char.toString())
- '{' -> createToken(Type.LEFT_BRACE, char.toString())
- '}' -> createToken(Type.RIGHT_BRACE, char.toString())
- '(' -> createToken(Type.LEFT_PARENTHESES, char.toString())
- ')' -> createToken(Type.RIGHT_PARENTHESES, char.toString())
+ '{' -> createToken(Type.LBRACE, char.toString())
+ '}' -> createToken(Type.RBRACE, char.toString())
+ '(' -> createToken(Type.LPAREN, char.toString())
+ ')' -> createToken(Type.RPAREN, char.toString())
',' -> createToken(Type.COMMA, char.toString())
':' -> createToken(Type.COLON, char.toString())
'>' -> createToken(Type.GT, ">")
@@ -131,9 +131,9 @@ private class PLexer(private val input: String) {
';' -> createToken(Type.SEMICOLON, char.toString())
'+' -> createToken(Type.PLUS, char.toString())
'=' -> createToken(Type.ASSIGNMENT, char.toString())
- '/' -> createToken(Type.FORWARD_SLASH, char.toString())
- '[' -> createToken(Type.LEFT_BRACKET, char.toString())
- ']' -> createToken(Type.RIGHT_BRACKET, char.toString())
+ '/' -> createToken(Type.FSLASH, char.toString())
+ '[' -> createToken(Type.LBRACK, char.toString())
+ ']' -> createToken(Type.RBRACKET, char.toString())
'#' -> readComments()
'\'' -> readSingleQString()
'\"' -> readDoubleQString()
@@ -151,7 +151,7 @@ private class PLexer(private val input: String) {
} while (currentChar() != '\n' && currentChar() != Char.MIN_VALUE)
val identifier = input.substring(start, position)
- return Token(Type.COMMENT_SINGLE, identifier)
+ return Token(Type.SCOMMENT, identifier)
}
private fun createToken(type: Type, value: String): Token {
@@ -170,7 +170,7 @@ private class PLexer(private val input: String) {
}
val identifier = input.substring(start, position)
- return Token(Type.WHITE_SPACE, identifier)
+ return Token(Type.SPACE, identifier)
}
private fun readIdentifier(): Token {
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
new file mode 100644
index 0000000..ef84136
--- /dev/null
+++ b/gradle/libs.versions.toml
@@ -0,0 +1,31 @@
+[versions]
+anhance = "2024.3.0"
+appcompat = "1.6.1"
+composeBom = "2024.05.00"
+constraintlayout = "2.1.4"
+coreKtx = "1.13.1"
+espressoCore = "3.5.1"
+junit = "4.13.2"
+junitVersion = "1.1.5"
+material = "1.12.0"
+
+[libraries]
+androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
+
+# compose
+androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "composeBom" }
+androidx-compose-ui = { module = "androidx.compose.ui:ui" }
+androidx-compose-ui-graphic = { module = "androidx.compose.ui:ui-graphics" }
+androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" }
+androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
+androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
+
+androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }
+androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }
+androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espressoCore" }
+androidx-junit = { module = "androidx.test.ext:junit", version.ref = "junitVersion" }
+anhance = { module = "com.naulian:anhance", version.ref = "anhance" }
+junit = { module = "junit:junit", version.ref = "junit" }
+material = { module = "com.google.android.material:material", version.ref = "material" }
+[plugins]
+