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

Unified Diff: pkg/analyzer/lib/src/services/writer.dart

Issue 132983008: Line pre-chunking. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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
« no previous file with comments | « no previous file | pkg/analyzer/test/services/formatter_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/services/writer.dart
===================================================================
--- pkg/analyzer/lib/src/services/writer.dart (revision 31927)
+++ pkg/analyzer/lib/src/services/writer.dart (working copy)
@@ -95,6 +95,8 @@
List<Chunk> breakLine(Line line) {
+ var tokens = preprocess(line.tokens);
+
var chunks = <Chunk>[];
// The current unbroken line
@@ -104,7 +106,7 @@
// absorbed into 'current'
var work = new Chunk(maxLength: maxLength);
- line.tokens.forEach((tok) {
+ tokens.forEach((tok) {
if (goodStart(tok, work)) {
if (current.fits(work)) {
@@ -141,6 +143,37 @@
return chunks;
}
+ static List<LineToken> preprocess(List<LineToken> tok) {
+
+ var tokens = <LineToken>[];
+ var curr;
+
+ tok.forEach((token){
+ if (token is! SpaceToken) {
+ if (curr == null) {
+ curr = token;
+ } else {
+ curr = merge(curr, token);
+ }
+ } else {
+ if (curr != null) {
+ tokens.add(curr);
+ curr = null;
+ }
+ tokens.add(token);
+ }
+ });
+
+ if (curr != null) {
+ tokens.add(curr);
+ }
+
+ return tokens;
+ }
+
+ static LineToken merge(LineToken first, LineToken second) =>
+ new LineToken(first.value + second.value);
+
bool isAllWhitespace(Chunk chunk) => isWhitespace(chunk.buffer.toString());
/// Test whether this token is a good start for a new working chunk
« no previous file with comments | « no previous file | pkg/analyzer/test/services/formatter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698