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

chapi.ast.thrift.ThriftAnalyser.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.9
Show newest version
package chapi.ast.thrift

import chapi.ast.antlr.ThriftLexer
import chapi.ast.antlr.ThriftParser
import chapi.domain.core.CodeContainer
import chapi.parser.Analyser
import org.antlr.v4.runtime.*
import org.antlr.v4.runtime.tree.ParseTreeWalker

class ThriftAnalyser : Analyser {
    override fun analysis(code: String, filePath: String): CodeContainer {
        val context = this.parse(code).document()
        val listener = ThriftFullIdentListener(fileName = filePath)
        ParseTreeWalker().walk(listener, context)

        return listener.getNodeInfo()
    }

    private fun parse(str: String): ThriftParser {
        val fromString = CharStreams.fromString(str)
        val lexer = ThriftLexer(fromString)
        val tokenStream = CommonTokenStream(lexer)
        val parser = ThriftParser(tokenStream)
        return parser
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy