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

chapi.ast.rustast.RustAnalyser.kt Maven / Gradle / Ivy

Go to download

Chapi is A common language meta information convertor, convert different languages to same meta-data model

There is a newer version: 2.4.3
Show newest version
package chapi.ast.rustast

import chapi.ast.antlr.RustLexer
import chapi.ast.antlr.RustParser
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 RustAnalyser : Analyser {
    override fun analysis(code: String, filePath: String): CodeContainer {
        val context = this.parse(code).crate()
        val listener = RustFullIdentListener(filePath)
        ParseTreeWalker().walk(listener, context)
        return listener.getNodeInfo()
    }

    private fun parse(str: String): RustParser =
        CharStreams.fromString(str)
            .let(::RustLexer)
            .let(::CommonTokenStream)
            .let(::RustParser)

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy