Unverified Commit 105d30d4 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Implement Jmespath shape traversal codegen for waiters (#3526)

This PR adds a `RustJmespathShapeTraversalGenerator` class that will
generate code to traverse Smithy generated shapes based on a Jmespath
expression. This is a necessary prerequisite for implementing Smithy
waiters support.

The generator only implements a subset of the full Jmespath spec. This
subset was determined by examining all the waiter expressions in the
existing SDK models.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 1c454bcd
Loading
Loading
Loading
Loading
+777 −0

File added.

Preview size limit exceeded, changes collapsed.

+591 −0

File added.

Preview size limit exceeded, changes collapsed.

+12 −6
Original line number Diff line number Diff line
@@ -524,13 +524,22 @@ fun RustWriter.rawTemplate(
 */
fun docLink(docLink: String): String = docLink.replace("::r##", "::").replace("::r#", "::")

class SafeNamer {
    private var n = 0

    fun safeName(prefix: String = "var"): String {
        n += 1
        return "${prefix}_$n"
    }
}

class RustWriter private constructor(
    private val filename: String,
    val namespace: String,
    private val commentCharacter: String = "//",
    private val printWarning: Boolean = true,
    /** Insert comments indicating where code was generated */
    private val debugMode: Boolean = false,
    val debugMode: Boolean = false,
    /** When true, automatically change all dependencies to be in the test scope */
    val devDependenciesOnly: Boolean = false,
) :
@@ -619,7 +628,7 @@ class RustWriter private constructor(

        private val preamble = mutableListOf<Writable>()
        private val formatter = RustSymbolFormatter()
        private var n = 0
        private val safeNamer = SafeNamer()

        init {
            expressionStart = '#'
@@ -644,10 +653,7 @@ class RustWriter private constructor(
                null
            }

        fun safeName(prefix: String = "var"): String {
            n += 1
            return "${prefix}_$n"
        }
        fun safeName(prefix: String = "var"): String = safeNamer.safeName(prefix)

        fun first(preWriter: Writable) {
            preamble.add(preWriter)
+4 −5
Original line number Diff line number Diff line
@@ -37,11 +37,10 @@ fun Writable.some(): Writable {

fun Writable.isNotEmpty(): Boolean = !this.isEmpty()

operator fun Writable.plus(other: Writable): Writable {
    val first = this
    return writable {
        rustTemplate("#{First:W}#{Second:W}", "First" to first, "Second" to other)
    }
operator fun Writable.plus(other: Writable): Writable =
    writable {
        this@plus(this)
        other(this)
    }

/**
+1 −1

File changed.

Contains only whitespace changes.