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 /** | 5 /** |
6 * Parser for Dart code based on the experimental analyzer. | 6 * Parser for Dart code based on the experimental analyzer. |
7 */ | 7 */ |
8 library dart_parser; | 8 library dart_parser; |
9 | 9 |
10 import 'dart:utf'; | |
11 import 'dart:math' as math; | |
12 import 'package:analyzer_experimental/src/generated/ast.dart'; | 10 import 'package:analyzer_experimental/src/generated/ast.dart'; |
13 import 'package:analyzer_experimental/src/generated/error.dart'; | 11 import 'package:analyzer_experimental/src/generated/error.dart'; |
14 import 'package:analyzer_experimental/src/generated/parser.dart'; | 12 import 'package:analyzer_experimental/src/generated/parser.dart'; |
15 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 13 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
16 import 'package:source_maps/span.dart' show SourceFile, SourceFileSegment, Locat
ion; | 14 import 'package:source_maps/span.dart' show SourceFile, SourceFileSegment, Locat
ion; |
17 import 'info.dart'; | |
18 import 'messages.dart'; | 15 import 'messages.dart'; |
19 import 'refactor.dart' show $CR, $LF; | |
20 import 'utils.dart'; | 16 import 'utils.dart'; |
21 | 17 |
22 /** Information extracted from a source Dart file. */ | 18 /** Information extracted from a source Dart file. */ |
23 class DartCodeInfo extends Hashable { | 19 class DartCodeInfo extends Hashable { |
24 | 20 |
25 /** Library qualified identifier, if any. */ | 21 /** Library qualified identifier, if any. */ |
26 final String libraryName; | 22 final String libraryName; |
27 | 23 |
28 /** Library which the code is part-of, if any. */ | 24 /** Library which the code is part-of, if any. */ |
29 final String partOf; | 25 final String partOf; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 for (var directive in unit.directives) { | 99 for (var directive in unit.directives) { |
104 if (directive is LibraryDirective) { | 100 if (directive is LibraryDirective) { |
105 libraryName = directive.name.name; | 101 libraryName = directive.name.name; |
106 } else if (directive is PartOfDirective) { | 102 } else if (directive is PartOfDirective) { |
107 partName = directive.libraryName.name; | 103 partName = directive.libraryName.name; |
108 } else { | 104 } else { |
109 assert(directive is UriBasedDirective); | 105 assert(directive is UriBasedDirective); |
110 // Normalize the library URI. | 106 // Normalize the library URI. |
111 var uriNode = directive.uri; | 107 var uriNode = directive.uri; |
112 if (uriNode is! SimpleStringLiteral) { | 108 if (uriNode is! SimpleStringLiteral) { |
113 String uri = uriNode.accept(new ConstantEvaluator(null)); | 109 String uri = uriNode.accept(new ConstantEvaluator()); |
114 directive.uri = createStringLiteral(uri); | 110 directive.uri = createStringLiteral(uri); |
115 } | 111 } |
116 directives.add(directive); | 112 directives.add(directive); |
117 } | 113 } |
118 } | 114 } |
119 | 115 |
120 var sourceFile = offset == null | 116 var sourceFile = offset == null |
121 ? new SourceFile.text(path, code) | 117 ? new SourceFile.text(path, code) |
122 : new SourceFileSegment(path, code, offset); | 118 : new SourceFileSegment(path, code, offset); |
123 | 119 |
(...skipping 11 matching lines...) Expand all Loading... |
135 var unit = parser.parseCompilationUnit(token); | 131 var unit = parser.parseCompilationUnit(token); |
136 | 132 |
137 if (path == null || messages == null) return unit; | 133 if (path == null || messages == null) return unit; |
138 | 134 |
139 // TODO(jmesserly): removed this for now because the analyzer doesn't format | 135 // TODO(jmesserly): removed this for now because the analyzer doesn't format |
140 // messages properly, so you end up with things like "Unexpected token '%s'". | 136 // messages properly, so you end up with things like "Unexpected token '%s'". |
141 // This used to convert parser messages into our messages. Enable this | 137 // This used to convert parser messages into our messages. Enable this |
142 // once analyzer is fixed. | 138 // once analyzer is fixed. |
143 // TODO(sigmund): once we enable this, we need to fix compiler.dart to clear | 139 // TODO(sigmund): once we enable this, we need to fix compiler.dart to clear |
144 // out the output of the compiler if we see compilation errors. | 140 // out the output of the compiler if we see compilation errors. |
145 if (false) { | 141 // if (false) { |
146 var file = new SourceFile.text(path, code); | 142 // var file = new SourceFile.text(path, code); |
147 for (var e in errorListener.errors) { | 143 // for (var e in errorListener.errors) { |
148 var span = file.span(e.offset, e.offset + e.length); | 144 // var span = file.span(e.offset, e.offset + e.length); |
149 | 145 // |
150 var severity = e.errorCode.errorSeverity; | 146 // var severity = e.errorCode.errorSeverity; |
151 if (severity == ErrorSeverity.ERROR) { | 147 // if (severity == ErrorSeverity.ERROR) { |
152 messages.error(e.message, span); | 148 // messages.error(e.message, span); |
153 } else { | 149 // } else { |
154 assert(severity == ErrorSeverity.WARNING); | 150 // assert(severity == ErrorSeverity.WARNING); |
155 messages.warning(e.message, span); | 151 // messages.warning(e.message, span); |
156 } | 152 // } |
157 } | 153 // } |
158 } | 154 // } |
159 | 155 |
160 return unit; | 156 return unit; |
161 } | 157 } |
162 | 158 |
163 class _ErrorCollector extends AnalysisErrorListener { | 159 class _ErrorCollector extends AnalysisErrorListener { |
164 final errors = new List<AnalysisError>(); | 160 final errors = new List<AnalysisError>(); |
165 onError(error) => errors.add(error); | 161 onError(error) => errors.add(error); |
166 } | 162 } |
OLD | NEW |