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

Unified Diff: frog/leg/scanner/listener.dart

Issue 9271037: Inserted string validation as separate task in compiler. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments. Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: frog/leg/scanner/listener.dart
diff --git a/frog/leg/scanner/listener.dart b/frog/leg/scanner/listener.dart
index 55904511798dcff819328d9f996d109b052f7ef2..ecbae7ba4a6b954a04d0c994128578636071a6f0 100644
--- a/frog/leg/scanner/listener.dart
+++ b/frog/leg/scanner/listener.dart
@@ -164,6 +164,12 @@ class Listener {
void endLiteralMapEntry(Token colon, Token endToken) {
}
+ void beginLiteralString(Token token) {
+ }
+
+ void endLiteralString(int interpolationCount) {
+ }
+
void beginMember(Token token) {
}
@@ -335,9 +341,6 @@ class Listener {
void handleLiteralNull(Token token) {
}
- void handleLiteralString(Token token) {
- }
-
void handleModifier(Token token) {
}
@@ -371,7 +374,7 @@ class Listener {
void handleQualified(Token period) {
}
- void handleStringInterpolationParts(int count) {
+ void handleStringPart(Token token) {
}
void handleSuperExpression(Token token) {
@@ -454,20 +457,37 @@ class ParserError {
class ElementListener extends Listener {
final Canceler canceler;
final CompilationUnitElement compilationUnitElement;
+ final StringValidator stringValidator;
+ final List<StringQuoting> interpolationScope;
Link<Node> nodes = const EmptyLink<Node>();
- ElementListener(Canceler this.canceler,
- CompilationUnitElement this.compilationUnitElement);
+ ElementListener(Canceler canceler,
+ CompilationUnitElement this.compilationUnitElement)
+ : this.canceler = canceler,
+ stringValidator = new StringValidator(canceler),
+ interpolationScope = <StringQuoting>[];
void endLibraryTag(bool hasPrefix, Token beginToken, Token endToken) {
LiteralString prefix = null;
Identifier argumentName = null;
if (hasPrefix) {
- prefix = popNode();
+ Node prefixNode = popNode();
+ if (prefixNode is !LiteralString) {
+ canceler.cancel("String is not a compile time constant", prefixNode);
+ } else {
+ prefix = prefixNode;
+ }
Lasse Reichstein Nielsen 2012/01/26 12:06:31 Abstracted this block into popLiteralString. Chang
argumentName = popNode();
}
- LiteralString firstArgument = popNode();
+ LiteralString firstArgument = null;
+ Node firstArgumentNode = popNode();
+ if (firstArgumentNode is !LiteralString) {
+ canceler.cancel("String is not a compile time constant",
+ firstArgumentNode);
+ } else {
+ firstArgument = firstArgumentNode;
+ }
Identifier tag = popNode();
compilationUnitElement.addTag(new ScriptTag(tag, firstArgument,
argumentName, prefix,
@@ -672,15 +692,59 @@ class ElementListener extends Listener {
return new NodeList(beginToken, nodes, endToken, sourceDelimiter);
}
- void handleLiteralString(Token token) {
- pushNode(new LiteralString(token));
+ void beginLiteralString(Token token) {
+ SourceString source = token.value;
+ StringQuoting quoting = StringValidator.quotingFromString(source);
+ interpolationScope.add(quoting);
+ // Just wrap the token for now. At the end of the interpolation,
+ // when we know how many there are, go back and validate the tokens.
+ pushNode(new LiteralString(token, null));
+ }
+
+ void handleStringPart(Token token) {
+ // Just push an unvalidated token now, and replace it when we know the
+ // end of the interpolation.
+ pushNode(new LiteralString(token, null));
+ }
+
+ void endLiteralString(int count) {
+ StringQuoting quoting = interpolationScope.removeLast();
+
+ Link<StringInterpolationPart> parts =
+ const EmptyLink<StringInterpolationPart>();
+ bool isLast = true;
+ for (int i = 0; i < count; i++) {
+ LiteralString string = popNode();
+ QuotedString validation =
+ stringValidator.validateInterpolationPart(string.token, quoting,
+ isFirst: false,
+ isLast: isLast);
+ string = new LiteralString(string.token, validation);
+ Expression expression = popNode();
+ parts = parts.prepend(new StringInterpolationPart(expression, string));
+ isLast = false;
+ }
+
+ LiteralString string = popNode();
+ QuotedString validation =
+ stringValidator.validateInterpolationPart(string.token, quoting,
+ isFirst: true,
+ isLast: isLast);
+ string = new LiteralString(string.token, validation);
+ if (isLast) {
+ pushNode(string);
+ } else {
+ NodeList nodes = new NodeList(null, parts, null, null);
+ pushNode(new StringInterpolation(string, nodes));
+ }
}
}
class NodeListener extends ElementListener {
final Logger logger;
- NodeListener(Canceler canceler, Logger this.logger) : super(canceler, null);
+ NodeListener(Canceler canceler, Logger this.logger)
+ : super(canceler, null);
void endClassDeclaration(int interfacesCount, Token beginToken,
Token extendsKeyword, Token implementsKeyword,
@@ -1051,21 +1115,6 @@ class NodeListener extends ElementListener {
pushNode(new NamedArgument(name, colon, expression));
}
- void handleStringInterpolationParts(int count) {
- Link<StringInterpolationPart> parts =
- const EmptyLink<StringInterpolationPart>();
- for (int i = 0; i < count; i++) {
- LiteralString string = popNode();
- Expression expression = popNode();
- parts = parts.prepend(new StringInterpolationPart(expression, string));
- }
- if (!parts.isEmpty()) {
- LiteralString string = popNode();
- NodeList nodes = new NodeList(null, parts, null, null);
- pushNode(new StringInterpolation(string, nodes));
- }
- }
-
void endOptionalFormalParameters(int count,
Token beginToken, Token endToken) {
pushNode(makeNodeList(count, beginToken, endToken, ','));
« no previous file with comments | « frog/leg/leg.dart ('k') | frog/leg/scanner/parser.dart » ('j') | frog/leg/scanner/parser.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698