Skip to content

Commit

Permalink
release 1.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
cinkhangin committed Sep 4, 2024
1 parent fa99afa commit a4be6c7
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 51 deletions.
11 changes: 0 additions & 11 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glow-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.naulian"
artifactId = "glow-compose"
version = "1.6.3"
version = "1.6.4"
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions glow-compose/src/main/java/com/naulian/glow_compose/mdx/Mdx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import com.naulian.modify.table.Table
fun MdxBlock(
modifier: Modifier = Modifier,
source: String,
onClickLink: (String) -> Unit = {},
onClickLink: ((String) -> Unit)? = null,
components: MdxComponents = mdxComponents(),
contentSpacing: Dp = 12.dp
) {
Expand All @@ -76,7 +76,7 @@ fun MdxBlock(
}

@Composable
fun HandleNode(node: MdxNode, components: MdxComponents, onClickLink: (String) -> Unit) {
fun HandleNode(node: MdxNode, components: MdxComponents, onClickLink: ((String) -> Unit)?) {
node.children.forEach {
when (it.type) {
MdxType.PARAGRAPH -> components.paragraph(it, onClickLink)
Expand Down Expand Up @@ -153,7 +153,7 @@ data class MdxComponents(
style: TextStyle,
onClickLink: (String) -> Unit
) -> Unit,
val paragraph: @Composable (MdxNode, onClickLink: (String) -> Unit) -> Unit,
val paragraph: @Composable (MdxNode, onClickLink: ((String) -> Unit)?) -> Unit,
val header: @Composable (MdxNode) -> Unit,
val quote: @Composable (MdxNode) -> Unit,
val codeBlock: @Composable (MdxNode) -> Unit,
Expand Down Expand Up @@ -189,7 +189,7 @@ fun mdxComponents(
text: @Composable (
node: MdxNode,
style: TextStyle,
onClickLink: (String) -> Unit
onClickLink: ((String) -> Unit)?
) -> Unit = { node, style, onClickLink ->
when {
node.children.isEmpty() && node.literal.isBlank() -> {}
Expand All @@ -202,12 +202,16 @@ fun mdxComponents(
paragraphContent.annotatedString.getStringAnnotations(
start = offset,
end = offset
).firstOrNull()?.let { paragraphContent.linkMap[it.tag]?.let(onClickLink) }
).firstOrNull()?.let {
paragraphContent.linkMap[it.tag]?.let { url ->
onClickLink?.invoke(url)
}
}
}
}
}
},
paragraph: @Composable (MdxNode, onClickLink: (String) -> Unit) -> Unit = { node, onClickLink ->
paragraph: @Composable (MdxNode, onClickLink: ((String) -> Unit)?) -> Unit = { node, onClickLink ->
text(node, textStyle, onClickLink)
},
header: @Composable (MdxNode) -> Unit = { node ->
Expand Down
2 changes: 1 addition & 1 deletion glow-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.naulian"
artifactId = "glow-core"
version = "1.6.3"
version = "1.6.4"
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions glow-core/src/main/java/com/naulian/glow_core/Lexer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,27 @@ private val symbols = listOf(
'<', ';', '+', '=', '[', ']', '/', '\'', '\"',
)

abstract class BaseLexer {
abstract fun tokenize(): List<Token>
abstract fun next(): Token
}

class Lexer(private val source: CharSequence) {
private var cursor: Int = 0
private fun char() = if (cursor < source.length) source[cursor] else Char.MIN_VALUE

fun tokenize(): List<Token> {
val tokens = mutableListOf<Token>()
var token = nextToken()

while (token.type != Type.EOF && token.type != Type.ILLEGAL) {
tokens.add(token)
token = nextToken()
}

return tokens
}

fun nextToken(): Token {
return when (val c = char()) {
' ' -> createSpaceToken()
Expand Down
16 changes: 0 additions & 16 deletions glow-core/src/main/java/com/naulian/glow_core/Tokenizer.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.naulian.glow_core.lang.kotlin

import com.naulian.glow_core.Lexer
import com.naulian.glow_core.Token
import com.naulian.glow_core.Tokenizer
import com.naulian.glow_core.Type

private val kotlinKeywords = listOf(
Expand All @@ -14,8 +14,8 @@ private val kotlinKeywords = listOf(
"typealias", "typeof", "val", "var", "when", "where", "while"
)

class KTokenizer(input: String) {
private var basicTokens: List<Token> = Tokenizer(input).tokenize()
class KtLexer(input: String) {
private var basicTokens: List<Token> = Lexer(input).tokenize()
private var cursor = 0

fun tokenize(): List<Token> {
Expand Down Expand Up @@ -99,16 +99,16 @@ class KTokenizer(input: String) {
val subList = basicTokens.subList(from, cursor)
return Token(Type.STRING, subList.joinToString(""))
}
}

private fun argumentToken(token: Token): Token {
return if (token.type != Type.IDENTIFIER) token
else token.copy(type = Type.ARGUMENT)
}

private fun numberToken(token: Token): Token {
if (token.type != Type.NUMBER) return token
return if (token.value.contains("L")) token.copy(type = Type.VALUE_LONG)
else if (token.value.contains("f")) token.copy(type = Type.VALUE_FLOAT)
else token.copy(type = Type.VALUE_INT)

private fun argumentToken(token: Token): Token {
return if (token.type != Type.IDENTIFIER) token
else token.copy(type = Type.ARGUMENT)
}

private fun numberToken(token: Token): Token {
if (token.type != Type.NUMBER) return token
return if (token.value.contains("L")) token.copy(type = Type.VALUE_LONG)
else if (token.value.contains("f")) token.copy(type = Type.VALUE_FLOAT)
else token.copy(type = Type.VALUE_INT)
}
}
2 changes: 1 addition & 1 deletion glow/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.naulian"
artifactId = "glow"
version = "1.6.3"
version = "1.6.4"
}
}
}
Expand Down

0 comments on commit a4be6c7

Please sign in to comment.