clean
This commit is contained in:
@@ -11,22 +11,6 @@ class Function(
|
||||
override val source: Path? = null,
|
||||
) : Resource, ParametersInterface {
|
||||
|
||||
// private fun <T> NextScript<T>.changeValue(block: (T) -> T): NextScript<T> {
|
||||
// return NextScript(block(value), restOfScript)
|
||||
// }
|
||||
//
|
||||
// private fun <T> NextScript<T>.changeScript(block: (String) -> String): NextScript<T> {
|
||||
// return NextScript(value, block(restOfScript))
|
||||
// }
|
||||
//
|
||||
// private fun <T> NextScript<T>.dropOneOf(vararg endTextList: String): NextScript<T> {
|
||||
// return changeScript { script ->
|
||||
// endTextList
|
||||
// .filter { script.startsWith(it) }
|
||||
// .let { script.drop(it.size) }
|
||||
// }
|
||||
// }
|
||||
|
||||
fun getDefinition(): String = parameters
|
||||
.filter { it.direction == IN }
|
||||
.joinToString(", ") { it.type.toString() }
|
||||
|
||||
@@ -32,7 +32,7 @@ internal fun parseFunction(script: String, source: Path? = null): Function {
|
||||
internal fun ScriptPart.getFunctionName(): NextScript<String> {
|
||||
try {
|
||||
return getNextScript { status.isNotEscaped() && afterBeginBy("(", " ", "\n") }
|
||||
.changeValue { unescapeOrLowercase() }
|
||||
.changeValue(String::unescapeOrLowercase)
|
||||
} catch (e: ParseException) {
|
||||
throw FunctionNameMalformed(this, e)
|
||||
}
|
||||
@@ -96,7 +96,7 @@ private fun ScriptPart.getParameterMode(): NextScript<Direction> {
|
||||
private fun ScriptPart.getParameterName(): NextScript<String> {
|
||||
try {
|
||||
return getNextScript { afterBeginBy(" ", "\n") && status.isNotEscaped() }
|
||||
.changeValue { unescapeOrLowercase() }
|
||||
.changeValue(String::unescapeOrLowercase)
|
||||
} catch (e: ParseException) {
|
||||
throw ParameterNameMalformed(this, e)
|
||||
}
|
||||
|
||||
@@ -149,13 +149,25 @@ internal inline fun ScriptPart.change(block: String.() -> String): ScriptPart {
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
internal inline fun <T> NextScript<T>.changeValue(block: T.() -> T): NextScript<T> {
|
||||
internal inline fun <T> NextScript<T>.changeValue(block: (T) -> T): NextScript<T> {
|
||||
contract {
|
||||
callsInPlace(block, EXACTLY_ONCE)
|
||||
}
|
||||
return NextScript(value.run(block), nextScriptPart.restOfScript)
|
||||
}
|
||||
|
||||
internal fun <T> NextScript<T>.changeScript(block: (String) -> String): NextScript<T> {
|
||||
return NextScript(value, block(restOfScript))
|
||||
}
|
||||
|
||||
internal fun <T> NextScript<T>.dropOneOf(vararg endTextList: String): NextScript<T> {
|
||||
return changeScript { script ->
|
||||
endTextList
|
||||
.filter { script.startsWith(it) }
|
||||
.let { script.drop(it.size) }
|
||||
}
|
||||
}
|
||||
|
||||
internal fun ScriptPart.getNextInteger(): NextScript<Int?> {
|
||||
val digits = restOfScript.takeWhile { it.isDigit() }
|
||||
val restOfScript = restOfScript.trimStart { it.isDigit() }
|
||||
|
||||
Reference in New Issue
Block a user