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

com.github.treepat.grammars.ast.ASTNodeFactory.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 com.github.treepat.grammars.ast

fun  List.tail() = subList(1, size)

/**
 * Creates recursively a target_trees with the list of [siblings].
 * @return A the root the [Sibling]s target_trees.
 */
fun createSiblingNodes(siblings: List): ASTNode {
    if (siblings.size < 2) {
        throw IllegalArgumentException("There must be at least 2 siblings.")
    }
    if (siblings.size == 2) {
        return Sibling(siblings[0], siblings[1])
    }
    val secondParam = createSiblingNodes(siblings.tail())
    return Sibling(siblings.first(), secondParam)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy