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