| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * Pretty-prints Node tree in XML-like format. | 6 * Pretty-prints Node tree in XML-like format. |
| 7 * | 7 * |
| 8 * TODO(smok): Add main() to run from command-line to print out tree for given | 8 * TODO(smok): Add main() to run from command-line to print out tree for given |
| 9 * .dart file. | 9 * .dart file. |
| 10 */ | 10 */ |
| 11 class PrettyPrinter implements Visitor { | 11 class PrettyPrinter implements Visitor { |
| 12 | 12 |
| 13 /** String used to represent one level of indent. */ | 13 /** String used to represent one level of indent. */ |
| 14 static const String INDENT = " "; | 14 static const String INDENT = " "; |
| 15 | 15 |
| 16 StringBuffer sb; | 16 StringBuffer sb; |
| 17 Link<String> tagStack; | 17 Link<String> tagStack; |
| 18 | 18 |
| 19 PrettyPrinter() : | 19 PrettyPrinter() : |
| 20 sb = new StringBuffer(), | 20 sb = new StringBuffer(), |
| 21 tagStack = const Link<String>(); | 21 tagStack = const Link<String>(); |
| 22 | 22 |
| 23 void pushTag(String tag) { | 23 void pushTag(String tag) { |
| 24 tagStack = tagStack.prepend(tag); | 24 tagStack = tagStack.prepend(tag); |
| 25 } | 25 } |
| 26 | 26 |
| 27 String popTag() { | 27 String popTag() { |
| 28 assert(!tagStack.isEmpty()); | 28 assert(!tagStack.isEmpty); |
| 29 String tag = tagStack.head; | 29 String tag = tagStack.head; |
| 30 tagStack = tagStack.tail; | 30 tagStack = tagStack.tail; |
| 31 return tag; | 31 return tag; |
| 32 } | 32 } |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Adds given string to result string. | 35 * Adds given string to result string. |
| 36 */ | 36 */ |
| 37 void add(SourceString string) { | 37 void add(SourceString string) { |
| 38 string.printOn(sb); | 38 string.printOn(sb); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 } | 461 } |
| 462 | 462 |
| 463 visitStringNode(StringNode node) { | 463 visitStringNode(StringNode node) { |
| 464 unimplemented('visitNode', node: node); | 464 unimplemented('visitNode', node: node); |
| 465 } | 465 } |
| 466 | 466 |
| 467 unimplemented(String message, {Node node}) { | 467 unimplemented(String message, {Node node}) { |
| 468 throw message; | 468 throw message; |
| 469 } | 469 } |
| 470 } | 470 } |
| OLD | NEW |