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

Unified Diff: compiler/java/com/google/dart/compiler/parser/DartParser.java

Issue 11414175: Issue 6881. Import and part URIs can be adjacent strings (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/parser/ParserErrorCode.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/parser/DartParser.java
diff --git a/compiler/java/com/google/dart/compiler/parser/DartParser.java b/compiler/java/com/google/dart/compiler/parser/DartParser.java
index 14821111a317ee6e3e96c7c3d4e0a6b679c9108e..e6104b6a5016fcbc0011096471b38bfc2c6d1435 100644
--- a/compiler/java/com/google/dart/compiler/parser/DartParser.java
+++ b/compiler/java/com/google/dart/compiler/parser/DartParser.java
@@ -654,9 +654,7 @@ public class DartParser extends CompletionHooksParserBase {
protected DartExportDirective parseExportDirective() {
beginExportDirective();
next(); // "export"
- beginLiteral();
- expect(Token.STRING);
- DartStringLiteral libUri = done(DartStringLiteral.get(ctx.getTokenString()));
+ DartStringLiteral libUri = parseUri();
List<ImportCombinator> combinators = new ArrayList<ImportCombinator>();
while (peekPseudoKeyword(0, HIDE_KEYWORD) || peekPseudoKeyword(0, SHOW_KEYWORD)) {
@@ -682,10 +680,7 @@ public class DartParser extends CompletionHooksParserBase {
protected DartImportDirective parseImportDirective() {
beginImportDirective();
next(); // "import"
- beginLiteral();
- expect(Token.STRING);
- DartStringLiteral libUri = done(DartStringLiteral.get(ctx.getTokenString()));
-
+ DartStringLiteral libUri = parseUri();
// allow "native" if we have "dart-ext:" import
if (StringUtils.startsWith(libUri.getValue(), "dart-ext:")) {
allowNativeKeyword = true;
@@ -741,9 +736,7 @@ public class DartParser extends CompletionHooksParserBase {
reportDeprecatedError(position(), ParserErrorCode.DEPRECATED_IMPORT_DIRECTIVE);
expect(Token.LPAREN);
- beginLiteral();
- expect(Token.STRING);
- DartStringLiteral libUri = done(DartStringLiteral.get(ctx.getTokenString()));
+ DartStringLiteral libUri = parseUri();
// allow "native" if we have "dart-ext:" import
if (StringUtils.startsWith(libUri.getValue(), "dart-ext:")) {
@@ -787,9 +780,7 @@ public class DartParser extends CompletionHooksParserBase {
expect(Token.SOURCE);
reportDeprecatedError(position(), ParserErrorCode.DEPRECATED_SOURCE_DIRECTIVE);
expect(Token.LPAREN);
- beginLiteral();
- expect(Token.STRING);
- DartStringLiteral sourceUri = done(DartStringLiteral.get(ctx.getTokenString()));
+ DartStringLiteral sourceUri = parseUri();
expectCloseParen();
expect(Token.SEMICOLON);
return new DartSourceDirective(sourceUri);
@@ -809,10 +800,8 @@ public class DartParser extends CompletionHooksParserBase {
expect(Token.RESOURCE);
reportError(position(), ParserErrorCode.DEPRECATED_RESOURCE_DIRECTIVE);
expect(Token.LPAREN);
- beginLiteral();
- expect(Token.STRING);
@SuppressWarnings("unused")
- DartStringLiteral resourceUri = done(DartStringLiteral.get(ctx.getTokenString()));
+ DartStringLiteral sourceUri = parseUri();
expectCloseParen();
expect(Token.SEMICOLON);
}
@@ -820,9 +809,7 @@ public class DartParser extends CompletionHooksParserBase {
private DartNativeDirective parseNativeDirective() {
expect(Token.NATIVE);
expect(Token.LPAREN);
- beginLiteral();
- expect(Token.STRING);
- DartStringLiteral nativeUri = done(DartStringLiteral.get(ctx.getTokenString()));
+ DartStringLiteral nativeUri = parseUri();
expect(Token.RPAREN);
expect(Token.SEMICOLON);
return new DartNativeDirective(nativeUri);
@@ -2891,6 +2878,21 @@ public class DartParser extends CompletionHooksParserBase {
return offset;
}
+ private DartStringLiteral parseUri() {
+ DartExpression str = parseStringWithPasting();
+ if (str instanceof DartStringLiteral) {
+ return (DartStringLiteral) str;
+ } else if (str != null) {
+ reportError(str, ParserErrorCode.URI_CANNOT_USE_INTERPOLATION);
+ DartStringLiteral result = DartStringLiteral.get("<invalid-uri>");
+ result.setSourceInfo(str.getSourceInfo());
+ return result;
+ } else {
+ expect(Token.STRING);
+ return DartStringLiteral.get(null);
+ }
+ }
+
/**
* Instances of the class {@code DepthCounter} represent the number of less than tokens that have
* not yet been matched.
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/parser/ParserErrorCode.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698