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

commonMain.org.antlr.v4.kotlinruntime.tree.ParseTreeWalker.kt Maven / Gradle / Ivy

// Copyright 2017-present Strumenta and contributors, licensed under Apache 2.0.
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.
package org.antlr.v4.kotlinruntime.tree

import org.antlr.v4.kotlinruntime.ParserRuleContext
import kotlin.jvm.JvmField

public open class ParseTreeWalker {
  public companion object {
    @JvmField
    public val DEFAULT: ParseTreeWalker = ParseTreeWalker()
  }

  /**
   * Performs a walk on the given parse tree starting at the root and going down recursively
   * with depth-first search. On each node, [ParseTreeWalker.enterRule] is called before
   * recursively walking down into child nodes, then [ParseTreeWalker.exitRule] is called
   * after the recursive call to wind up.
   *
   * @param listener The listener used by the walker to process grammar rules
   * @param t The parse tree to be walked on
   */
  public open fun walk(listener: ParseTreeListener, t: ParseTree) {
    if (t is ErrorNode) {
      listener.visitErrorNode(t)
      return
    } else if (t is TerminalNode) {
      listener.visitTerminal(t)
      return
    }

    val r = t as RuleNode
    enterRule(listener, r)

    val n = r.childCount

    for (i in 0..




© 2015 - 2024 Weber Informatics LLC | Privacy Policy