| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 parser_helper; | 5 library parser_helper; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import "dart:uri"; | 8 import "dart:uri"; |
| 9 | 9 |
| 10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t"; | 10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t"; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 Node parseMember(String text, {DiagnosticListener diagnosticHandler}) { | 71 Node parseMember(String text, {DiagnosticListener diagnosticHandler}) { |
| 72 return parseBodyCode(text, (parser, tokens) => parser.parseMember(tokens), | 72 return parseBodyCode(text, (parser, tokens) => parser.parseMember(tokens), |
| 73 diagnosticHandler: diagnosticHandler); | 73 diagnosticHandler: diagnosticHandler); |
| 74 } | 74 } |
| 75 | 75 |
| 76 class MockFile extends SourceFile { | 76 class MockFile extends SourceFile { |
| 77 MockFile(text) | 77 MockFile(text) |
| 78 : super('<string>', text); | 78 : super('<string>', text); |
| 79 } | 79 } |
| 80 | 80 |
| 81 var sourceCounter = 0; |
| 82 |
| 81 Link<Element> parseUnit(String text, Compiler compiler, | 83 Link<Element> parseUnit(String text, Compiler compiler, |
| 82 LibraryElement library) { | 84 LibraryElement library, |
| 85 [void registerSource(Uri uri, String source)]) { |
| 83 Token tokens = scan(text); | 86 Token tokens = scan(text); |
| 84 Uri uri = new Uri.fromComponents(scheme: "source"); | 87 Uri uri = |
| 88 new Uri.fromComponents(scheme: "source", path: '${++sourceCounter}'); |
| 89 if (registerSource != null) { |
| 90 registerSource(uri, text); |
| 91 } |
| 85 var script = new Script(uri, new MockFile(text)); | 92 var script = new Script(uri, new MockFile(text)); |
| 86 var unit = new CompilationUnitElementX(script, library); | 93 var unit = new CompilationUnitElementX(script, library); |
| 87 int id = 0; | 94 int id = 0; |
| 88 ElementListener listener = new ElementListener(compiler, unit, () => id++); | 95 ElementListener listener = new ElementListener(compiler, unit, () => id++); |
| 89 PartialParser parser = new PartialParser(listener); | 96 PartialParser parser = new PartialParser(listener); |
| 90 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); | 97 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); |
| 91 return unit.localMembers; | 98 return unit.localMembers; |
| 92 } | 99 } |
| 93 | 100 |
| 94 NodeList fullParseUnit(String source, {DiagnosticListener diagnosticHandler}) { | 101 NodeList fullParseUnit(String source, {DiagnosticListener diagnosticHandler}) { |
| 95 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), | 102 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), |
| 96 diagnosticHandler: diagnosticHandler); | 103 diagnosticHandler: diagnosticHandler); |
| 97 } | 104 } |
| 98 | 105 |
| 99 // TODO(ahe): We define this method to avoid having to import | 106 // TODO(ahe): We define this method to avoid having to import |
| 100 // the scanner in the tests. We should move SourceString to another | 107 // the scanner in the tests. We should move SourceString to another |
| 101 // location instead. | 108 // location instead. |
| 102 SourceString buildSourceString(String name) { | 109 SourceString buildSourceString(String name) { |
| 103 return new SourceString(name); | 110 return new SourceString(name); |
| 104 } | 111 } |
| OLD | NEW |