77 "errors"
88 "fmt"
99 "io"
10+ "log"
1011
1112 "github.com/haya14busa/go-vimlparser/ast"
1213)
@@ -41,6 +42,23 @@ func (p *printer) init(cfg *Config) {
4142 p .Config = * cfg
4243}
4344
45+ func (p * printer ) print (args ... interface {}) {
46+ for _ , arg := range args {
47+ switch arg := arg .(type ) {
48+ case * ast.BasicLit :
49+ p .writeString (arg .Value )
50+ case * ast.Ident :
51+ p .writeString (arg .Name )
52+ default :
53+ log .Fatal (fmt .Errorf ("print: unsupported type %T" , arg ))
54+ }
55+ }
56+ }
57+
58+ func (p * printer ) writeString (s string ) {
59+ p .output = append (p .output , s ... )
60+ }
61+
4462func (p * printer ) printNode (node ast.Node ) error {
4563 switch n := node .(type ) {
4664 case * ast.File :
@@ -59,7 +77,27 @@ func (p *printer) file(f *ast.File) error {
5977}
6078
6179func (p * printer ) expr (expr ast.Expr ) error {
62- return errors .New ("Not implemented: printer.expr" )
80+ switch n := expr .(type ) {
81+ // case *ast.TernaryExpr:
82+ // case *ast.BinaryExpr:
83+ // case *ast.UnaryExpr:
84+ // case *ast.SubscriptExpr:
85+ // case *ast.SliceExpr:
86+ // case *ast.CallExpr:
87+ // case *ast.DotExpr:
88+ // case *ast.List:
89+ // case *ast.Dict:
90+ // case *ast.CurlyName:
91+ // case *ast.CurlyNameLit:
92+ // case *ast.CurlyNameExpr:
93+ case * ast.BasicLit , * ast.Ident :
94+ p .print (n )
95+ // case *ast.LambdaExpr:
96+ // case *ast.ParenExpr:
97+ default :
98+ return fmt .Errorf ("unsupported expr type %T" , n )
99+ }
100+ return nil
63101}
64102
65103func (p * printer ) stmt (node ast.Statement ) error {
0 commit comments