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

Unified Diff: lib/compiler/implementation/scanner/scanner.dart

Issue 10539021: Scanner can include comments in the token stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Nested comments bug fixed Created 8 years, 6 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: lib/compiler/implementation/scanner/scanner.dart
diff --git a/lib/compiler/implementation/scanner/scanner.dart b/lib/compiler/implementation/scanner/scanner.dart
index 24f439dedf9f5cf42a2d34522f5c29c3614a0834..685bab4fb76502b7a84931d37903b4c490f03253 100644
--- a/lib/compiler/implementation/scanner/scanner.dart
+++ b/lib/compiler/implementation/scanner/scanner.dart
@@ -12,14 +12,42 @@ interface Scanner {
class AbstractScanner<T extends SourceString> implements Scanner {
abstract int advance();
abstract int nextByte();
+ /**
ahe 2012/06/22 08:42:49 Please add a newline before all the documentation
Johnni Winther 2012/06/22 10:23:10 Done.
+ * Returns the current char.
ahe 2012/06/22 08:42:49 No it doesn't :-) I think the word you're looking
Johnni Winther 2012/06/22 10:23:10 Done.
+ */
abstract int peek();
+ /**
+ * Appends a fixed token based on whether the current char is [choice] or not.
+ * If the current char is [choice] a fixed token whose kind and content
+ * is determined by [yes] is appended, otherwise a fixed token whose kind
+ * and content is determined by [no] is appended. */
abstract int select(int choice, PrecedenceInfo yes, PrecedenceInfo no);
+ /**
+ * Appends a fixed token whose kind and content is determined by [info].
+ */
abstract void appendPrecedenceToken(PrecedenceInfo info);
+ /**
+ * Appends a token whose kind is determined by [info] and content is [value].
+ */
abstract void appendStringToken(PrecedenceInfo info, String value);
+ /**
+ * Appends a token whose kind is determined by [info] and content is defined by
ahe 2012/06/22 08:42:49 Long line.
Johnni Winther 2012/06/22 10:23:10 Done.
+ * the SourceString [value].
+ */
abstract void appendByteStringToken(PrecedenceInfo info, T value);
+ /**
+ * Appends a keyword token whose kind is determined by [keyword].
+ */
abstract void appendKeywordToken(Keyword keyword);
abstract void appendWhiteSpace(int next);
abstract void appendEofToken();
+ /**
+ * Creates an ascii SourceString whose content begins at the source byte
+ * offset [start] and ends at [offset] bytes from the current byte offset of
+ * the scanner. I.e. if the current byte offset is 10, [:asciiString(0,-1):]
ahe 2012/06/22 08:42:49 A tech-writer once recommended that I avoided the
Johnni Winther 2012/06/22 10:23:10 Done.
+ * creates an ascii SourceString whose content is found at the [0,9[ byte
+ * interval of the source text.
+ */
abstract T asciiString(int start, int offset);
abstract T utf8String(int start, int offset);
abstract Token firstToken();
@@ -33,6 +61,7 @@ class AbstractScanner<T extends SourceString> implements Scanner {
abstract void appendGt(PrecedenceInfo info, String value);
abstract void appendGtGt(PrecedenceInfo info, String value);
abstract void appendGtGtGt(PrecedenceInfo info, String value);
+ abstract void appendComment();
/**
* We call this method to discard '<' from the "grouping" stack
@@ -543,6 +572,7 @@ class AbstractScanner<T extends SourceString> implements Scanner {
while (true) {
next = advance();
if ($LF === next || $CR === next || $EOF === next) {
ahe 2012/06/22 08:42:49 Should we include DOS line endings?
Johnni Winther 2012/06/22 09:55:52 The terminating character is not included in the s
+ appendComment();
return next;
}
}
@@ -560,7 +590,9 @@ class AbstractScanner<T extends SourceString> implements Scanner {
if ($SLASH === next) {
--nesting;
if (0 === nesting) {
- return advance();
+ next = advance();
+ appendComment();
+ return next;
} else {
next = advance();
}
@@ -686,7 +718,8 @@ class AbstractScanner<T extends SourceString> implements Scanner {
}
int tokenizeStringInterpolation(int start) {
- beginToken();
+ appendByteStringToken(STRING_INFO, utf8String(start, -1));
+ beginToken(); // $ starts here
ahe 2012/06/22 08:42:49 Not a proper sentence. A proper sentence starts wi
Johnni Winther 2012/06/22 10:23:10 Done.
int next = advance();
if (next === $OPEN_CURLY_BRACKET) {
return tokenizeInterpolatedExpression(next, start);
@@ -696,21 +729,24 @@ class AbstractScanner<T extends SourceString> implements Scanner {
}
int tokenizeInterpolatedExpression(int next, int start) {
- appendByteStringToken(STRING_INFO, utf8String(start, -2));
appendBeginGroup(STRING_INTERPOLATION_INFO, "\${");
+ beginToken(); // expression starts here
ahe 2012/06/22 08:42:49 Not proper sentence.
Johnni Winther 2012/06/22 10:23:10 Done.
next = advance();
while (next !== $EOF && next !== $STX) {
next = bigSwitch(next);
}
if (next === $EOF) return next;
- return advance();
+ next = advance();
+ beginToken(); // string interpolation suffix starts here
ahe 2012/06/22 08:42:49 Ditto.
Johnni Winther 2012/06/22 10:23:10 Done.
+ return next;
}
int tokenizeInterpolatedIdentifier(int next, int start) {
- appendByteStringToken(STRING_INFO, utf8String(start, -2));
- appendBeginGroup(STRING_INTERPOLATION_INFO, "\${");
+ appendBeginGroup(STRING_INTERPOLATION_INFO, "\$");
+ beginToken(); // identifier starts here
ahe 2012/06/22 08:42:49 Ditto.
Johnni Winther 2012/06/22 10:23:10 Done.
next = tokenizeKeywordOrIdentifier(next, false);
- appendEndGroup(CLOSE_CURLY_BRACKET_INFO, "}", OPEN_CURLY_BRACKET_TOKEN);
+ beginToken(); // string interpolation suffix starts here
ahe 2012/06/22 08:42:49 Ditto.
Johnni Winther 2012/06/22 10:23:10 Done.
+ appendEndGroup(CLOSE_CURLY_BRACKET_INFO, "", OPEN_CURLY_BRACKET_TOKEN);
ahe 2012/06/22 08:42:49 This is not a CLOSE_CURLE_BRACKET.
Johnni Winther 2012/06/22 10:23:10 Done.
return next;
}

Powered by Google App Engine
This is Rietveld 408576698