7
7
"errors"
8
8
"fmt"
9
9
"io"
10
+ "log"
10
11
11
12
"github.com/haya14busa/go-vimlparser/ast"
12
13
)
@@ -41,6 +42,23 @@ func (p *printer) init(cfg *Config) {
41
42
p .Config = * cfg
42
43
}
43
44
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
+
44
62
func (p * printer ) printNode (node ast.Node ) error {
45
63
switch n := node .(type ) {
46
64
case * ast.File :
@@ -59,7 +77,27 @@ func (p *printer) file(f *ast.File) error {
59
77
}
60
78
61
79
func (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
63
101
}
64
102
65
103
func (p * printer ) stmt (node ast.Statement ) error {
0 commit comments