@@ -16,6 +16,7 @@ type parser struct {
16
16
s * scanner
17
17
w io.Writer
18
18
packageName string
19
+ lineComments bool
19
20
prefix string
20
21
forDepth int
21
22
switchDepth int
@@ -29,10 +30,20 @@ type parser struct {
29
30
// the supplied writer. Uses filename as the source file for line comments, and
30
31
// pkg as the Go package name.
31
32
func Parse (w io.Writer , r io.Reader , filename , pkg string ) error {
33
+ return parse (w , r , filename , pkg , true )
34
+ }
35
+
36
+ // ParseNoLineComments is the same as Parse, but does not write line comments.
37
+ func ParseNoLineComments (w io.Writer , r io.Reader , filename , pkg string ) error {
38
+ return parse (w , r , filename , pkg , false )
39
+ }
40
+
41
+ func parse (w io.Writer , r io.Reader , filename , pkg string , lineComments bool ) error {
32
42
p := & parser {
33
- s : newScanner (r , filename ),
34
- w : w ,
35
- packageName : pkg ,
43
+ s : newScanner (r , filename ),
44
+ w : w ,
45
+ packageName : pkg ,
46
+ lineComments : lineComments ,
36
47
}
37
48
return p .parseTemplate ()
38
49
}
@@ -801,8 +812,10 @@ func (p *parser) Printf(format string, args ...interface{}) {
801
812
return
802
813
}
803
814
w := p .w
804
- // line comments are required to start at the beginning of the line
805
- p .s .WriteLineComment (w )
815
+ if p .lineComments {
816
+ // line comments are required to start at the beginning of the line
817
+ p .s .WriteLineComment (w )
818
+ }
806
819
fmt .Fprintf (w , "%s" , p .prefix )
807
820
fmt .Fprintf (w , format , args ... )
808
821
fmt .Fprintf (w , "\n " )
0 commit comments