Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: dart/frog/leg/tools/mini_parser.dart

Issue 9112008: Improve error recovery in parser. (Closed) Base URL: ssh://aaricia.aar/home/ahe/Dart/all/dart.googlecode.com.git@master
Patch Set: Update language-leg.status Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dart/frog/leg/tools/find_file_to_parse.sh ('k') | dart/tests/language/language-leg.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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('../elements/elements.dart'); 7 #import('../elements/elements.dart');
8 #import('../scanner/scanner_implementation.dart'); 8 #import('../scanner/scanner_implementation.dart');
9 #import('../scanner/scannerlib.dart'); 9 #import('../scanner/scannerlib.dart');
10 #import('../tree/tree.dart'); 10 #import('../tree/tree.dart');
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 : new Parser(listener); 79 : new Parser(listener);
80 try { 80 try {
81 Token token = scan(file); 81 Token token = scan(file);
82 if (!options.scanOnly) parser.parseUnit(token); 82 if (!options.scanOnly) parser.parseUnit(token);
83 } catch (ParserError ex) { 83 } catch (ParserError ex) {
84 if (options.throwOnError) { 84 if (options.throwOnError) {
85 throw; 85 throw;
86 } else { 86 } else {
87 print(ex); 87 print(ex);
88 } 88 }
89 } catch (MalformedInputException ex) {
90 print('$filename: $ex');
91 } catch (var ex) {
92 print('Error in file: $filename');
93 throw;
89 } 94 }
90 if (options.buildAst) { 95 if (options.buildAst) {
91 MyNodeListener l = listener; 96 MyNodeListener l = listener;
92 if (!l.nodes.isEmpty()) { 97 if (!l.nodes.isEmpty()) {
93 parserError('Stack not empty after parsing', 98 parserError('Stack not empty after parsing',
94 l.nodes.head.getBeginToken(), l.nodes.head.getEndToken(), 99 l.nodes.head.getBeginToken(), l.nodes.head.getEndToken(),
95 file); 100 file);
96 } 101 }
97 } 102 }
98 return bytes.length; 103 return bytes.length;
99 } 104 }
100 105
101 Token scan(MySourceFile source) { 106 Token scan(MySourceFile source) {
102 Scanner scanner = new ByteArrayScanner(source.rawText); 107 Scanner scanner = new ByteArrayScanner(source.rawText);
103 try { 108 try {
104 return scanner.tokenize(); 109 return scanner.tokenize();
105 } catch (MalformedInputException ex) { 110 } catch (MalformedInputException ex) {
106 var message = ex.message; 111 var message = ex.message;
107 if (message is !String) message = "unexpected character"; 112 if (message is !String) message = "unexpected character";
108 Token fakeToken = new Token($QUESTION, scanner.charOffset); 113 Token fakeToken = new Token(QUESTION_INFO, scanner.charOffset);
109 try { 114 try {
110 new MyListener(source).error(message, fakeToken); 115 new MyListener(source).error(message, fakeToken);
111 } catch (ParserError ex) { 116 } catch (ParserError ex) {
112 // TODO(ahe): Clean this up, don't throw exceptions. 117 // TODO(ahe): Clean this up, don't throw exceptions.
113 print(ex); 118 print(ex);
114 } 119 }
115 throw; 120 throw;
116 } 121 }
117 } 122 }
118 123
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 String _GREEN_COLOR = '\u001b[32m'; 301 String _GREEN_COLOR = '\u001b[32m';
297 String _RED_COLOR = '\u001b[31m'; 302 String _RED_COLOR = '\u001b[31m';
298 String _MAGENTA_COLOR = '\u001b[35m'; 303 String _MAGENTA_COLOR = '\u001b[35m';
299 String _NO_COLOR = '\u001b[0m'; 304 String _NO_COLOR = '\u001b[0m';
300 305
301 class Mock { 306 class Mock {
302 const Mock(); 307 const Mock();
303 bool get useColors() => true; 308 bool get useColors() => true;
304 internalError(message) { throw message.toString(); } 309 internalError(message) { throw message.toString(); }
305 } 310 }
OLDNEW
« no previous file with comments | « dart/frog/leg/tools/find_file_to_parse.sh ('k') | dart/tests/language/language-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698