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

Side by Side Diff: pkg/dartdoc/lib/src/markdown/block_parser.dart

Issue 11314019: Using 'interface' and 'abstract' for methods should produce error (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /// The line contains only whitespace or is empty. 5 /// The line contains only whitespace or is empty.
6 const _RE_EMPTY = const RegExp(r'^([ \t]*)$'); 6 const _RE_EMPTY = const RegExp(r'^([ \t]*)$');
7 7
8 /// A series of `=` or `-` (on the next line) define setext-style headers. 8 /// A series of `=` or `-` (on the next line) define setext-style headers.
9 const _RE_SETEXT = const RegExp(r'^((=+)|(-+))$'); 9 const _RE_SETEXT = const RegExp(r'^((=+)|(-+))$');
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return regex.firstMatch(current) != null; 73 return regex.firstMatch(current) != null;
74 } 74 }
75 75
76 /// Gets whether or not the current line matches the given pattern. 76 /// Gets whether or not the current line matches the given pattern.
77 bool matchesNext(RegExp regex) { 77 bool matchesNext(RegExp regex) {
78 if (next == null) return false; 78 if (next == null) return false;
79 return regex.firstMatch(next) != null; 79 return regex.firstMatch(next) != null;
80 } 80 }
81 } 81 }
82 82
83 class BlockSyntax { 83 abstract class BlockSyntax {
84 /// Gets the collection of built-in block parsers. To turn a series of lines 84 /// Gets the collection of built-in block parsers. To turn a series of lines
85 /// into blocks, each of these will be tried in turn. Order matters here. 85 /// into blocks, each of these will be tried in turn. Order matters here.
86 static List<BlockSyntax> get syntaxes { 86 static List<BlockSyntax> get syntaxes {
87 // Lazy initialize. 87 // Lazy initialize.
88 if (_syntaxes == null) { 88 if (_syntaxes == null) {
89 _syntaxes = [ 89 _syntaxes = [
90 new EmptyBlockSyntax(), 90 new EmptyBlockSyntax(),
91 new BlockHtmlSyntax(), 91 new BlockHtmlSyntax(),
92 new SetextHeaderSyntax(), 92 new SetextHeaderSyntax(),
93 new HeaderSyntax(), 93 new HeaderSyntax(),
(...skipping 13 matching lines...) Expand all
107 107
108 /// Gets the regex used to identify the beginning of this block, if any. 108 /// Gets the regex used to identify the beginning of this block, if any.
109 RegExp get pattern => null; 109 RegExp get pattern => null;
110 110
111 bool get canEndBlock => true; 111 bool get canEndBlock => true;
112 112
113 bool canParse(BlockParser parser) { 113 bool canParse(BlockParser parser) {
114 return pattern.firstMatch(parser.current) != null; 114 return pattern.firstMatch(parser.current) != null;
115 } 115 }
116 116
117 abstract Node parse(BlockParser parser); 117 Node parse(BlockParser parser);
118 118
119 List<String> parseChildLines(BlockParser parser) { 119 List<String> parseChildLines(BlockParser parser) {
120 // Grab all of the lines that form the blockquote, stripping off the ">". 120 // Grab all of the lines that form the blockquote, stripping off the ">".
121 final childLines = <String>[]; 121 final childLines = <String>[];
122 122
123 while (!parser.isDone) { 123 while (!parser.isDone) {
124 final match = pattern.firstMatch(parser.current); 124 final match = pattern.firstMatch(parser.current);
125 if (match == null) break; 125 if (match == null) break;
126 childLines.add(match[1]); 126 childLines.add(match[1]);
127 parser.advance(); 127 parser.advance();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 252 }
253 253
254 class ListItem { 254 class ListItem {
255 bool forceBlock = false; 255 bool forceBlock = false;
256 final List<String> lines; 256 final List<String> lines;
257 257
258 ListItem(this.lines); 258 ListItem(this.lines);
259 } 259 }
260 260
261 /// Base class for both ordered and unordered lists. 261 /// Base class for both ordered and unordered lists.
262 class ListSyntax extends BlockSyntax { 262 abstract class ListSyntax extends BlockSyntax {
263 bool get canEndBlock => false; 263 bool get canEndBlock => false;
264 264
265 abstract String get listTag; 265 String get listTag;
266 266
267 Node parse(BlockParser parser) { 267 Node parse(BlockParser parser) {
268 final items = <ListItem>[]; 268 final items = <ListItem>[];
269 var childLines = <String>[]; 269 var childLines = <String>[];
270 270
271 endItem() { 271 endItem() {
272 if (childLines.length > 0) { 272 if (childLines.length > 0) {
273 items.add(new ListItem(childLines)); 273 items.add(new ListItem(childLines));
274 childLines = <String>[]; 274 childLines = <String>[];
275 } 275 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 while (!BlockSyntax.isAtBlockEnd(parser)) { 427 while (!BlockSyntax.isAtBlockEnd(parser)) {
428 childLines.add(parser.current); 428 childLines.add(parser.current);
429 parser.advance(); 429 parser.advance();
430 } 430 }
431 431
432 final contents = parser.document.parseInline( 432 final contents = parser.document.parseInline(
433 Strings.join(childLines, '\n')); 433 Strings.join(childLines, '\n'));
434 return new Element('p', contents); 434 return new Element('p', contents);
435 } 435 }
436 } 436 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698