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 if (!setPrevious) head.previousToken = null; |
108 for (var token in tokens) { | 109 for (var token in tokens) { |
109 head.next = token; | 110 head.next = token; |
110 if (setPrevious) token.previousToken = head; | 111 if (setPrevious) token.previousToken = head; |
111 head = token; | 112 head = token; |
112 } | 113 } |
113 int eofOffset = head.charOffset + head.lexeme.length; | 114 int eofOffset = head.charOffset + head.lexeme.length; |
114 if (eofOffset < 0) eofOffset = 0; | 115 if (eofOffset < 0) eofOffset = 0; |
115 Token eof = new SymbolToken(EOF_INFO, eofOffset); | 116 Token eof = new SymbolToken.eof(eofOffset); |
| 117 if (!setPrevious) eof.previousToken = null; |
116 head.next = eof; | 118 head.next = eof; |
117 if (setPrevious) eof.previousToken = head; | 119 if (setPrevious) eof.previousToken = head; |
118 return eof; | 120 return eof; |
119 } | 121 } |
120 | 122 |
121 BeginGroupToken _makeBeginGroupToken(int charOffset) { | 123 BeginGroupToken _makeBeginGroupToken(int charOffset) { |
122 return new BeginGroupToken(OPEN_PAREN_INFO, charOffset); | 124 return new BeginGroupToken(OPEN_PAREN_INFO, charOffset); |
123 } | 125 } |
124 | 126 |
125 StringToken _makeToken(int charOffset, String text) { | 127 StringToken _makeToken(int charOffset, String text) { |
(...skipping 14 matching lines...) Expand all Loading... |
140 /// Concrete implementation of [TokenStreamRewriterTest] in which | 142 /// Concrete implementation of [TokenStreamRewriterTest] in which |
141 /// [Token.previousToken] values are set to non-null. | 143 /// [Token.previousToken] values are set to non-null. |
142 /// | 144 /// |
143 /// Since [TokenStreamRewriter] makes use of [Token.previousToken] when it can, | 145 /// Since [TokenStreamRewriter] makes use of [Token.previousToken] when it can, |
144 /// these tests do not exercise the more complex heuristics for finding previous | 146 /// these tests do not exercise the more complex heuristics for finding previous |
145 /// tokens. | 147 /// tokens. |
146 @reflectiveTest | 148 @reflectiveTest |
147 class TokenStreamRewriterTest_UsingPrevious extends TokenStreamRewriterTest { | 149 class TokenStreamRewriterTest_UsingPrevious extends TokenStreamRewriterTest { |
148 bool get setPrevious => true; | 150 bool get setPrevious => true; |
149 } | 151 } |
OLD | NEW |