chapi.ast.scalaast.ScalaAnalyser.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chapi-ast-scala Show documentation
Show all versions of chapi-ast-scala Show documentation
Chapi is A common language meta information convertor, convert different languages to same meta-data model
The newest version!
package chapi.ast.scalaast
import chapi.ast.antlr.ScalaLexer
import chapi.ast.antlr.ScalaParser
import chapi.domain.core.CodeContainer
import chapi.parser.Analyser
import org.antlr.v4.runtime.CharStreams
import org.antlr.v4.runtime.CommonTokenStream
import org.antlr.v4.runtime.tree.ParseTreeWalker
open class ScalaAnalyser: Analyser {
override fun analysis(code: String, filePath: String): CodeContainer {
val context = this.parse(code).compilationUnit()
val listener = ScalaFullIdentListener(fileName = filePath)
ParseTreeWalker().walk(listener, context)
return listener.getNodeInfo()
}
private fun parse(str: String): ScalaParser =
CharStreams.fromString(str)
.let(::ScalaLexer)
.let(::CommonTokenStream)
.let(::ScalaParser)
}