Robert Griesemer f8cf82f6f2 go/printer: implement SourcePos mode
If a printer is configured with the SourcePos mode
set, it will emit //-line comments as necessary to
ensure that the result - if reparsed - reflects the
original source position information.

This change required a bit of reworking of the
output section in printer.go. Specifically:

- Introduced new Config mode 'SourcePos'.

- Introduced new position 'out' which tracks the
position of the generated output if it were read
in again. If there is a discrepancy between out
and the current AST/source position, a //line
comment is emitted to correct for it.

- Lazy emission of indentation so that //line
comments can be placed correctly. As a result,
the trimmer will have to do less work.

- Merged writeItem into writeString.

- Merged writeByteN into writeByte.

- Use a []byte instead of a byte.Buffer both in the
printer and in the trimmer (eliminates dependency).

Also: introduced explicit printer.Mode type (in
sync w/ parser.Mode, scanner.Mode, etc.)

Runs all tests. Applied gofmt to src, misc w/o changes.

Fixes #1047.
Fixes #2697.

R=rsc, rsc
CC=golang-dev
https://golang.org/cl/5643066
2012-02-10 13:27:32 -08:00
..
2012-02-10 13:27:32 -08:00
2012-02-06 13:34:25 -05:00
2012-02-06 13:34:25 -05:00
2012-02-06 13:34:25 -05:00
2012-02-10 13:27:32 -08:00
2012-02-04 00:54:08 -05:00
2012-02-10 01:27:59 -05:00
2012-02-04 00:54:08 -05:00
2012-02-09 20:47:12 -02:00
2012-02-10 11:48:22 +11:00
2012-02-04 00:54:08 -05:00
2012-02-04 00:48:31 -05:00
2012-02-05 14:50:38 +11:00