Skip to content

A small library to help rewrite / modify the AST of a Go (golang) program

License

Notifications You must be signed in to change notification settings

tsuna/gorewrite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

gorewrite

Go has pretty amazing tooling to parse Go code and pretty-print the AST back into the original code. It also has a utility to visit an AST and modify parts of it as you Go, using ast.Walk() with a Visitor.

This is fine when you just to tweak the contents of existing AST nodes, or change the sub-nodes of a given node, but it doesn't let you replace an existing node with another one. This is needed, for instance, if you want to go from one type of Node to another (e.g. when you want to rewrite one type of expression as another type of expression).

gorewrite gives you the exact same thing as Walk() with a Visitor except that your Visitor, called a Rewriter can return a modified ast.Node, and that you need to call Rewrite() instead of Walk().

About

A small library to help rewrite / modify the AST of a Go (golang) program

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages