| 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 import 'package:front_end/src/fasta/scanner.dart' show Token; | 5 import 'package:front_end/src/fasta/scanner.dart' show Token; |
| 6 import '../util/util.dart'; | 6 import '../util/util.dart'; |
| 7 import 'nodes.dart'; | 7 import 'nodes.dart'; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Pretty-prints Node tree in XML-like format. | 10 * Pretty-prints Node tree in XML-like format. |
| 11 * | 11 * |
| 12 * TODO(smok): Add main() to run from command-line to print out tree for given | 12 * TODO(smok): Add main() to run from command-line to print out tree for given |
| 13 * .dart file. | 13 * .dart file. |
| 14 */ | 14 */ |
| 15 class PrettyPrinter extends Indentation with Tagging<Node> implements Visitor { | 15 class PrettyPrinter extends Indentation with Tagging<Node> implements Visitor { |
| 16 @override | 16 @override |
| 17 void addDefaultParameters(Node node, Map params) { | 17 void addDefaultParameters(Node node, Map params) { |
| 18 params['getBeginToken'] = tokenToStringOrNull(node.getBeginToken()); | 18 params['getBeginToken'] = tokenToStringOrNull(node.getBeginToken()); |
| 19 params['getEndToken'] = tokenToStringOrNull(node.getEndToken()); | 19 params['getEndToken'] = tokenToStringOrNull(node.getEndToken()); |
| 20 } | 20 } |
| 21 | 21 |
| 22 String valueToString(var value) { | 22 String valueToString(var value) { |
| 23 if (value is Token) { | 23 if (value is Token) { |
| 24 return value.value; | 24 return value.lexeme; |
| 25 } | 25 } |
| 26 return value; | 26 return value; |
| 27 } | 27 } |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * Pretty-prints given node tree into string. | 30 * Pretty-prints given node tree into string. |
| 31 */ | 31 */ |
| 32 static String prettyPrint(Node node) { | 32 static String prettyPrint(Node node) { |
| 33 var p = new PrettyPrinter(); | 33 var p = new PrettyPrinter(); |
| 34 node.accept(p); | 34 node.accept(p); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 } | 481 } |
| 482 | 482 |
| 483 visitTypeAnnotation(TypeAnnotation node) { | 483 visitTypeAnnotation(TypeAnnotation node) { |
| 484 unimplemented('visitNode', node: node); | 484 unimplemented('visitNode', node: node); |
| 485 } | 485 } |
| 486 | 486 |
| 487 unimplemented(String message, {Node node}) { | 487 unimplemented(String message, {Node node}) { |
| 488 throw message; | 488 throw message; |
| 489 } | 489 } |
| 490 } | 490 } |
| OLD | NEW |