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

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

Issue 8441001: Prefix string literal must be identifier (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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.annotations.VisibleForTesting; 7 import com.google.common.annotations.VisibleForTesting;
8 import com.google.common.io.CharStreams; 8 import com.google.common.io.CharStreams;
9 import com.google.dart.compiler.DartCompilationError; 9 import com.google.dart.compiler.DartCompilationError;
10 import com.google.dart.compiler.DartCompilerListener; 10 import com.google.dart.compiler.DartCompilerListener;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 expect(Token.LIBRARY); 355 expect(Token.LIBRARY);
356 expect(Token.LPAREN); 356 expect(Token.LPAREN);
357 beginLiteral(); 357 beginLiteral();
358 expect(Token.STRING); 358 expect(Token.STRING);
359 DartStringLiteral libname = done(DartStringLiteral.get(ctx.getTokenString()) ); 359 DartStringLiteral libname = done(DartStringLiteral.get(ctx.getTokenString()) );
360 expectCloseParen(); 360 expectCloseParen();
361 expect(Token.SEMICOLON); 361 expect(Token.SEMICOLON);
362 return new DartLibraryDirective(libname); 362 return new DartLibraryDirective(libname);
363 } 363 }
364 364
365 private boolean VerifyStringIdentifier(String id) {
mmendez 2011/11/02 13:45:58 Nit: VerifyString... -> verifyString... Please ad
codefu 2011/11/02 14:32:57 Done.
366 boolean pass = false;
367 if(id.charAt(0) == '$') {
368 pass = id.matches("[_$a-zA-Z]([_$A-Za-z0-9]*)");
369 } else {
370 pass = id.matches("[_a-zA-Z]([_A-Za-z0-9]*)");
371 }
372 return pass;
373 }
374
365 private DartImportDirective parseImportDirective() { 375 private DartImportDirective parseImportDirective() {
366 expect(Token.IMPORT); 376 expect(Token.IMPORT);
367 expect(Token.LPAREN); 377 expect(Token.LPAREN);
368 beginLiteral(); 378 beginLiteral();
369 expect(Token.STRING); 379 expect(Token.STRING);
370 DartStringLiteral libUri = done(DartStringLiteral.get(ctx.getTokenString())) ; 380 DartStringLiteral libUri = done(DartStringLiteral.get(ctx.getTokenString())) ;
371 DartStringLiteral prefix = null; 381 DartStringLiteral prefix = null;
372 if (optional(Token.COMMA)) { 382 if (optional(Token.COMMA)) {
373 if (!optionalPseudoKeyword(PREFIX_KEYWORD)) { 383 if (!optionalPseudoKeyword(PREFIX_KEYWORD)) {
374 reportError(position(), ParserErrorCode.EXPECTED_PREFIX_KEYWORD); 384 reportError(position(), ParserErrorCode.EXPECTED_PREFIX_KEYWORD);
375 } 385 }
376 expect(Token.COLON); 386 expect(Token.COLON);
377 beginLiteral(); 387 beginLiteral();
378 expect(Token.STRING); 388 expect(Token.STRING);
389 if (!VerifyStringIdentifier(ctx.getTokenString())){
390 reportError(position(), ParserErrorCode.EXPECTED_PREFIX_IDENTIFIER);
391 }
379 prefix = done(DartStringLiteral.get(ctx.getTokenString())); 392 prefix = done(DartStringLiteral.get(ctx.getTokenString()));
380 } 393 }
381 expectCloseParen(); 394 expectCloseParen();
382 expect(Token.SEMICOLON); 395 expect(Token.SEMICOLON);
383 return new DartImportDirective(libUri, prefix); 396 return new DartImportDirective(libUri, prefix);
384 } 397 }
385 398
386 private DartSourceDirective parseSourceDirective() { 399 private DartSourceDirective parseSourceDirective() {
387 expect(Token.SOURCE); 400 expect(Token.SOURCE);
388 expect(Token.LPAREN); 401 expect(Token.LPAREN);
(...skipping 3083 matching lines...) Expand 10 before | Expand all | Expand 10 after
3472 } else { 3485 } else {
3473 ctx.error(dartError); 3486 ctx.error(dartError);
3474 errorHistory.add(dartError.hashCode()); 3487 errorHistory.add(dartError.hashCode());
3475 } 3488 }
3476 } 3489 }
3477 3490
3478 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen ts) { 3491 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen ts) {
3479 reportError(new DartCompilationError(node, errorCode, arguments)); 3492 reportError(new DartCompilationError(node, errorCode, arguments));
3480 } 3493 }
3481 } 3494 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698