LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // The printer package implements printing of AST nodes. | 5 // The printer package implements printing of AST nodes. |
6 package printer | 6 package printer |
7 | 7 |
8 import ( | 8 import ( |
9 "bytes" | 9 "bytes" |
10 "fmt" | 10 "fmt" |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 // A Config node controls the output of Fprint. | 1021 // A Config node controls the output of Fprint. |
1022 type Config struct { | 1022 type Config struct { |
1023 Mode uint // default: 0 | 1023 Mode uint // default: 0 |
1024 Tabwidth int // default: 8 | 1024 Tabwidth int // default: 8 |
1025 Styler Styler // default: nil | 1025 Styler Styler // default: nil |
1026 } | 1026 } |
1027 | 1027 |
1028 | 1028 |
1029 // Fprint "pretty-prints" an AST node to output and returns the number | 1029 // Fprint "pretty-prints" an AST node to output and returns the number |
1030 // of bytes written and an error (if any) for a given configuration cfg. | 1030 // of bytes written and an error (if any) for a given configuration cfg. |
| 1031 // Position information is interpreted relative to the file set fset. |
1031 // The node type must be *ast.File, or assignment-compatible to ast.Expr, | 1032 // The node type must be *ast.File, or assignment-compatible to ast.Expr, |
1032 // ast.Decl, ast.Spec, or ast.Stmt. | 1033 // ast.Decl, ast.Spec, or ast.Stmt. |
1033 // | 1034 // |
1034 func (cfg *Config) Fprint(output io.Writer, fset *token.FileSet, node interface{
}) (int, os.Error) { | 1035 func (cfg *Config) Fprint(output io.Writer, fset *token.FileSet, node interface{
}) (int, os.Error) { |
1035 // redirect output through a trimmer to eliminate trailing whitespace | 1036 // redirect output through a trimmer to eliminate trailing whitespace |
1036 // (Input to a tabwriter must be untrimmed since trailing tabs provide | 1037 // (Input to a tabwriter must be untrimmed since trailing tabs provide |
1037 // formatting information. The tabwriter could provide trimming | 1038 // formatting information. The tabwriter could provide trimming |
1038 // functionality but no tabwriter is used when RawFormat is set.) | 1039 // functionality but no tabwriter is used when RawFormat is set.) |
1039 output = &trimmer{output: output} | 1040 output = &trimmer{output: output} |
1040 | 1041 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 } | 1111 } |
1111 | 1112 |
1112 | 1113 |
1113 // Fprint "pretty-prints" an AST node to output. | 1114 // Fprint "pretty-prints" an AST node to output. |
1114 // It calls Config.Fprint with default settings. | 1115 // It calls Config.Fprint with default settings. |
1115 // | 1116 // |
1116 func Fprint(output io.Writer, fset *token.FileSet, node interface{}) os.Error { | 1117 func Fprint(output io.Writer, fset *token.FileSet, node interface{}) os.Error { |
1117 _, err := (&Config{Tabwidth: 8}).Fprint(output, fset, node) // don't car
e about number of bytes written | 1118 _, err := (&Config{Tabwidth: 8}).Fprint(output, fset, node) // don't car
e about number of bytes written |
1118 return err | 1119 return err |
1119 } | 1120 } |
LEFT | RIGHT |