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

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

Issue 42863002: New analyzer_experimental snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
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
11 import 'src/generated/java_core.dart' show CharSequence;
11 import 'src/error.dart'; 12 import 'src/error.dart';
12 import 'src/generated/ast.dart'; 13 import 'src/generated/ast.dart';
13 import 'src/generated/error.dart'; 14 import 'src/generated/error.dart';
14 import 'src/generated/parser.dart'; 15 import 'src/generated/parser.dart';
15 import 'src/generated/scanner.dart'; 16 import 'src/generated/scanner.dart';
16 import 'src/generated/source_io.dart'; 17 import 'src/generated/source_io.dart';
17 import 'src/string_source.dart'; 18 import 'src/string_source.dart';
18 19
19 export 'src/error.dart'; 20 export 'src/error.dart';
20 export 'src/generated/ast.dart'; 21 export 'src/generated/ast.dart';
21 export 'src/generated/error.dart'; 22 export 'src/generated/error.dart';
22 export 'src/generated/utilities_dart.dart'; 23 export 'src/generated/utilities_dart.dart';
23 24
24 /// Parses a Dart file into an AST. 25 /// Parses a Dart file into an AST.
25 CompilationUnit parseDartFile(String path) { 26 CompilationUnit parseDartFile(String path) {
26 var contents = new File(path).readAsStringSync(); 27 String contents = new File(path).readAsStringSync();
27 var errorCollector = new _ErrorCollector(); 28 var errorCollector = new _ErrorCollector();
28 var sourceFactory = new SourceFactory.con2([new FileUriResolver()]); 29 var sourceFactory = new SourceFactory.con2([new FileUriResolver()]);
29 30
30 var absolutePath = pathos.absolute(path); 31 var absolutePath = pathos.absolute(path);
31 var source = sourceFactory.forUri(pathos.toUri(absolutePath).toString()); 32 var source = sourceFactory.forUri(pathos.toUri(absolutePath).toString());
32 if (source == null) { 33 if (source == null) {
33 throw new ArgumentError("Can't get source for path $path"); 34 throw new ArgumentError("Can't get source for path $path");
34 } 35 }
35 if (!source.exists()) { 36 if (!source.exists()) {
36 throw new ArgumentError("Source $source doesn't exist"); 37 throw new ArgumentError("Source $source doesn't exist");
37 } 38 }
38 39
39 var scanner = new StringScanner(source, contents, errorCollector); 40 var reader = new CharSequenceReader(new CharSequence(contents));
41 var scanner = new Scanner(source, reader, errorCollector);
40 var token = scanner.tokenize(); 42 var token = scanner.tokenize();
41 var parser = new Parser(source, errorCollector); 43 var parser = new Parser(source, errorCollector);
42 var unit = parser.parseCompilationUnit(token); 44 var unit = parser.parseCompilationUnit(token);
43 unit.lineInfo = new LineInfo(scanner.lineStarts); 45 unit.lineInfo = new LineInfo(scanner.lineStarts);
44 46
45 if (errorCollector.hasErrors) throw errorCollector.group; 47 if (errorCollector.hasErrors) throw errorCollector.group;
46 48
47 return unit; 49 return unit;
48 } 50 }
49 51
50 /// Parses a string of Dart code into an AST. 52 /// Parses a string of Dart code into an AST.
51 /// 53 ///
52 /// If [name] is passed, it's used in error messages as the name of the code 54 /// If [name] is passed, it's used in error messages as the name of the code
53 /// being parsed. 55 /// being parsed.
54 CompilationUnit parseCompilationUnit(String contents, {String name}) { 56 CompilationUnit parseCompilationUnit(String contents, {String name}) {
55 if (name == null) name = '<unknown source>'; 57 if (name == null) name = '<unknown source>';
56 var source = new StringSource(contents, name); 58 var source = new StringSource(contents, name);
57 var errorCollector = new _ErrorCollector(); 59 var errorCollector = new _ErrorCollector();
58 var scanner = new StringScanner(source, contents, errorCollector); 60 var reader = new CharSequenceReader(new CharSequence(contents));
61 var scanner = new Scanner(source, reader, errorCollector);
59 var token = scanner.tokenize(); 62 var token = scanner.tokenize();
60 var parser = new Parser(source, errorCollector); 63 var parser = new Parser(source, errorCollector);
61 var unit = parser.parseCompilationUnit(token); 64 var unit = parser.parseCompilationUnit(token);
62 unit.lineInfo = new LineInfo(scanner.lineStarts); 65 unit.lineInfo = new LineInfo(scanner.lineStarts);
63 66
64 if (errorCollector.hasErrors) throw errorCollector.group; 67 if (errorCollector.hasErrors) throw errorCollector.group;
65 68
66 return unit; 69 return unit;
67 } 70 }
68 71
(...skipping 10 matching lines...) Expand all
79 bool get hasErrors => !_errors.isEmpty; 82 bool get hasErrors => !_errors.isEmpty;
80 83
81 /// The group of errors collected. 84 /// The group of errors collected.
82 AnalyzerErrorGroup get group => 85 AnalyzerErrorGroup get group =>
83 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); 86 new AnalyzerErrorGroup.fromAnalysisErrors(_errors);
84 87
85 _ErrorCollector(); 88 _ErrorCollector();
86 89
87 void onError(AnalysisError error) => _errors.add(error); 90 void onError(AnalysisError error) => _errors.add(error);
88 } 91 }
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/example/scanner_driver.dart ('k') | pkg/analyzer_experimental/lib/src/generated/ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698