Created
June 20, 2025 18:26
-
-
Save manuelarte/8f5cafbb44fa736b9381d4fb9c625e34 to your computer and use it in GitHub Desktop.
`KeyValueExpr` parsing comments with dst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/dave/dst" | |
"github.com/dave/dst/decorator" | |
"os" | |
) | |
func main() { | |
code := `package a | |
func main(){ | |
_ = Person{ | |
// the birthdate is now | |
Birthdate: time.Now(), | |
// the surname is important | |
Surname: "Doe", | |
Name: "John", | |
} | |
} | |
` | |
f, err := decorator.Parse(code) | |
if err != nil { | |
panic(err) | |
} | |
dst.Fprint(os.Stdout, f, dst.NotNilFilter) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment