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

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

Issue 10910253: Change RegExp constructor to insist on proper named optional parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update co19/dart2js status. 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
« no previous file with comments | « runtime/lib/regexp_patch.dart ('k') | tests/co19/co19-dart2js.status » ('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) 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) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 pos += length; 133 pos += length;
134 start = pos; 134 start = pos;
135 } 135 }
136 } 136 }
137 137
138 /// Represents one kind of markdown tag that can be parsed. 138 /// Represents one kind of markdown tag that can be parsed.
139 class InlineSyntax { 139 class InlineSyntax {
140 final RegExp pattern; 140 final RegExp pattern;
141 141
142 InlineSyntax(String pattern) 142 InlineSyntax(String pattern)
143 : pattern = new RegExp(pattern, true); 143 : pattern = new RegExp(pattern, multiLine: true);
144 // TODO(rnystrom): Should use named arg for RegExp multiLine.
145 144
146 bool tryMatch(InlineParser parser) { 145 bool tryMatch(InlineParser parser) {
147 final startMatch = pattern.firstMatch(parser.currentSource); 146 final startMatch = pattern.firstMatch(parser.currentSource);
148 if ((startMatch != null) && (startMatch.start() == 0)) { 147 if ((startMatch != null) && (startMatch.start() == 0)) {
149 // Write any existing plain text up to this point. 148 // Write any existing plain text up to this point.
150 parser.writeText(); 149 parser.writeText();
151 150
152 if (onMatch(parser, startMatch)) { 151 if (onMatch(parser, startMatch)) {
153 parser.consume(startMatch[0].length); 152 parser.consume(startMatch[0].length);
154 } 153 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 197 }
199 198
200 /// Matches syntax that has a pair of tags and becomes an element, like `*` for 199 /// Matches syntax that has a pair of tags and becomes an element, like `*` for
201 /// `<em>`. Allows nested tags. 200 /// `<em>`. Allows nested tags.
202 class TagSyntax extends InlineSyntax { 201 class TagSyntax extends InlineSyntax {
203 final RegExp endPattern; 202 final RegExp endPattern;
204 final String tag; 203 final String tag;
205 204
206 TagSyntax(String pattern, [String tag, String end = null]) 205 TagSyntax(String pattern, [String tag, String end = null])
207 : super(pattern), 206 : super(pattern),
208 endPattern = new RegExp((end != null) ? end : pattern, true), 207 endPattern = new RegExp((end != null) ? end : pattern, multiLine: true),
209 tag = tag; 208 tag = tag;
210 // TODO(rnystrom): Doing this.field doesn't seem to work with named args. 209 // TODO(rnystrom): Doing this.field doesn't seem to work with named args.
211 // TODO(rnystrom): Should use named arg for RegExp multiLine.
212 210
213 bool onMatch(InlineParser parser, Match match) { 211 bool onMatch(InlineParser parser, Match match) {
214 parser._stack.add(new TagState(parser.pos, 212 parser._stack.add(new TagState(parser.pos,
215 parser.pos + match[0].length, this)); 213 parser.pos + match[0].length, this));
216 return true; 214 return true;
217 } 215 }
218 216
219 bool onMatchEnd(InlineParser parser, Match match, TagState state) { 217 bool onMatchEnd(InlineParser parser, Match match, TagState state) {
220 parser.addNode(new Element(tag, state.children)); 218 parser.addNode(new Element(tag, state.children));
221 return true; 219 return true;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 parser.consume(endMatch[0].length); 387 parser.consume(endMatch[0].length);
390 } else { 388 } else {
391 // Didn't close correctly so revert to text. 389 // Didn't close correctly so revert to text.
392 parser.start = startPos; 390 parser.start = startPos;
393 parser.advanceBy(endMatch[0].length); 391 parser.advanceBy(endMatch[0].length);
394 } 392 }
395 393
396 return null; 394 return null;
397 } 395 }
398 } 396 }
OLDNEW
« no previous file with comments | « runtime/lib/regexp_patch.dart ('k') | tests/co19/co19-dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698