| 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("dart:uri"); | 7 #import("dart:uri"); |
| 8 | 8 |
| 9 #import("../../../lib/compiler/implementation/elements/elements.dart"); | 9 #import("../../../lib/compiler/implementation/elements/elements.dart"); |
| 10 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 10 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 void log(message) { | 21 void log(message) { |
| 22 print(message); | 22 print(message); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 Token scan(String text) => new StringScanner(text).tokenize(); | 26 Token scan(String text) => new StringScanner(text).tokenize(); |
| 27 | 27 |
| 28 Node parseBodyCode(String text, Function parseMethod) { | 28 Node parseBodyCode(String text, Function parseMethod) { |
| 29 Token tokens = scan(text); | 29 Token tokens = scan(text); |
| 30 LoggerCanceler lc = new LoggerCanceler(); | 30 LoggerCanceler lc = new LoggerCanceler(); |
| 31 NodeListener listener = new NodeListener(lc, null); | 31 Script script = new Script(new Uri(scheme: "source"), new MockFile(text)); |
| 32 Library library = new LibraryElement(script); |
| 33 library.canUseNative = true; |
| 34 NodeListener listener = new NodeListener(lc, library); |
| 32 Parser parser = new Parser(listener); | 35 Parser parser = new Parser(listener); |
| 33 Token endToken = parseMethod(parser, tokens); | 36 Token endToken = parseMethod(parser, tokens); |
| 34 assert(endToken.kind == EOF_TOKEN); | 37 assert(endToken.kind == EOF_TOKEN); |
| 35 Node node = listener.popNode(); | 38 Node node = listener.popNode(); |
| 36 Expect.isNotNull(node); | 39 Expect.isNotNull(node); |
| 37 Expect.isTrue(listener.nodes.isEmpty(), 'Not empty: ${listener.nodes}'); | 40 Expect.isTrue(listener.nodes.isEmpty(), 'Not empty: ${listener.nodes}'); |
| 38 return node; | 41 return node; |
| 39 } | 42 } |
| 40 | 43 |
| 41 Node parseStatement(String text) => | 44 Node parseStatement(String text) => |
| (...skipping 26 matching lines...) Expand all Loading... |
| 68 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); | 71 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); |
| 69 return unit.topLevelElements; | 72 return unit.topLevelElements; |
| 70 } | 73 } |
| 71 | 74 |
| 72 // TODO(ahe): We define this method to avoid having to import | 75 // TODO(ahe): We define this method to avoid having to import |
| 73 // the scanner in the tests. We should move SourceString to another | 76 // the scanner in the tests. We should move SourceString to another |
| 74 // location instead. | 77 // location instead. |
| 75 SourceString buildSourceString(String name) { | 78 SourceString buildSourceString(String name) { |
| 76 return new SourceString(name); | 79 return new SourceString(name); |
| 77 } | 80 } |
| OLD | NEW |