https://kotlinlang.org logo
#dsl
Title
# dsl
t

tjb

11/26/2018, 3:03 AM
Copy code
fun match(block: MatchBuilder.() -> Unit = {}) {
        val matchBuilder = MatchBuilder()
        matchBuilder.block()
        match = match.plus(matchBuilder.build())
    }
d

dave08

11/26/2018, 3:16 AM
match = match.plus? What's match here? I think you mean
return matchBuilder.build()
?
What does the builder return? If Regex, just
infix fun Regex.with(toMatch: String) = toMatch.match(this)
@tjb
t

tjb

11/26/2018, 3:18 PM
Ah sorry i should have added more code.
match
is an array of
Match
objects. I need to be able to have multiple
match
blocks in my DSL
Example:
Copy code
val m = builder {
        match {
            optional = true
            node {
                alias = "firstField"
                node = "Field"
                parameters = hashMapOf("id" to "12345", "hasTime" to false)
            }
        }

        match {
            node {
                alias = "secondField"
                node = "Field"
                parameters = hashMapOf("id" to "12345", "hasTime" to false)
            }
        }
    }
d

dave08

11/26/2018, 3:28 PM
You initialize
m
once and re-use it?
t

tjb

11/26/2018, 3:29 PM
no i do not
just once which is what i want
d

dave08

11/26/2018, 3:30 PM
Like the initialization of a server?
And how do you run the match?
t

tjb

11/26/2018, 3:31 PM
essentially this DSL is a query builder for neo4j. neo4j has a
WITH
clause and im struggling how to implement the
WITH
clause since its a separate method over
MATCH
.
my initial thought was to make
WITH
its own builder but it seems like that shouldnt be the right move.
ideally i want to do
Copy code
match {
            node {
                alias = "secondField"
                node = "Field"
                parameters = hashMapOf("id" to "12345", "hasTime" to false)
            }
        }
        
        with "hello, world, right, here"
but not sure how to implement the
with
here
d

dave08

11/26/2018, 3:33 PM
You can get ideas of a db dsl here: https://github.com/orangy/squash
But I'm not sure if that's a bit heavy for your needs
t

tjb

11/26/2018, 3:34 PM
ok cool i will take a look! yeah im just making a proof of concept right now
i appreciate the insight!
d

dave08

11/26/2018, 3:35 PM
no problem
2 Views