unpackdev / solgo

Solidity parser in Go, designed to transform Solidity code into a structured format for enhanced analysis, particularly beneficial for developers using Go to analyze Solidity smart contracts.
https://unpack.dev
Apache License 2.0
1 stars 0 forks source link

Print `ast` to Solidity Source Code #201

Open xianlinc opened 5 months ago

xianlinc commented 5 months ago

Introduced a new package called ast_printer to print ast.Node[ast.NodeType] to solidity source code. Right now, we do not support the printing of all the nodes, and we haven't tested it rigorously yet, but would love to get some feedback on what changes need to be made to integrate this into the codebase 🤩

Heres an example of how you would use this:

func printRoot(root *ast.RootNode) {
    str, ok := ast_printer.Print(root.GetSourceUnits()[0])
    if !ok {
        zap.L().Error("Failed to print root")
    }
    fmt.Println(str)
}