forked from joernio/joern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46c95ad
commit 445d90a
Showing
5 changed files
with
60 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...li/frontends/rubysrc2cpg/src/main/scala/io/joern/rubysrc2cpg/parser/AnltrAstPrinter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.joern.rubysrc2cpg.parser | ||
|
||
import org.antlr.v4.runtime.ParserRuleContext | ||
import org.antlr.v4.runtime.tree.TerminalNode | ||
|
||
/** General purpose ANTLR parse tree printer. | ||
*/ | ||
object AnltrAstPrinter { | ||
private val indentationIncrement = 1 | ||
|
||
private def print(level: Int, sb: StringBuilder, context: ParserRuleContext): StringBuilder = { | ||
val indentation = " ".repeat(level) | ||
val contextName = context.getClass.getSimpleName.stripSuffix("Context") | ||
val nextLevel = level + indentationIncrement | ||
sb.append(s"$indentation$contextName\n") | ||
Option(context.children).foreach(_.forEach { | ||
case c: ParserRuleContext => print(nextLevel, sb, c) | ||
case t: TerminalNode => print(nextLevel, sb, t) | ||
}) | ||
sb | ||
} | ||
|
||
private def print(level: Int, sb: StringBuilder, terminal: TerminalNode): StringBuilder = { | ||
val indentation = " ".repeat(level) | ||
sb.append(s"$indentation${terminal.getText}\n") | ||
sb | ||
} | ||
|
||
/** Pretty-prints an entire `ParserRuleContext` together with its descendants. | ||
* @param context | ||
* the context to pretty-print | ||
* @return | ||
* an indented, multiline string representation | ||
*/ | ||
def print(context: ParserRuleContext): String = print(0, new StringBuilder, context).toString() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 0 additions & 102 deletions
102
...ends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/testfixtures/RubyParserFixture.scala
This file was deleted.
Oops, something went wrong.