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

Side by Side Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 1536483002: Skip comments code blocks indented with 4 spaces. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library analyzer.src.generated.parser; 5 library analyzer.src.generated.parser;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 3868 matching lines...) Expand 10 before | Expand all | Expand 10 after
3879 comment, index, 0x2A, 0x20, 0x20, 0x20, 0x20, 0x20)) { 3879 comment, index, 0x2A, 0x20, 0x20, 0x20, 0x20, 0x20)) {
3880 int end = index + 6; 3880 int end = index + 6;
3881 while (end < length && 3881 while (end < length &&
3882 comment.codeUnitAt(end) != 0xD && 3882 comment.codeUnitAt(end) != 0xD &&
3883 comment.codeUnitAt(end) != 0xA) { 3883 comment.codeUnitAt(end) != 0xA) {
3884 end = end + 1; 3884 end = end + 1;
3885 } 3885 }
3886 ranges.add(<int>[index, end]); 3886 ranges.add(<int>[index, end]);
3887 index = end; 3887 index = end;
3888 } 3888 }
3889 } else if (StringUtilities.startsWith5(
3890 comment, index, 0x20, 0x20, 0x20, 0x20, 0x20)) {
Brian Wilkerson 2015/12/16 21:23:33 That looks like five spaces to me. (If we only req
scheglov 2015/12/16 21:27:06 According to https://www.dartlang.org/effective-da
Brian Wilkerson 2015/12/16 21:35:02 Given the example you showed me earlier, it's poss
scheglov 2015/12/16 22:28:18 Acknowledged.
3891 int end = index + 5;
3892 while (end < length &&
3893 comment.codeUnitAt(end) != 0xD &&
3894 comment.codeUnitAt(end) != 0xA) {
3895 end = end + 1;
3896 }
3897 ranges.add(<int>[index, end]);
3898 index = end;
3889 } else if (index + 1 < length && 3899 } else if (index + 1 < length &&
3890 currentChar == 0x5B && 3900 currentChar == 0x5B &&
3891 comment.codeUnitAt(index + 1) == 0x3A) { 3901 comment.codeUnitAt(index + 1) == 0x3A) {
3892 int end = StringUtilities.indexOf2(comment, index + 2, 0x3A, 0x5D); 3902 int end = StringUtilities.indexOf2(comment, index + 2, 0x3A, 0x5D);
3893 if (end < 0) { 3903 if (end < 0) {
3894 end = length; 3904 end = length;
3895 } 3905 }
3896 ranges.add(<int>[index, end]); 3906 ranges.add(<int>[index, end]);
3897 index = end + 1; 3907 index = end + 1;
3898 } else { 3908 } else {
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after
5036 * '[' 'new'? qualified ']' libraryReference? 5046 * '[' 'new'? qualified ']' libraryReference?
5037 * 5047 *
5038 * libraryReference ::= 5048 * libraryReference ::=
5039 * '(' stringLiteral ')' 5049 * '(' stringLiteral ')'
5040 */ 5050 */
5041 List<CommentReference> _parseCommentReferences( 5051 List<CommentReference> _parseCommentReferences(
5042 List<DocumentationCommentToken> tokens) { 5052 List<DocumentationCommentToken> tokens) {
5043 List<CommentReference> references = new List<CommentReference>(); 5053 List<CommentReference> references = new List<CommentReference>();
5044 for (DocumentationCommentToken token in tokens) { 5054 for (DocumentationCommentToken token in tokens) {
5045 String comment = token.lexeme; 5055 String comment = token.lexeme;
5046 comment = _removeGitHubCodeBlocks(comment); 5056 comment = _removeCodeBlocksGitHub(comment);
5047 int length = comment.length; 5057 int length = comment.length;
5048 List<List<int>> codeBlockRanges = _getCodeBlockRanges(comment); 5058 List<List<int>> codeBlockRanges = _getCodeBlockRanges(comment);
5049 int leftIndex = comment.indexOf('['); 5059 int leftIndex = comment.indexOf('[');
5050 while (leftIndex >= 0 && leftIndex + 1 < length) { 5060 while (leftIndex >= 0 && leftIndex + 1 < length) {
5051 List<int> range = _findRange(codeBlockRanges, leftIndex); 5061 List<int> range = _findRange(codeBlockRanges, leftIndex);
5052 if (range == null) { 5062 if (range == null) {
5053 int nameOffset = token.offset + leftIndex + 1; 5063 int nameOffset = token.offset + leftIndex + 1;
5054 int rightIndex = JavaString.indexOf(comment, ']', leftIndex); 5064 int rightIndex = JavaString.indexOf(comment, ']', leftIndex);
5055 if (rightIndex >= 0) { 5065 if (rightIndex >= 0) {
5056 int firstChar = comment.codeUnitAt(leftIndex + 1); 5066 int firstChar = comment.codeUnitAt(leftIndex + 1);
(...skipping 3169 matching lines...) Expand 10 before | Expand all | Expand 10 after
8226 * is the current token, `1` is the next token, etc. 8236 * is the current token, `1` is the next token, etc.
8227 */ 8237 */
8228 Token _peekAt(int distance) { 8238 Token _peekAt(int distance) {
8229 Token token = _currentToken; 8239 Token token = _currentToken;
8230 for (int i = 0; i < distance; i++) { 8240 for (int i = 0; i < distance; i++) {
8231 token = token.next; 8241 token = token.next;
8232 } 8242 }
8233 return token; 8243 return token;
8234 } 8244 }
8235 8245
8236 String _removeGitHubCodeBlocks(String comment) { 8246 String _removeCodeBlocksGitHub(String comment) {
8237 int index = 0; 8247 int index = 0;
8238 while (true) { 8248 while (true) {
8239 int beginIndex = comment.indexOf('`', index); 8249 int beginIndex = comment.indexOf('`', index);
8240 if (beginIndex == -1) { 8250 if (beginIndex == -1) {
8241 break; 8251 break;
8242 } 8252 }
8243 int endIndex = comment.indexOf('`', beginIndex + 1); 8253 int endIndex = comment.indexOf('`', beginIndex + 1);
8244 if (endIndex == -1) { 8254 if (endIndex == -1) {
8245 break; 8255 break;
8246 } 8256 }
(...skipping 3062 matching lines...) Expand 10 before | Expand all | Expand 10 after
11309 } 11319 }
11310 11320
11311 /** 11321 /**
11312 * Copy resolution data from the [fromNode] to the [toNode]. 11322 * Copy resolution data from the [fromNode] to the [toNode].
11313 */ 11323 */
11314 static void copyResolutionData(AstNode fromNode, AstNode toNode) { 11324 static void copyResolutionData(AstNode fromNode, AstNode toNode) {
11315 ResolutionCopier copier = new ResolutionCopier(); 11325 ResolutionCopier copier = new ResolutionCopier();
11316 copier._isEqualNodes(fromNode, toNode); 11326 copier._isEqualNodes(fromNode, toNode);
11317 } 11327 }
11318 } 11328 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698