-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
setVersion
and unicode class names bugs.
- Loading branch information
1 parent
ff246a3
commit f0e82a5
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
Submodule acceptance-tests
updated
from d33303 to c0e7d1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../core/src/commonMain/kotlin/co/touchlab/skie/phases/sir/RenameNonAsciiDeclarationPhase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package co.touchlab.skie.phases.sir | ||
|
||
import co.touchlab.skie.oir.element.OirConstructor | ||
import co.touchlab.skie.oir.element.OirProperty | ||
import co.touchlab.skie.oir.element.OirSimpleFunction | ||
import co.touchlab.skie.phases.SirPhase | ||
import co.touchlab.skie.util.resolveCollisionWithWarning | ||
|
||
object RenameNonAsciiDeclarationPhase: SirPhase { | ||
private val firstCharAllowedChars: Set<Char> = (('a'..'z') + ('A' .. 'Z') + '_').toSet() | ||
private val nextCharAllowedChars: Set<Char> = firstCharAllowedChars + ('0' .. '9') | ||
|
||
context(SirPhase.Context) | ||
override suspend fun execute() { | ||
oirProvider.kotlinClassesAndProtocols | ||
.filterNot { isValidAsciiIdentifier(it.originalSirClass.baseName) } | ||
.forEach { | ||
it.originalSirClass.baseName = it.name | ||
} | ||
} | ||
|
||
private fun isValidAsciiIdentifier(identifier: String): Boolean { | ||
if (identifier.isEmpty()) { | ||
return false | ||
} | ||
|
||
identifier.forEachIndexed { index, c -> | ||
if (index == 0) { | ||
if (!firstCharAllowedChars.contains(c)) { | ||
return false | ||
} | ||
} else { | ||
if (!nextCharAllowedChars.contains(c)) { | ||
return false | ||
} | ||
} | ||
} | ||
|
||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters