I'm experimenting with writing a tree matching DSL...
# getting-started
c
I'm experimenting with writing a tree matching DSL in Kotlin. Anybody know if there's something similar out there already?
m
What would this DSL accomplish? I didn’t get it from your message, sorry
g
Maybe try check in #mathematics (or related channels) There are quite a few people who have experience with math/science libraries with DSL
c
Thanks Andrey, I'll check there. Matteo, this would let me check if an AST matches an expected pattern. This is a proof of concept I wrote.
Copy code
val ast =
      ExponentNode(AdditionNode(VariableNode("x"), NumberNode(5)), NumberNode(2))
    val matcher =
      exp {
          parens {
            optional()
            plus {
              variable {}
              num {}
            }
          }
          num {}
        }
    assertThat(matcher.matches(ast)).isTrue()
đź‘Ť 1
m
Understood, thanks!