| 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 part of scanner; | 5 part of scanner; |
| 6 | 6 |
| 7 const bool VERBOSE = false; | 7 const bool VERBOSE = false; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * A parser event listener that does nothing except throw exceptions | 10 * A parser event listener that does nothing except throw exceptions |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 void recoverableError(String message, {Token token, Node node}) { | 588 void recoverableError(String message, {Token token, Node node}) { |
| 589 if (token == null && node != null) { | 589 if (token == null && node != null) { |
| 590 token = node.getBeginToken(); | 590 token = node.getBeginToken(); |
| 591 } | 591 } |
| 592 error(message, token); | 592 error(message, token); |
| 593 } | 593 } |
| 594 | 594 |
| 595 void error(String message, Token token) { | 595 void error(String message, Token token) { |
| 596 throw new ParserError("$message @ ${token.charOffset}"); | 596 throw new ParserError("$message @ ${token.charOffset}"); |
| 597 } | 597 } |
| 598 |
| 599 void reportError(Spannable spannable, |
| 600 MessageKind errorCode, |
| 601 [Map arguments = const {}]) { |
| 602 String message = errorCode.error(arguments, true).toString(); |
| 603 Token token; |
| 604 Node node; |
| 605 if (spannable is Token) { |
| 606 token = spannable; |
| 607 } else if (spannable is Node) { |
| 608 node = spannable; |
| 609 } else { |
| 610 throw new ParserError(message); |
| 611 } |
| 612 recoverableError(message, token: token, node: node); |
| 613 } |
| 598 } | 614 } |
| 599 | 615 |
| 600 class ParserError { | 616 class ParserError { |
| 601 final String reason; | 617 final String reason; |
| 602 ParserError(this.reason); | 618 ParserError(this.reason); |
| 603 toString() => reason; | 619 toString() => reason; |
| 604 } | 620 } |
| 605 | 621 |
| 606 typedef int IdGenerator(); | 622 typedef int IdGenerator(); |
| 607 | 623 |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 assert(stringCount != 0); | 1131 assert(stringCount != 0); |
| 1116 Expression accumulator = popNode(); | 1132 Expression accumulator = popNode(); |
| 1117 stringCount--; | 1133 stringCount--; |
| 1118 while (stringCount > 0) { | 1134 while (stringCount > 0) { |
| 1119 Expression expression = popNode(); | 1135 Expression expression = popNode(); |
| 1120 accumulator = new StringJuxtaposition(expression, accumulator); | 1136 accumulator = new StringJuxtaposition(expression, accumulator); |
| 1121 stringCount--; | 1137 stringCount--; |
| 1122 } | 1138 } |
| 1123 pushNode(accumulator); | 1139 pushNode(accumulator); |
| 1124 } | 1140 } |
| 1141 |
| 1142 void reportError(Spannable spannable, |
| 1143 MessageKind errorCode, |
| 1144 [Map arguments = const {}]) { |
| 1145 listener.reportError(spannable, errorCode, arguments); |
| 1146 } |
| 1125 } | 1147 } |
| 1126 | 1148 |
| 1127 class NodeListener extends ElementListener { | 1149 class NodeListener extends ElementListener { |
| 1128 NodeListener(DiagnosticListener listener, CompilationUnitElement element) | 1150 NodeListener(DiagnosticListener listener, CompilationUnitElement element) |
| 1129 : super(listener, element, null); | 1151 : super(listener, element, null); |
| 1130 | 1152 |
| 1131 void addLibraryTag(LibraryTag tag) { | 1153 void addLibraryTag(LibraryTag tag) { |
| 1132 pushNode(tag); | 1154 pushNode(tag); |
| 1133 } | 1155 } |
| 1134 | 1156 |
| (...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 | 1997 |
| 1976 Node parse(DiagnosticListener diagnosticListener, | 1998 Node parse(DiagnosticListener diagnosticListener, |
| 1977 CompilationUnitElement element, | 1999 CompilationUnitElement element, |
| 1978 doParse(Parser parser)) { | 2000 doParse(Parser parser)) { |
| 1979 NodeListener listener = new NodeListener(diagnosticListener, element); | 2001 NodeListener listener = new NodeListener(diagnosticListener, element); |
| 1980 doParse(new Parser(listener)); | 2002 doParse(new Parser(listener)); |
| 1981 Node node = listener.popNode(); | 2003 Node node = listener.popNode(); |
| 1982 assert(listener.nodes.isEmpty); | 2004 assert(listener.nodes.isEmpty); |
| 1983 return node; | 2005 return node; |
| 1984 } | 2006 } |
| OLD | NEW |