| 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('../../../utf/utf.dart'); | 9 #import('../../../utf/utf.dart'); |
| 10 | 10 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 MySourceFile file = new MySourceFile(filename, bytes); | 92 MySourceFile file = new MySourceFile(filename, bytes); |
| 93 final Listener listener = options.buildAst | 93 final Listener listener = options.buildAst |
| 94 ? new MyNodeListener(file, options) | 94 ? new MyNodeListener(file, options) |
| 95 : new MyListener(file); | 95 : new MyListener(file); |
| 96 final Parser parser = options.diet | 96 final Parser parser = options.diet |
| 97 ? new PartialParser(listener) | 97 ? new PartialParser(listener) |
| 98 : new Parser(listener); | 98 : new Parser(listener); |
| 99 try { | 99 try { |
| 100 Token token = scan(file); | 100 Token token = scan(file); |
| 101 if (!options.scanOnly) parser.parseUnit(token); | 101 if (!options.scanOnly) parser.parseUnit(token); |
| 102 } catch (ParserError ex) { | 102 } on ParserError catch (ex) { |
| 103 if (options.throwOnError) { | 103 if (options.throwOnError) { |
| 104 throw; | 104 throw; |
| 105 } else { | 105 } else { |
| 106 print(ex); | 106 print(ex); |
| 107 } | 107 } |
| 108 } catch (MalformedInputException ex) { | 108 } on MalformedInputException catch (ex) { |
| 109 // Already diagnosed. | 109 // Already diagnosed. |
| 110 } catch (var ex) { | 110 } catch (ex) { |
| 111 print('Error in file: $filename'); | 111 print('Error in file: $filename'); |
| 112 throw; | 112 throw; |
| 113 } | 113 } |
| 114 if (options.buildAst) { | 114 if (options.buildAst) { |
| 115 MyNodeListener l = listener; | 115 MyNodeListener l = listener; |
| 116 if (!l.nodes.isEmpty()) { | 116 if (!l.nodes.isEmpty()) { |
| 117 String message = 'Stack not empty after parsing'; | 117 String message = 'Stack not empty after parsing'; |
| 118 print(formatError(message, l.nodes.head.getBeginToken(), | 118 print(formatError(message, l.nodes.head.getBeginToken(), |
| 119 l.nodes.head.getEndToken(), file)); | 119 l.nodes.head.getEndToken(), file)); |
| 120 throw message; | 120 throw message; |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 Token scan(MySourceFile source) { | 125 Token scan(MySourceFile source) { |
| 126 Scanner scanner = new ByteArrayScanner(source.rawText); | 126 Scanner scanner = new ByteArrayScanner(source.rawText); |
| 127 try { | 127 try { |
| 128 return scanner.tokenize(); | 128 return scanner.tokenize(); |
| 129 } catch (MalformedInputException ex) { | 129 } on MalformedInputException catch (ex) { |
| 130 if (ex.position is Token) { | 130 if (ex.position is Token) { |
| 131 print(formatError(ex.message, ex.position, ex.position, source)); | 131 print(formatError(ex.message, ex.position, ex.position, source)); |
| 132 } else { | 132 } else { |
| 133 Token fakeToken = new Token(QUESTION_INFO, ex.position); | 133 Token fakeToken = new Token(QUESTION_INFO, ex.position); |
| 134 print(formatError(ex.message, fakeToken, fakeToken, source)); | 134 print(formatError(ex.message, fakeToken, fakeToken, source)); |
| 135 } | 135 } |
| 136 throw; | 136 throw; |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 var filesWithCrashes; | 140 var filesWithCrashes; |
| 141 | 141 |
| 142 void parseFilesFrom(InputStream input, MyOptions options, Function whenDone) { | 142 void parseFilesFrom(InputStream input, MyOptions options, Function whenDone) { |
| 143 void readLine(String line) { | 143 void readLine(String line) { |
| 144 stopwatch.start(); | 144 stopwatch.start(); |
| 145 try { | 145 try { |
| 146 parseFile(line, options); | 146 parseFile(line, options); |
| 147 } catch (var ex, var trace) { | 147 } catch (ex, trace) { |
| 148 filesWithCrashes.add(line); | 148 filesWithCrashes.add(line); |
| 149 print(ex); | 149 print(ex); |
| 150 print(trace); | 150 print(trace); |
| 151 } | 151 } |
| 152 stopwatch.stop(); | 152 stopwatch.stop(); |
| 153 } | 153 } |
| 154 forEachLine(input, readLine, whenDone); | 154 forEachLine(input, readLine, whenDone); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void forEachLine(InputStream input, | 157 void forEachLine(InputStream input, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 173 try { | 173 try { |
| 174 int size = file.lengthSync(); | 174 int size = file.lengthSync(); |
| 175 List<int> bytes = new Uint8List(size + 1); | 175 List<int> bytes = new Uint8List(size + 1); |
| 176 file.readListSync(bytes, 0, size); | 176 file.readListSync(bytes, 0, size); |
| 177 bytes[size] = $EOF; | 177 bytes[size] = $EOF; |
| 178 threw = false; | 178 threw = false; |
| 179 return bytes; | 179 return bytes; |
| 180 } finally { | 180 } finally { |
| 181 try { | 181 try { |
| 182 file.closeSync(); | 182 file.closeSync(); |
| 183 } catch (var ex) { | 183 } catch (ex) { |
| 184 if (!threw) throw; | 184 if (!threw) throw; |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 int classCount = 0; | 189 int classCount = 0; |
| 190 int errorCount = 0; | 190 int errorCount = 0; |
| 191 | 191 |
| 192 class MyListener extends Listener { | 192 class MyListener extends Listener { |
| 193 final SourceFile file; | 193 final SourceFile file; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 set text(String newText) { | 321 set text(String newText) { |
| 322 throw "not supported"; | 322 throw "not supported"; |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 | 325 |
| 326 class Mock { | 326 class Mock { |
| 327 const Mock(); | 327 const Mock(); |
| 328 bool get useColors => true; | 328 bool get useColors => true; |
| 329 internalError(message) { throw message.toString(); } | 329 internalError(message) { throw message.toString(); } |
| 330 } | 330 } |
| OLD | NEW |