Skip to content

Commit

Permalink
Add iOS targets to applicable artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
wingio committed Jul 24, 2024
1 parent d2efac8 commit 0d1f394
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
jobs:
build:
timeout-minutes: 60
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
jobs:
release:
timeout-minutes: 60
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v2

Expand Down
4 changes: 4 additions & 0 deletions syntakts-compose-material3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ kotlin {
}
jvm()

iosX64()
iosArm64()
iosSimulatorArm64()

jvmToolchain(17)
explicitApi()

Expand Down
4 changes: 4 additions & 0 deletions syntakts-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ kotlin {
}
jvm()

iosX64()
iosArm64()
iosSimulatorArm64()

jvmToolchain(17)
explicitApi()

Expand Down
10 changes: 9 additions & 1 deletion syntakts-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
kotlin("multiplatform")
id("com.android.library")
Expand All @@ -12,11 +14,17 @@ setup(
)

kotlin {
androidTarget() {
androidTarget {
publishLibraryVariants("release")
}
jvm()

iosX64()
iosArm64()
iosSimulatorArm64()
macosX64()
macosArm64()

jvmToolchain(17)
explicitApi()

Expand Down

This file was deleted.

43 changes: 27 additions & 16 deletions syntakts-core/src/commonMain/kotlin/xyz/wingio/syntakts/Syntakts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import xyz.wingio.syntakts.parser.Rule
import xyz.wingio.syntakts.parser.addTextRule
import xyz.wingio.syntakts.style.StyledTextBuilder
import xyz.wingio.syntakts.util.Logger
import xyz.wingio.syntakts.util.LoggerImpl
import xyz.wingio.syntakts.util.SynchronizedCache
import xyz.wingio.syntakts.util.Stack
import xyz.wingio.syntakts.util.firstMapOrNull
import kotlin.time.measureTime

/**
* The base class used to parse any input string into AST [Node]s from as set of [Rule]s
Expand All @@ -37,7 +37,7 @@ public class Syntakts<C> internal constructor(
@Stable
public data class DebugOptions(
var enableLogging: Boolean = false,
var logger: Logger = LoggerImpl(tag = "Syntakts"),
var logger: Logger? = null,
var storeMetadata: Boolean = false
)

Expand Down Expand Up @@ -208,7 +208,7 @@ public class Syntakts<C> internal constructor(
// Make sure parameters here match the DebugOptions data class
public fun debugOptions(
enableLogging: Boolean = false,
logger: Logger = LoggerImpl(tag = "Syntakts"),
logger: Logger? = null,
storeMetadata: Boolean = false
): Builder<C> {
debugOptions = DebugOptions(
Expand All @@ -235,7 +235,7 @@ public class Syntakts<C> internal constructor(
* Log a message to stdout with a defined prefix
*/
private fun log(message: String) {
if(debugOptions.enableLogging) debugOptions.logger.debug(message)
if(debugOptions.enableLogging) debugOptions.logger?.debug(message)
}

private val cache: SynchronizedCache<String, MatchResult> = SynchronizedCache()
Expand All @@ -250,17 +250,17 @@ public class Syntakts<C> internal constructor(
public fun parse(
text: CharSequence
): List<Node<C>> {
val start = System.currentTimeMillis()
val remainingParses = Stack<ParseSpec<C>>()
val rootNode = Node<C>()

var lastCapture: String? = null
val duration = measureTime {
var lastCapture: String? = null

if(text.isNotEmpty()) {
remainingParses.add(ParseSpec(rootNode, 0, text.length))
}
if (text.isNotEmpty()) {
remainingParses.add(ParseSpec(rootNode, 0, text.length))
}

while (!remainingParses.isEmpty()) {
while (!remainingParses.isEmpty()) {
val builder = remainingParses.pop()

if (builder.startIndex >= builder.endIndex) {
Expand All @@ -274,11 +274,11 @@ public class Syntakts<C> internal constructor(
rules.firstMapOrNull { rule ->
val key = "${rule.regex}-$inspectionSource-$lastCapture"

val matchResult = if(cache.hasKey(key))
val matchResult = if (cache.hasKey(key))
cache[key]
else
rule.match(inspectionSource, lastCapture).apply {
if(cache.size > 10_000) cache.removeFirst()
if (cache.size > 10_000) cache.removeFirst()
cache[key] = this
}

Expand All @@ -295,7 +295,7 @@ public class Syntakts<C> internal constructor(
val matcherSourceEnd = matchResult.range.last + offset + 1
val newBuilder = rule.parse(matchResult)

if(debugOptions.storeMetadata) {
if (debugOptions.storeMetadata) {
newBuilder.root.setMetadata(rule.name, rule.regex, matchResult)
}

Expand All @@ -305,7 +305,13 @@ public class Syntakts<C> internal constructor(
// In case the last match didn't consume the rest of the source for this subtree,
// make sure the rest of the source is consumed.
if (matcherSourceEnd != builder.endIndex) {
remainingParses.push(ParseSpec.createNonterminal(parent, matcherSourceEnd, builder.endIndex))
remainingParses.push(
ParseSpec.createNonterminal(
parent,
matcherSourceEnd,
builder.endIndex
)
)
}

// We want to speak in terms of indices within the source string,
Expand All @@ -319,12 +325,17 @@ public class Syntakts<C> internal constructor(
try {
lastCapture = matchResult.groups[0]!!.value
} catch (throwable: Throwable) {
throw ParseException(message = "matcher found no matches", source = text, cause = throwable)
throw ParseException(
message = "matcher found no matches",
source = text,
cause = throwable
)
}
}
}

val ast = rootNode.children?.toMutableList()
log("Finished in ${System.currentTimeMillis() - start}ms")
log("Finished in ${duration.inWholeMilliseconds}ms")
return ast ?: arrayListOf()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,4 @@ public interface Logger {
*/
public fun error(message: String, throwable: Throwable? = null)

}

/**
* Uses [println] on jvm and Log on Android
*
* @param tag Printed alongside each message for better locating
*/
internal expect class LoggerImpl internal constructor(tag: String): Logger
}

This file was deleted.

0 comments on commit 0d1f394

Please sign in to comment.