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

chapi.ast.scalaast.ScalaAnalyser.kt Maven / Gradle / Ivy

Go to download

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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy