| 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('dart2js'); | 5 #library('dart2js'); |
| 6 | 6 |
| 7 #import('dart:io'); | 7 #import('dart:io'); |
| 8 #import('dart:uri'); | 8 #import('dart:uri'); |
| 9 #import('dart:utf'); | 9 #import('dart:utf'); |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 String extractParameter(String argument) { | 28 String extractParameter(String argument) { |
| 29 return argument.substring(argument.indexOf('=') + 1); | 29 return argument.substring(argument.indexOf('=') + 1); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void parseCommandLine(List<OptionHandler> handlers, List<String> argv) { | 32 void parseCommandLine(List<OptionHandler> handlers, List<String> argv) { |
| 33 var patterns = <String>[]; | 33 var patterns = <String>[]; |
| 34 for (OptionHandler handler in handlers) { | 34 for (OptionHandler handler in handlers) { |
| 35 patterns.add(handler.pattern); | 35 patterns.add(handler.pattern); |
| 36 } | 36 } |
| 37 var pattern = new RegExp('^(${Strings.join(patterns, ")|(")})\$'); | 37 var pattern = new RegExp('^(${Strings.join(patterns, ")|(")})\$'); |
| 38 assert(pattern.groupCount() == handlers.length); | |
| 39 OUTER: for (String argument in argv) { | 38 OUTER: for (String argument in argv) { |
| 40 Match match = pattern.firstMatch(argument); | 39 Match match = pattern.firstMatch(argument); |
| 40 assert(match.groupCount() == handlers.length); |
| 41 for (int i = 0; i < handlers.length; i++) { | 41 for (int i = 0; i < handlers.length; i++) { |
| 42 if (match[i + 1] !== null) { | 42 if (match[i + 1] !== null) { |
| 43 handlers[i].handle(argument); | 43 handlers[i].handle(argument); |
| 44 continue OUTER; | 44 continue OUTER; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 throw 'Internal error: "$argument" did not match'; | 47 throw 'Internal error: "$argument" did not match'; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } catch (var ignored) { | 223 } catch (var ignored) { |
| 224 print('Internal error: error while printing exception'); | 224 print('Internal error: error while printing exception'); |
| 225 } | 225 } |
| 226 try { | 226 try { |
| 227 print(trace); | 227 print(trace); |
| 228 } finally { | 228 } finally { |
| 229 exit(253); // 253 is recognized as a crash by our test scripts. | 229 exit(253); // 253 is recognized as a crash by our test scripts. |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 } | 232 } |
| OLD | NEW |