fun createNumberPlugin()

in kotlin-node/karakum/src/jsMain/kotlin/node/karakum/plugins/NumberPlugin.kt [84:107]


fun createNumberPlugin(vararg matchers: Pair<String, MatcherScope.() -> Unit>): Plugin {
    val config = matchers.map { (numberType, block) ->
        match(block).map { it.toChain() } to numberType
    }

    return createPlugin plugin@{ node, _, _ ->
        if (node.kind != SyntaxKind.NumberKeyword) return@plugin null

        for ((matcherChains, numberType) in config) {
            matcherChains@ for (matcherChain in matcherChains) {
                var current = node.getParentOrNull()

                for (matcher in matcherChain) {
                    if (current == null || !matcher(current)) continue@matcherChains
                    current = current.getParentOrNull()
                }

                return@plugin numberType
            }
        }

        null
    }
}