OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:front_end/src/fasta/parser/token_stream_rewriter.dart'; | 5 import 'package:front_end/src/fasta/parser/token_stream_rewriter.dart'; |
6 import 'package:front_end/src/fasta/scanner/precedence.dart'; | 6 import 'package:front_end/src/fasta/scanner/precedence.dart'; |
7 import 'package:front_end/src/fasta/scanner/token.dart'; | 7 import 'package:front_end/src/fasta/scanner/token.dart'; |
8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
9 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 9 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 rewriter.insertTokenBefore(d, e); | 97 rewriter.insertTokenBefore(d, e); |
98 expect(c.next, same(d)); | 98 expect(c.next, same(d)); |
99 expect(d.next, same(e)); | 99 expect(d.next, same(e)); |
100 } | 100 } |
101 | 101 |
102 /// Links together the given [tokens] and adds an EOF token to the end of the | 102 /// Links together the given [tokens] and adds an EOF token to the end of the |
103 /// token stream. | 103 /// token stream. |
104 /// | 104 /// |
105 /// The EOF token is returned. | 105 /// The EOF token is returned. |
106 Token _link(Iterable<Token> tokens) { | 106 Token _link(Iterable<Token> tokens) { |
107 Token head = new SymbolToken(EOF_INFO, -1); | 107 Token head = new SymbolToken.eof(-1); |
108 for (var token in tokens) { | 108 for (var token in tokens) { |
109 head.next = token; | 109 head.next = token; |
110 if (setPrevious) token.previousToken = head; | 110 if (setPrevious) token.previousToken = head; |
111 head = token; | 111 head = token; |
112 } | 112 } |
113 int eofOffset = head.charOffset + head.lexeme.length; | 113 int eofOffset = head.charOffset + head.lexeme.length; |
114 if (eofOffset < 0) eofOffset = 0; | 114 if (eofOffset < 0) eofOffset = 0; |
115 Token eof = new SymbolToken(EOF_INFO, eofOffset); | 115 Token eof = new SymbolToken.eof(eofOffset); |
116 head.next = eof; | 116 head.next = eof; |
117 if (setPrevious) eof.previousToken = head; | 117 if (setPrevious) eof.previousToken = head; |
118 return eof; | 118 return eof; |
119 } | 119 } |
120 | 120 |
121 BeginGroupToken _makeBeginGroupToken(int charOffset) { | 121 BeginGroupToken _makeBeginGroupToken(int charOffset) { |
122 return new BeginGroupToken(OPEN_PAREN_INFO, charOffset); | 122 return new BeginGroupToken(OPEN_PAREN_INFO, charOffset); |
123 } | 123 } |
124 | 124 |
125 StringToken _makeToken(int charOffset, String text) { | 125 StringToken _makeToken(int charOffset, String text) { |
(...skipping 14 matching lines...) Expand all Loading... |
140 /// Concrete implementation of [TokenStreamRewriterTest] in which | 140 /// Concrete implementation of [TokenStreamRewriterTest] in which |
141 /// [Token.previousToken] values are set to non-null. | 141 /// [Token.previousToken] values are set to non-null. |
142 /// | 142 /// |
143 /// Since [TokenStreamRewriter] makes use of [Token.previousToken] when it can, | 143 /// Since [TokenStreamRewriter] makes use of [Token.previousToken] when it can, |
144 /// these tests do not exercise the more complex heuristics for finding previous | 144 /// these tests do not exercise the more complex heuristics for finding previous |
145 /// tokens. | 145 /// tokens. |
146 @reflectiveTest | 146 @reflectiveTest |
147 class TokenStreamRewriterTest_UsingPrevious extends TokenStreamRewriterTest { | 147 class TokenStreamRewriterTest_UsingPrevious extends TokenStreamRewriterTest { |
148 bool get setPrevious => true; | 148 bool get setPrevious => true; |
149 } | 149 } |
OLD | NEW |