| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library source_writer; | 5 library source_writer; |
| 6 | 6 |
| 7 | 7 |
| 8 /// DEBUG flag indicating whether to use the experimental line-breaker |
| 9 const _USE_LINE_BREAKER = false; |
| 10 |
| 11 |
| 8 class Line { | 12 class Line { |
| 9 | 13 |
| 10 final tokens = <LineToken>[]; | 14 final tokens = <LineToken>[]; |
| 11 final bool useTabs; | 15 final bool useTabs; |
| 12 final int spacesPerIndent; | 16 final int spacesPerIndent; |
| 13 final int indent; | 17 final int indent; |
| 14 final LinePrinter printer; | 18 final LinePrinter printer; |
| 15 | 19 |
| 16 Line({this.indent: 0, this.useTabs: false, this.spacesPerIndent: 2, | 20 Line({this.indent: 0, this.useTabs: false, this.spacesPerIndent: 2, |
| 17 this.printer: const SimpleLinePrinter()}) { | 21 this.printer: const SimpleLinePrinter()}) { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 Line currentLine; | 253 Line currentLine; |
| 250 | 254 |
| 251 final String lineSeparator; | 255 final String lineSeparator; |
| 252 int indentCount = 0; | 256 int indentCount = 0; |
| 253 | 257 |
| 254 LinePrinter linePrinter; | 258 LinePrinter linePrinter; |
| 255 LineToken _lastToken; | 259 LineToken _lastToken; |
| 256 | 260 |
| 257 SourceWriter({this.indentCount: 0, this.lineSeparator: NEW_LINE, | 261 SourceWriter({this.indentCount: 0, this.lineSeparator: NEW_LINE, |
| 258 bool useTabs: false, int spacesPerIndent: 2, int maxLineLength: 80}) { | 262 bool useTabs: false, int spacesPerIndent: 2, int maxLineLength: 80}) { |
| 259 // linePrinter = new SimpleLineBreaker(maxLineLength, (n) => | 263 if (_USE_LINE_BREAKER) { |
| 260 // getIndentString(n, useTabs: useTabs, spacesPerIndent: spacesPerIndent)
); | 264 linePrinter = new SimpleLineBreaker(maxLineLength, (n) => |
| 261 linePrinter = new SimpleLinePrinter(); | 265 getIndentString(n, useTabs: useTabs, spacesPerIndent: spacesPerIndent)
); |
| 266 } else { |
| 267 linePrinter = new SimpleLinePrinter(); |
| 268 } |
| 262 currentLine = new Line(indent: indentCount, printer: linePrinter); | 269 currentLine = new Line(indent: indentCount, printer: linePrinter); |
| 263 } | 270 } |
| 264 | 271 |
| 265 LineToken get lastToken => _lastToken; | 272 LineToken get lastToken => _lastToken; |
| 266 | 273 |
| 267 _addToken(LineToken token) { | 274 _addToken(LineToken token) { |
| 268 _lastToken = token; | 275 _lastToken = token; |
| 269 currentLine.addToken(token); | 276 currentLine.addToken(token); |
| 270 } | 277 } |
| 271 | 278 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 374 |
| 368 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); | 375 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); |
| 369 | 376 |
| 370 String repeat(String ch, int times) { | 377 String repeat(String ch, int times) { |
| 371 var sb = new StringBuffer(); | 378 var sb = new StringBuffer(); |
| 372 for (var i = 0; i < times; ++i) { | 379 for (var i = 0; i < times; ++i) { |
| 373 sb.write(ch); | 380 sb.write(ch); |
| 374 } | 381 } |
| 375 return sb.toString(); | 382 return sb.toString(); |
| 376 } | 383 } |
| OLD | NEW |