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 | 8 |
9 import "package:compiler/src/elements/elements.dart"; | 9 import "package:compiler/src/elements/elements.dart"; |
10 import "package:compiler/src/tree/tree.dart"; | 10 import "package:compiler/src/tree/tree.dart"; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return element.parseNode(compiler); | 95 return element.parseNode(compiler); |
96 } | 96 } |
97 | 97 |
98 Node parseMember(String text, {DiagnosticListener diagnosticHandler}) { | 98 Node parseMember(String text, {DiagnosticListener diagnosticHandler}) { |
99 return parseBodyCode(text, (parser, tokens) => parser.parseMember(tokens), | 99 return parseBodyCode(text, (parser, tokens) => parser.parseMember(tokens), |
100 diagnosticHandler: diagnosticHandler); | 100 diagnosticHandler: diagnosticHandler); |
101 } | 101 } |
102 | 102 |
103 class MockFile extends StringSourceFile { | 103 class MockFile extends StringSourceFile { |
104 MockFile(text) | 104 MockFile(text) |
105 : super('<string>', text); | 105 : super.fromName('<string>', text); |
106 } | 106 } |
107 | 107 |
108 var sourceCounter = 0; | 108 var sourceCounter = 0; |
109 | 109 |
110 Link<Element> parseUnit(String text, Compiler compiler, | 110 Link<Element> parseUnit(String text, Compiler compiler, |
111 LibraryElement library, | 111 LibraryElement library, |
112 [void registerSource(Uri uri, String source)]) { | 112 [void registerSource(Uri uri, String source)]) { |
113 Token tokens = scan(text); | 113 Token tokens = scan(text); |
114 Uri uri = new Uri(scheme: "source", path: '${++sourceCounter}'); | 114 Uri uri = new Uri(scheme: "source", path: '${++sourceCounter}'); |
115 if (registerSource != null) { | 115 if (registerSource != null) { |
116 registerSource(uri, text); | 116 registerSource(uri, text); |
117 } | 117 } |
118 var script = new Script(uri, uri, new MockFile(text)); | 118 var script = new Script(uri, uri, new MockFile(text)); |
119 var unit = new CompilationUnitElementX(script, library); | 119 var unit = new CompilationUnitElementX(script, library); |
120 int id = 0; | 120 int id = 0; |
121 ElementListener listener = new ElementListener(compiler, unit, () => id++); | 121 ElementListener listener = new ElementListener(compiler, unit, () => id++); |
122 PartialParser parser = new PartialParser(listener); | 122 PartialParser parser = new PartialParser(listener); |
123 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); | 123 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); |
124 return unit.localMembers; | 124 return unit.localMembers; |
125 } | 125 } |
126 | 126 |
127 NodeList fullParseUnit(String source, {DiagnosticListener diagnosticHandler}) { | 127 NodeList fullParseUnit(String source, {DiagnosticListener diagnosticHandler}) { |
128 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), | 128 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), |
129 diagnosticHandler: diagnosticHandler); | 129 diagnosticHandler: diagnosticHandler); |
130 } | 130 } |
OLD | NEW |