Descriptiongo/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 issue 1047.
Fixes issue 2697.
Patch Set 1 #Patch Set 2 : diff -r 75b8bf14a037 https://code.google.com/p/go #Patch Set 3 : diff -r e86e50000118 https://code.google.com/p/go #Patch Set 4 : diff -r e86e50000118 https://code.google.com/p/go #Patch Set 5 : diff -r e86e50000118 https://code.google.com/p/go #Patch Set 6 : diff -r 0b9d256eeec2 https://code.google.com/p/go #Patch Set 7 : diff -r 0b9d256eeec2 https://code.google.com/p/go #
Total comments: 1
Patch Set 8 : diff -r caf7dca9d711 https://code.google.com/p/go #
MessagesTotal messages: 5
|