| 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 #library('parser'); | 5 #library('parser'); |
| 6 | 6 |
| 7 #import('dart:io'); | 7 #import('dart:io'); |
| 8 | 8 |
| 9 #import('../../../utils/utf8/utf8.dart'); | 9 #import('../../../utils/utf8/utf8.dart'); |
| 10 | 10 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 try { | 93 try { |
| 94 Token token = scan(file); | 94 Token token = scan(file); |
| 95 if (!options.scanOnly) parser.parseUnit(token); | 95 if (!options.scanOnly) parser.parseUnit(token); |
| 96 } catch (ParserError ex) { | 96 } catch (ParserError ex) { |
| 97 if (options.throwOnError) { | 97 if (options.throwOnError) { |
| 98 throw; | 98 throw; |
| 99 } else { | 99 } else { |
| 100 print(ex); | 100 print(ex); |
| 101 } | 101 } |
| 102 } catch (MalformedInputException ex) { | 102 } catch (MalformedInputException ex) { |
| 103 print('$filename: $ex'); | 103 // Already diagnosed. |
| 104 } catch (var ex) { | 104 } catch (var ex) { |
| 105 print('Error in file: $filename'); | 105 print('Error in file: $filename'); |
| 106 throw; | 106 throw; |
| 107 } | 107 } |
| 108 if (options.buildAst) { | 108 if (options.buildAst) { |
| 109 MyNodeListener l = listener; | 109 MyNodeListener l = listener; |
| 110 if (!l.nodes.isEmpty()) { | 110 if (!l.nodes.isEmpty()) { |
| 111 String message = 'Stack not empty after parsing'; | 111 String message = 'Stack not empty after parsing'; |
| 112 print(formatError(message, l.nodes.head.getBeginToken(), | 112 print(formatError(message, l.nodes.head.getBeginToken(), |
| 113 l.nodes.head.getEndToken(), file)); | 113 l.nodes.head.getEndToken(), file)); |
| 114 throw message; | 114 throw message; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 Token scan(MySourceFile source) { | 119 Token scan(MySourceFile source) { |
| 120 Scanner scanner = new ByteArrayScanner(source.rawText); | 120 Scanner scanner = new ByteArrayScanner(source.rawText); |
| 121 try { | 121 try { |
| 122 return scanner.tokenize(); | 122 return scanner.tokenize(); |
| 123 } catch (MalformedInputException ex) { | 123 } catch (MalformedInputException ex) { |
| 124 var message = ex.message; | 124 if (ex.position is Token) { |
| 125 if (message is !String) message = "unexpected character"; | 125 print(formatError(ex.message, ex.position, ex.position, source)); |
| 126 Token fakeToken = new Token(QUESTION_INFO, scanner.charOffset); | 126 } else { |
| 127 print(formatError(message, fakeToken, fakeToken, source)); | 127 Token fakeToken = new Token(QUESTION_INFO, ex.position); |
| 128 print(formatError(ex.message, fakeToken, fakeToken, source)); |
| 129 } |
| 128 throw; | 130 throw; |
| 129 } | 131 } |
| 130 } | 132 } |
| 131 | 133 |
| 132 var filesWithCrashes; | 134 var filesWithCrashes; |
| 133 | 135 |
| 134 void parseFilesFrom(InputStream input, MyOptions options, Function whenDone) { | 136 void parseFilesFrom(InputStream input, MyOptions options, Function whenDone) { |
| 135 void readLine(String line) { | 137 void readLine(String line) { |
| 136 stopwatch.start(); | 138 stopwatch.start(); |
| 137 try { | 139 try { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 String _GREEN_COLOR = '\u001b[32m'; | 321 String _GREEN_COLOR = '\u001b[32m'; |
| 320 String _RED_COLOR = '\u001b[31m'; | 322 String _RED_COLOR = '\u001b[31m'; |
| 321 String _MAGENTA_COLOR = '\u001b[35m'; | 323 String _MAGENTA_COLOR = '\u001b[35m'; |
| 322 String _NO_COLOR = '\u001b[0m'; | 324 String _NO_COLOR = '\u001b[0m'; |
| 323 | 325 |
| 324 class Mock { | 326 class Mock { |
| 325 const Mock(); | 327 const Mock(); |
| 326 bool get useColors() => true; | 328 bool get useColors() => true; |
| 327 internalError(message) { throw message.toString(); } | 329 internalError(message) { throw message.toString(); } |
| 328 } | 330 } |
| OLD | NEW |