diff --git a/build.gradle.kts b/build.gradle.kts index d9605e0..1c24a43 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile val containerAlwaysOn: String by project val disableLint: String by project +val projectName = "postgres-json" plugins { jacoco @@ -86,7 +87,7 @@ val sourcesJar by tasks.creating(Jar::class) { apply(plugin = "docker-compose") dockerCompose { - setProjectName("postgres-json") + setProjectName(projectName) setProperty("useComposeFiles", listOf("docker-compose.yml")) setProperty("stopContainers", !containerAlwaysOn.toBoolean()) isRequiredBy(project.tasks.test) @@ -95,7 +96,7 @@ dockerCompose { publishing { repositories { maven { - name = "postgres-json" + name = projectName url = uri("https://maven.pkg.github.com/flecomte/postgres-json") credentials { username = System.getenv("GITHUB_USERNAME") @@ -105,7 +106,7 @@ publishing { } publications { - create("postgres-json") { + create(projectName) { from(components["java"]) artifact(sourcesJar) } diff --git a/src/main/kotlin/fr/postgresjson/connexion/Connection.kt b/src/main/kotlin/fr/postgresjson/connexion/Connection.kt index dd9fc77..c14e893 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Connection.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Connection.kt @@ -14,9 +14,6 @@ import kotlin.jvm.Throws import kotlin.random.Random import kotlin.reflect.full.hasAnnotation -// TODO move execute function outside -// TODO create function executeNullable - class Connection( private val database: String, private val username: String, diff --git a/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt b/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt index e1fb89b..0663eff 100644 --- a/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt +++ b/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt @@ -28,6 +28,7 @@ internal fun ScriptPart.removeParentheses(): ScriptPart { this } } + /** * Get next part of script. * You can define a list of characters that end the part of script. Like `(` or space. @@ -36,35 +37,26 @@ internal fun ScriptPart.removeParentheses(): ScriptPart { internal fun ScriptPart.getNextScript(isEnd: Context.() -> Boolean = { false }): NextScript { val status = Status() - fun String.unescape(): String { - val first = take(1) - val last = takeLast(1) - return if (first == last && first in listOf("\"", "'")) { - drop(1).dropLast(1).replace("$first$first", first) - } else { - this - } - } - for ((index, c) in restOfScript.withIndex()) { - val nextChar = restOfScript.getOrNull(index + 1) val prevChar = restOfScript.getOrNull(index - 1) - if (c == '"' && (nextChar != '"' && prevChar != '"')) { + val nextChar = restOfScript.getOrNull(index + 1) + val nestedChars = listOf(prevChar, nextChar) + + if (c == '"' && nestedChars.none { c == it }) { status.doubleQuoted = !status.doubleQuoted - } else if (c == '\'' && (nextChar != '\'' && prevChar != '\'')) { + } else if (c == '\'' && nestedChars.none { c == it }) { status.simpleQuoted = !status.simpleQuoted - } else if (c == '(' && status.isNotQuoted()) { - status.parentheses++ - } else if (c == ')' && status.isNotQuoted()) { - status.parentheses-- - } else if (c == '[' && status.isNotQuoted()) { - status.brackets++ - } else if (c == ']' && status.isNotQuoted()) { - status.brackets-- - } else if (c == '{' && status.isNotQuoted()) { - status.braces++ - } else if (c == '}' && status.isNotQuoted()) { - status.braces-- + } + + if (status.isNotQuoted()) { + when (c) { + '(' -> status.parentheses++ + ')' -> status.parentheses-- + '[' -> status.brackets++ + ']' -> status.brackets-- + '{' -> status.braces++ + '}' -> status.braces-- + } } if (isEnd(Context(index, c, status.copy(), restOfScript))) { @@ -72,11 +64,21 @@ internal fun ScriptPart.getNextScript(isEnd: Context.() -> Boolean = { false }): } } if (status.isNotEscaped()) { - return NextScript(restOfScript.unescape().trim(), "").trimSpace() + return NextScript(restOfScript.trim(), "").trimSpace() } throw ParseError() } +private fun String.unescape(): String { + val first = take(1) + val last = takeLast(1) + return if (first == last && first in listOf("\"", "'")) { + drop(1).dropLast(1).replace("$first$first", first) + } else { + this + } +} + internal fun NextScript.trimSpace(): NextScript { val spaces = charArrayOf(' ', '\n', '\t') return trim(chars = spaces) diff --git a/src/main/kotlin/fr/postgresjson/functionGenerator/FunctionGenerator.kt b/src/main/kotlin/fr/postgresjson/functionGenerator/FunctionGenerator.kt index 484661d..bd9502b 100644 --- a/src/main/kotlin/fr/postgresjson/functionGenerator/FunctionGenerator.kt +++ b/src/main/kotlin/fr/postgresjson/functionGenerator/FunctionGenerator.kt @@ -117,8 +117,8 @@ class FunctionGenerator(private val functionsDirectories: List) { val functionDecl = if (generics.isNotEmpty()) "inline fun <${generics.joinToString(", ")}>" else "fun" - if (hasReturn) { - return """ + return if (hasReturn) { + """ |package fr.postgresjson.functionGenerator.generated | |import com.fasterxml.jackson.core.type.TypeReference @@ -130,7 +130,7 @@ class FunctionGenerator(private val functionsDirectories: List) { |} """.trimMargin() } else { - return """ + """ |package fr.postgresjson.functionGenerator.generated | |import fr.postgresjson.connexion.Requester