Curtis Ullerich
10/06/2022, 3:02 AMaltavir
10/06/2022, 12:35 PMCurtis Ullerich
10/06/2022, 8:20 PMCurtis Ullerich
10/06/2022, 8:22 PMval ast = ExponentNode(AdditionNode(VariableNode("x"), NumberNode(5)), NumberNode(2))
var name: String? = null
var value: Int? = null
val matcher =
exp {
parens() {
optional()
plus {
variable { extract { name = it.name } }
num { extract { value = it.value } }
}
}
num { where { it.value == 2 } }
}
val match = matcher.matches(ast)
println("$match $name $value")
Curtis Ullerich
10/06/2022, 8:25 PMval (name: String, value: Int) = matcher.extractFrom(ast) ?: return null
but I can't find a good way to implement itCurtis Ullerich
10/06/2022, 8:29 PMextract
there but I'm still interested in any prior art for AST (math or otherwise) matchers.altavir
10/07/2022, 8:25 AMaltavir
10/07/2022, 8:26 AM