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

Side by Side Diff: pkg/analyzer/lib/analyzer.dart

Issue 314583007: Only parse the directives when rewriting imports. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/pubspec.yaml » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 analyzer; 5 library analyzer;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:path/path.dart' as pathos; 9 import 'package:path/path.dart' as pathos;
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 var token = scanner.tokenize(); 62 var token = scanner.tokenize();
63 var parser = new Parser(source, errorCollector); 63 var parser = new Parser(source, errorCollector);
64 var unit = parser.parseCompilationUnit(token); 64 var unit = parser.parseCompilationUnit(token);
65 unit.lineInfo = new LineInfo(scanner.lineStarts); 65 unit.lineInfo = new LineInfo(scanner.lineStarts);
66 66
67 if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group; 67 if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group;
68 68
69 return unit; 69 return unit;
70 } 70 }
71 71
72 /// Parses the script tag and directives in a string of Dart code into an AST.
73 ///
74 /// Stops parsing when the first non-directive is encountered. The rest of the
75 /// string will not be parsed.
76 ///
77 /// If [name] is passed, it's used in error messages as the name of the code
78 /// being parsed.
nweiz 2014/06/03 21:23:09 Document [suppressErrors] as well.
Bob Nystrom 2014/06/03 21:46:59 Done.
79 CompilationUnit parseDirectives(String contents,
nweiz 2014/06/03 21:23:09 Probably a good idea to add a CHANGELOG entry abou
Bob Nystrom 2014/06/03 21:46:59 The analyzer package doesn't have a changelog.
nweiz 2014/06/03 23:06:57 Great opportunity to add one :).
80 {String name, bool suppressErrors: false}) {
81 if (name == null) name = '<unknown source>';
82 var source = new StringSource(contents, name);
83 var errorCollector = new _ErrorCollector();
84 var reader = new CharSequenceReader(contents);
85 var scanner = new Scanner(source, reader, errorCollector);
86 var token = scanner.tokenize();
87 var parser = new Parser(source, errorCollector);
88 var unit = parser.parseDirectives(token);
89 unit.lineInfo = new LineInfo(scanner.lineStarts);
90
91 if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group;
92
93 return unit;
94 }
95
72 /// Converts an AST node representing a string literal into a [String]. 96 /// Converts an AST node representing a string literal into a [String].
73 String stringLiteralToString(StringLiteral literal) { 97 String stringLiteralToString(StringLiteral literal) {
74 return literal.stringValue; 98 return literal.stringValue;
75 } 99 }
76 100
77 /// A simple error listener that collects errors into an [AnalysisErrorGroup]. 101 /// A simple error listener that collects errors into an [AnalysisErrorGroup].
78 class _ErrorCollector extends AnalysisErrorListener { 102 class _ErrorCollector extends AnalysisErrorListener {
79 final _errors = <AnalysisError>[]; 103 final _errors = <AnalysisError>[];
80 104
81 /// Whether any errors where collected. 105 /// Whether any errors where collected.
82 bool get hasErrors => !_errors.isEmpty; 106 bool get hasErrors => !_errors.isEmpty;
83 107
84 /// The group of errors collected. 108 /// The group of errors collected.
85 AnalyzerErrorGroup get group => 109 AnalyzerErrorGroup get group =>
86 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); 110 new AnalyzerErrorGroup.fromAnalysisErrors(_errors);
87 111
88 _ErrorCollector(); 112 _ErrorCollector();
89 113
90 void onError(AnalysisError error) => _errors.add(error); 114 void onError(AnalysisError error) => _errors.add(error);
91 } 115 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698