OLD | NEW |
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 10 matching lines...) Expand all Loading... |
21 export 'src/generated/error.dart'; | 21 export 'src/generated/error.dart'; |
22 export 'src/generated/utilities_dart.dart'; | 22 export 'src/generated/utilities_dart.dart'; |
23 | 23 |
24 /// Parses a string of Dart code into an AST. | 24 /// Parses a string of Dart code into an AST. |
25 /// | 25 /// |
26 /// If [name] is passed, it's used in error messages as the name of the code | 26 /// If [name] is passed, it's used in error messages as the name of the code |
27 /// being parsed. | 27 /// being parsed. |
28 /// | 28 /// |
29 /// Throws an [AnalyzerErrorGroup] if any errors occurred, unless | 29 /// Throws an [AnalyzerErrorGroup] if any errors occurred, unless |
30 /// [suppressErrors] is `true`, in which case any errors are discarded. | 30 /// [suppressErrors] is `true`, in which case any errors are discarded. |
31 CompilationUnit parseCompilationUnit(String contents, {String name, | 31 CompilationUnit parseCompilationUnit(String contents, |
32 bool suppressErrors: false}) { | 32 {String name, bool suppressErrors: false}) { |
33 if (name == null) name = '<unknown source>'; | 33 if (name == null) name = '<unknown source>'; |
34 var source = new StringSource(contents, name); | 34 var source = new StringSource(contents, name); |
35 var errorCollector = new _ErrorCollector(); | 35 var errorCollector = new _ErrorCollector(); |
36 var reader = new CharSequenceReader(contents); | 36 var reader = new CharSequenceReader(contents); |
37 var scanner = new Scanner(source, reader, errorCollector); | 37 var scanner = new Scanner(source, reader, errorCollector); |
38 var token = scanner.tokenize(); | 38 var token = scanner.tokenize(); |
39 var parser = new Parser(source, errorCollector); | 39 var parser = new Parser(source, errorCollector); |
40 var unit = parser.parseCompilationUnit(token); | 40 var unit = parser.parseCompilationUnit(token); |
41 unit.lineInfo = new LineInfo(scanner.lineStarts); | 41 unit.lineInfo = new LineInfo(scanner.lineStarts); |
42 | 42 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 /// Parses the script tag and directives in a string of Dart code into an AST. | 75 /// Parses the script tag and directives in a string of Dart code into an AST. |
76 /// | 76 /// |
77 /// Stops parsing when the first non-directive is encountered. The rest of the | 77 /// Stops parsing when the first non-directive is encountered. The rest of the |
78 /// string will not be parsed. | 78 /// string will not be parsed. |
79 /// | 79 /// |
80 /// If [name] is passed, it's used in error messages as the name of the code | 80 /// If [name] is passed, it's used in error messages as the name of the code |
81 /// being parsed. | 81 /// being parsed. |
82 /// | 82 /// |
83 /// Throws an [AnalyzerErrorGroup] if any errors occurred, unless | 83 /// Throws an [AnalyzerErrorGroup] if any errors occurred, unless |
84 /// [suppressErrors] is `true`, in which case any errors are discarded. | 84 /// [suppressErrors] is `true`, in which case any errors are discarded. |
85 CompilationUnit parseDirectives(String contents, {String name, | 85 CompilationUnit parseDirectives(String contents, |
86 bool suppressErrors: false}) { | 86 {String name, bool suppressErrors: false}) { |
87 if (name == null) name = '<unknown source>'; | 87 if (name == null) name = '<unknown source>'; |
88 var source = new StringSource(contents, name); | 88 var source = new StringSource(contents, name); |
89 var errorCollector = new _ErrorCollector(); | 89 var errorCollector = new _ErrorCollector(); |
90 var reader = new CharSequenceReader(contents); | 90 var reader = new CharSequenceReader(contents); |
91 var scanner = new Scanner(source, reader, errorCollector); | 91 var scanner = new Scanner(source, reader, errorCollector); |
92 var token = scanner.tokenize(); | 92 var token = scanner.tokenize(); |
93 var parser = new Parser(source, errorCollector); | 93 var parser = new Parser(source, errorCollector); |
94 var unit = parser.parseDirectives(token); | 94 var unit = parser.parseDirectives(token); |
95 unit.lineInfo = new LineInfo(scanner.lineStarts); | 95 unit.lineInfo = new LineInfo(scanner.lineStarts); |
96 | 96 |
(...skipping 15 matching lines...) Expand all Loading... |
112 | 112 |
113 /// The group of errors collected. | 113 /// The group of errors collected. |
114 AnalyzerErrorGroup get group => | 114 AnalyzerErrorGroup get group => |
115 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); | 115 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); |
116 | 116 |
117 /// Whether any errors where collected. | 117 /// Whether any errors where collected. |
118 bool get hasErrors => !_errors.isEmpty; | 118 bool get hasErrors => !_errors.isEmpty; |
119 | 119 |
120 void onError(AnalysisError error) => _errors.add(error); | 120 void onError(AnalysisError error) => _errors.add(error); |
121 } | 121 } |
OLD | NEW |