Chromium Code Reviews| Index: pkg/analyzer/lib/analyzer.dart |
| diff --git a/pkg/analyzer/lib/analyzer.dart b/pkg/analyzer/lib/analyzer.dart |
| index fc9cfa11e3080626f3bb8446759a0869fb3481b9..0758cad7d7da287e9535d354ae83624f86ba907b 100644 |
| --- a/pkg/analyzer/lib/analyzer.dart |
| +++ b/pkg/analyzer/lib/analyzer.dart |
| @@ -69,6 +69,30 @@ CompilationUnit parseCompilationUnit(String contents, |
| return unit; |
| } |
| +/// Parses the script tag and directives in a string of Dart code into an AST. |
| +/// |
| +/// Stops parsing when the first non-directive is encountered. The rest of the |
| +/// string will not be parsed. |
| +/// |
| +/// If [name] is passed, it's used in error messages as the name of the code |
| +/// being parsed. |
|
nweiz
2014/06/03 21:23:09
Document [suppressErrors] as well.
Bob Nystrom
2014/06/03 21:46:59
Done.
|
| +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 :).
|
| + {String name, bool suppressErrors: false}) { |
| + if (name == null) name = '<unknown source>'; |
| + var source = new StringSource(contents, name); |
| + var errorCollector = new _ErrorCollector(); |
| + var reader = new CharSequenceReader(contents); |
| + var scanner = new Scanner(source, reader, errorCollector); |
| + var token = scanner.tokenize(); |
| + var parser = new Parser(source, errorCollector); |
| + var unit = parser.parseDirectives(token); |
| + unit.lineInfo = new LineInfo(scanner.lineStarts); |
| + |
| + if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group; |
| + |
| + return unit; |
| +} |
| + |
| /// Converts an AST node representing a string literal into a [String]. |
| String stringLiteralToString(StringLiteral literal) { |
| return literal.stringValue; |