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

Side by Side Diff: samples/markdown/inline_parser.dart

Issue 10919146: Get rid of a lot of () for getters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /// Maintains the internal state needed to parse inline span elements in 5 /// Maintains the internal state needed to parse inline span elements in
6 /// markdown. 6 /// markdown.
7 class InlineParser { 7 class InlineParser {
8 static List<InlineSyntax> get syntaxes() { 8 static List<InlineSyntax> get syntaxes {
9 // Lazy initialize. 9 // Lazy initialize.
10 if (_syntaxes == null) { 10 if (_syntaxes == null) {
11 _syntaxes = <InlineSyntax>[ 11 _syntaxes = <InlineSyntax>[
12 new AutolinkSyntax(), 12 new AutolinkSyntax(),
13 new LinkSyntax(), 13 new LinkSyntax(),
14 // "*" surrounded by spaces is left alone. 14 // "*" surrounded by spaces is left alone.
15 new TextSyntax(@' \* '), 15 new TextSyntax(@' \* '),
16 // "_" surrounded by spaces is left alone. 16 // "_" surrounded by spaces is left alone.
17 new TextSyntax(@' _ '), 17 new TextSyntax(@' _ '),
18 // Leave already-encoded HTML entities alone. Ensures we don't turn 18 // Leave already-encoded HTML entities alone. Ensures we don't turn
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 } 115 }
116 } 116 }
117 117
118 addNode(Node node) { 118 addNode(Node node) {
119 _stack.last().children.add(node); 119 _stack.last().children.add(node);
120 } 120 }
121 121
122 // TODO(rnystrom): Only need this because RegExp doesn't let you start 122 // TODO(rnystrom): Only need this because RegExp doesn't let you start
123 // searching from a given offset. 123 // searching from a given offset.
124 String get currentSource() => source.substring(pos, source.length); 124 String get currentSource => source.substring(pos, source.length);
125 125
126 bool get isDone() => pos == source.length; 126 bool get isDone => pos == source.length;
127 127
128 void advanceBy(int length) { 128 void advanceBy(int length) {
129 pos += length; 129 pos += length;
130 } 130 }
131 131
132 void consume(int length) { 132 void consume(int length) {
133 pos += length; 133 pos += length;
134 start = pos; 134 start = pos;
135 } 135 }
136 } 136 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 parser.addNode(new Element(tag, state.children)); 220 parser.addNode(new Element(tag, state.children));
221 return true; 221 return true;
222 } 222 }
223 } 223 }
224 224
225 /// Matches inline links like `[blah] [id]` and `[blah] (url)`. 225 /// Matches inline links like `[blah] [id]` and `[blah] (url)`.
226 class LinkSyntax extends TagSyntax { 226 class LinkSyntax extends TagSyntax {
227 /// The regex for the end of a link needs to handle both reference style and 227 /// The regex for the end of a link needs to handle both reference style and
228 /// inline styles as well as optional titles for inline links. To make that 228 /// inline styles as well as optional titles for inline links. To make that
229 /// a bit more palatable, this breaks it into pieces. 229 /// a bit more palatable, this breaks it into pieces.
230 static get linkPattern() { 230 static get linkPattern {
231 final refLink = @'\s?\[([^\]]*)\]'; // "[id]" reflink id. 231 final refLink = @'\s?\[([^\]]*)\]'; // "[id]" reflink id.
232 final title = @'(?:[ ]*"([^"]+)"|)'; // Optional title in quotes. 232 final title = @'(?:[ ]*"([^"]+)"|)'; // Optional title in quotes.
233 final inlineLink = '\\s?\\(([^ )]+)$title\\)'; // "(url "title")" link. 233 final inlineLink = '\\s?\\(([^ )]+)$title\\)'; // "(url "title")" link.
234 return '\](?:($refLink|$inlineLink)|)'; 234 return '\](?:($refLink|$inlineLink)|)';
235 235
236 // The groups matched by this are: 236 // The groups matched by this are:
237 // 1: Will be non-empty if it's either a ref or inline link. Will be empty 237 // 1: Will be non-empty if it's either a ref or inline link. Will be empty
238 // if it's just a bare pair of square brackets with nothing after them. 238 // if it's just a bare pair of square brackets with nothing after them.
239 // 2: Contains the id inside [] for a reference-style link. 239 // 2: Contains the id inside [] for a reference-style link.
240 // 3: Contains the URL for an inline link. 240 // 3: Contains the URL for an inline link.
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 parser.consume(endMatch[0].length); 389 parser.consume(endMatch[0].length);
390 } else { 390 } else {
391 // Didn't close correctly so revert to text. 391 // Didn't close correctly so revert to text.
392 parser.start = startPos; 392 parser.start = startPos;
393 parser.advanceBy(endMatch[0].length); 393 parser.advanceBy(endMatch[0].length);
394 } 394 }
395 395
396 return null; 396 return null;
397 } 397 }
398 } 398 }
OLDNEW
« no previous file with comments | « samples/markdown/block_parser.dart ('k') | samples/sample_extension/sample_asynchronous_extension.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698