Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: compiler/java/com/google/dart/compiler/parser/AbstractParser.java

Issue 10704180: Use 'int' instead of Position. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 package com.google.dart.compiler.parser; 5 package com.google.dart.compiler.parser;
6 6
7 import com.google.common.collect.Lists; 7 import com.google.common.collect.Lists;
8 import com.google.common.collect.Maps; 8 import com.google.common.collect.Maps;
9 import com.google.common.collect.Sets; 9 import com.google.common.collect.Sets;
10 import com.google.dart.compiler.DartCompilationError; 10 import com.google.dart.compiler.DartCompilationError;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 183
184 protected Token peek(int n) { 184 protected Token peek(int n) {
185 return ctx.peek(n); 185 return ctx.peek(n);
186 } 186 }
187 187
188 protected boolean peekPseudoKeyword(int n, String keyword) { 188 protected boolean peekPseudoKeyword(int n, String keyword) {
189 return (peek(n) == Token.IDENTIFIER) 189 return (peek(n) == Token.IDENTIFIER)
190 && keyword.equals(getPeekTokenValue(n)); 190 && keyword.equals(getPeekTokenValue(n));
191 } 191 }
192 192
193 protected DartScanner.Position position() { 193 protected int position() {
194 DartScanner.Location tokenLocation = ctx.getTokenLocation(); 194 DartScanner.Location tokenLocation = ctx.getTokenLocation();
195 return tokenLocation != null ? tokenLocation.getBegin() 195 return tokenLocation != null ? tokenLocation.getBegin() : 0;
196 : new DartScanner.Position(0, 1, 1);
197 } 196 }
198 197
199 /** 198 /**
200 * Report a syntax error, unless an error has already been reported at the 199 * Report a syntax error, unless an error has already been reported at the
201 * given or a later position. 200 * given or a later position.
202 */ 201 */
203 protected void reportError(DartScanner.Position position, 202 protected void reportError(int position,
204 ErrorCode errorCode, Object... arguments) { 203 ErrorCode errorCode, Object... arguments) {
205 DartScanner.Location location = ctx.getTokenLocation(); 204 DartScanner.Location location = ctx.getTokenLocation();
206 if (location.getBegin().getPos() <= lastErrorPosition) { 205 if (location.getBegin() <= lastErrorPosition) {
207 return; 206 return;
208 } 207 }
209 DartCompilationError dartError = new DartCompilationError(ctx.getSource(), 208 DartCompilationError dartError = new DartCompilationError(ctx.getSource(),
210 location, errorCode, arguments); 209 location, errorCode, arguments);
211 lastErrorPosition = position.getPos(); 210 lastErrorPosition = position;
212 ctx.error(dartError); 211 ctx.error(dartError);
213 } 212 }
214 213
215 /** 214 /**
216 * Even though you pass a 'Position' to {@link #reportError} above, it only 215 * Even though you pass a 'Position' to {@link #reportError} above, it only
217 * uses that to prevent logging more than one error at that position. This 216 * uses that to prevent logging more than one error at that position. This
218 * method actually uses the passed position to create the error event. 217 * method actually uses the passed position to create the error event.
219 */ 218 */
220 protected void reportErrorAtPosition(DartScanner.Position startPosition, 219 protected void reportErrorAtPosition(int startPosition,
221 DartScanner.Position endPosition, 220 int endPosition,
222 ErrorCode errorCode, Object... arguments) { 221 ErrorCode errorCode, Object... arguments) {
223 DartScanner.Location location = ctx.getTokenLocation(); 222 DartScanner.Location location = ctx.getTokenLocation();
224 if (location.getBegin().getPos() <= lastErrorPosition) { 223 if (location.getBegin() <= lastErrorPosition) {
225 return; 224 return;
226 } 225 }
227 DartCompilationError dartError = new DartCompilationError(ctx.getSource(), 226 DartCompilationError dartError = new DartCompilationError(ctx.getSource(),
228 new Location(startPosition, endPosition), errorCode, arguments); 227 new Location(startPosition, endPosition), errorCode, arguments);
229 ctx.error(dartError); 228 ctx.error(dartError);
230 } 229 }
231 230
232 protected void reportUnexpectedToken(DartScanner.Position position, 231 protected void reportUnexpectedToken(int position,
233 Token expected, Token actual) { 232 Token expected, Token actual) {
234 if (expected == Token.EOS) { 233 if (expected == Token.EOS) {
235 reportError(position, ParserErrorCode.EXPECTED_EOS, actual); 234 reportError(position, ParserErrorCode.EXPECTED_EOS, actual);
236 } else if (expected == Token.IDENTIFIER) { 235 } else if (expected == Token.IDENTIFIER) {
237 reportError(position, ParserErrorCode.INVALID_IDENTIFIER, actual); 236 reportError(position, ParserErrorCode.INVALID_IDENTIFIER, actual);
238 } else if (expected == null) { 237 } else if (expected == null) {
239 reportError(position, ParserErrorCode.UNEXPECTED_TOKEN, actual); 238 reportError(position, ParserErrorCode.UNEXPECTED_TOKEN, actual);
240 } else { 239 } else {
241 reportError(position, ParserErrorCode.EXPECTED_TOKEN, actual, expected); 240 reportError(position, ParserErrorCode.EXPECTED_TOKEN, actual, expected);
242 } 241 }
243 } 242 }
244 243
245 protected void setPeek(int n, Token token) { 244 protected void setPeek(int n, Token token) {
246 assert n == 0; // so far, n is always zero 245 assert n == 0; // so far, n is always zero
247 ctx.replaceNextToken(token); 246 ctx.replaceNextToken(token);
248 } 247 }
249 248
250 protected boolean consume(Token token) { 249 protected boolean consume(Token token) {
251 boolean result = (peek(0) == token); 250 boolean result = (peek(0) == token);
252 assert (result); 251 assert (result);
253 next(); 252 next();
254 return result; 253 return result;
255 } 254 }
256 } 255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698