diff --git a/src/main/kotlin/fr/postgresjson/definition/Function.kt b/src/main/kotlin/fr/postgresjson/definition/Function.kt index 88846dc..2f142e4 100644 --- a/src/main/kotlin/fr/postgresjson/definition/Function.kt +++ b/src/main/kotlin/fr/postgresjson/definition/Function.kt @@ -11,22 +11,6 @@ class Function( override val source: Path? = null, ) : Resource, ParametersInterface { -// private fun NextScript.changeValue(block: (T) -> T): NextScript { -// return NextScript(block(value), restOfScript) -// } -// -// private fun NextScript.changeScript(block: (String) -> String): NextScript { -// return NextScript(value, block(restOfScript)) -// } -// -// private fun NextScript.dropOneOf(vararg endTextList: String): NextScript { -// 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() } diff --git a/src/main/kotlin/fr/postgresjson/definition/parse/ParsingFunction.kt b/src/main/kotlin/fr/postgresjson/definition/parse/ParsingFunction.kt index 337bba5..a78fe60 100644 --- a/src/main/kotlin/fr/postgresjson/definition/parse/ParsingFunction.kt +++ b/src/main/kotlin/fr/postgresjson/definition/parse/ParsingFunction.kt @@ -32,7 +32,7 @@ internal fun parseFunction(script: String, source: Path? = null): Function { internal fun ScriptPart.getFunctionName(): NextScript { 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 { private fun ScriptPart.getParameterName(): NextScript { try { return getNextScript { afterBeginBy(" ", "\n") && status.isNotEscaped() } - .changeValue { unescapeOrLowercase() } + .changeValue(String::unescapeOrLowercase) } catch (e: ParseException) { throw ParameterNameMalformed(this, e) } diff --git a/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt b/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt index 1e73829..49c801f 100644 --- a/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt +++ b/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt @@ -149,13 +149,25 @@ internal inline fun ScriptPart.change(block: String.() -> String): ScriptPart { } @OptIn(ExperimentalContracts::class) -internal inline fun NextScript.changeValue(block: T.() -> T): NextScript { +internal inline fun NextScript.changeValue(block: (T) -> T): NextScript { contract { callsInPlace(block, EXACTLY_ONCE) } return NextScript(value.run(block), nextScriptPart.restOfScript) } +internal fun NextScript.changeScript(block: (String) -> String): NextScript { + return NextScript(value, block(restOfScript)) +} + +internal fun NextScript.dropOneOf(vararg endTextList: String): NextScript { + return changeScript { script -> + endTextList + .filter { script.startsWith(it) } + .let { script.drop(it.size) } + } +} + internal fun ScriptPart.getNextInteger(): NextScript { val digits = restOfScript.takeWhile { it.isDigit() } val restOfScript = restOfScript.trimStart { it.isDigit() }