Chromium Code Reviews| 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 |
| 12 class Line { | 9 class Line { |
| 13 | 10 |
| 14 final tokens = <LineToken>[]; | 11 final tokens = <LineToken>[]; |
| 15 final bool useTabs; | 12 final bool useTabs; |
| 16 final int spacesPerIndent; | 13 final int spacesPerIndent; |
| 17 final int indent; | 14 final int indent; |
| 18 final LinePrinter printer; | 15 final LinePrinter printer; |
| 19 | 16 |
| 20 Line({this.indent: 0, this.useTabs: false, this.spacesPerIndent: 2, | 17 Line({this.indent: 0, this.useTabs: false, this.spacesPerIndent: 2, |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 Line currentLine; | 283 Line currentLine; |
| 287 | 284 |
| 288 final String lineSeparator; | 285 final String lineSeparator; |
| 289 int indentCount = 0; | 286 int indentCount = 0; |
| 290 | 287 |
| 291 LinePrinter linePrinter; | 288 LinePrinter linePrinter; |
| 292 LineToken _lastToken; | 289 LineToken _lastToken; |
| 293 | 290 |
| 294 SourceWriter({this.indentCount: 0, this.lineSeparator: NEW_LINE, | 291 SourceWriter({this.indentCount: 0, this.lineSeparator: NEW_LINE, |
| 295 bool useTabs: false, int spacesPerIndent: 2, int maxLineLength: 80}) { | 292 bool useTabs: false, int spacesPerIndent: 2, int maxLineLength: 80}) { |
| 296 if (_USE_LINE_BREAKER) { | 293 if (maxLineLength > -1) { |
|
Brian Wilkerson
2014/01/27 20:14:50
Will the SimpleLineBreaker work if the line length
lukechurch
2014/01/27 20:39:44
I agree (+1 seems loaded in this context ;))
Zero
pquitslund
2014/01/27 22:23:37
Good call. Done!
pquitslund
2014/01/27 22:23:37
Done.
| |
| 297 linePrinter = new SimpleLineBreaker(maxLineLength, (n) => | 294 linePrinter = new SimpleLineBreaker(maxLineLength, (n) => |
| 298 getIndentString(n, useTabs: useTabs, spacesPerIndent: spacesPerIndent) ); | 295 getIndentString(n, useTabs: useTabs, spacesPerIndent: spacesPerIndent) ); |
| 299 } else { | 296 } else { |
| 300 linePrinter = new SimpleLinePrinter(); | 297 linePrinter = new SimpleLinePrinter(); |
| 301 } | 298 } |
| 302 currentLine = new Line(indent: indentCount, printer: linePrinter); | 299 currentLine = new Line(indent: indentCount, printer: linePrinter); |
| 303 } | 300 } |
| 304 | 301 |
| 305 LineToken get lastToken => _lastToken; | 302 LineToken get lastToken => _lastToken; |
| 306 | 303 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 | 404 |
| 408 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); | 405 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); |
| 409 | 406 |
| 410 String repeat(String ch, int times) { | 407 String repeat(String ch, int times) { |
| 411 var sb = new StringBuffer(); | 408 var sb = new StringBuffer(); |
| 412 for (var i = 0; i < times; ++i) { | 409 for (var i = 0; i < times; ++i) { |
| 413 sb.write(ch); | 410 sb.write(ch); |
| 414 } | 411 } |
| 415 return sb.toString(); | 412 return sb.toString(); |
| 416 } | 413 } |
| OLD | NEW |