All Downloads are FREE. Search and download functionalities are using the official Maven repository.

expression.operators.ChildFunction.kt Maven / Gradle / Ivy

Go to download

Treepat is a language to recognise patterns in trees in a similar way as regular expressions recognize patterns in strings. Treepat includes analogous operators to regex union, concatenation, and closure, which are extended to the notion of trees.

There is a newer version: 2.0.0
Show newest version
package expression.operators

fun childFunction(
    father: VisitorFunction,
    child: VisitorFunction
): VisitorFunction = { targetTreeNode ->
    val fathers = father.invoke(targetTreeNode)
    var answers = emptyList()
    if (fathers.hasMatch) {
        answers = fathers.responses.map {
            if (it.matches.isEmpty()) {
                VisitorFunctionResponseFactory.createResponseWithZeroMatches(targetTreeNode, true)
            } else {
                val nextMove = it.oddParent ?: it.lastVisitedSibling
                val response = child.invoke(nextMove?.moveToFirstChild())
                VisitorFunctionResponseFactory.createMergeResponse(it, response, true)
            }
        }
    }
    VisitorFunctionResponseFactory.createResponse(answers, targetTreeNode)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy