Skip to content

Commit

Permalink
Syntactic sugar for inRegex, toRegex operations
Browse files Browse the repository at this point in the history
  • Loading branch information
raf-nr committed Dec 8, 2024
1 parent eb068cc commit 1b38d12
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ksmt-core/src/main/kotlin/io/ksmt/KContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,7 @@ open class KContext(
/**
* Check if first string contains second one.
* */
@JvmName("strContains")
infix fun KExpr<KStringSort>.contains(other: KExpr<KStringSort>) = mkStringContains(this, other)

private val stringToRegexExprCache = mkAstInterner<KStringToRegexExpr>()
Expand All @@ -2170,6 +2171,16 @@ open class KContext(
KStringToRegexExpr(this, arg)
}

/**
* Create a regular expression based on a string expression.
* */
fun KExpr<KStringSort>.toRegex() = mkStringToRegex(this)

/**
* Create a regular expression based on a string expression.
* */
fun String.toRegex() = mkStringToRegex(this.expr)

private val stringInRegexExprCache = mkAstInterner<KStringInRegexExpr>()

/**
Expand All @@ -2187,6 +2198,22 @@ open class KContext(
KStringInRegexExpr(this, arg0, arg1)
}

/**
* Check if a string belongs to the language defined by the regular expression.
* */
infix fun KExpr<KStringSort>.inRegex(other: KExpr<KRegexSort>) = mkStringInRegex(this, other)

/**
* Check if a string belongs to the language defined by the regular expression.
* */
infix fun String.inRegex(other: KExpr<KRegexSort>) = mkStringInRegex(this.expr, other)

/**
* Check if a string belongs to the language defined by the regular expression.
* */
@JvmName("regexContains")
infix fun KExpr<KRegexSort>.contains(other: KExpr<KStringSort>) = mkStringInRegex(other, this)

private val regexLiteralCache = mkAstInterner<KRegexLiteralExpr>()

/**
Expand Down

0 comments on commit 1b38d12

Please sign in to comment.