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

Side by Side Diff: petitparser/lib/src/core/parsers.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « petitparser/lib/src/core/parser.dart ('k') | petitparser/lib/src/core/predicates.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 part of petitparser;
2
3 /**
4 * Returns a parser that consumes nothing and succeeds.
5 *
6 * For example, `char('a').or(epsilon())` is equivalent to
7 * `char('a').optional()`.
8 */
9 Parser epsilon([result]) => new EpsilonParser(result);
10
11 /**
12 * A parser that consumes nothing and succeeds.
13 */
14 class EpsilonParser extends Parser {
15 final _result;
16
17 EpsilonParser(this._result);
18
19 @override
20 Result parseOn(Context context) => context.success(_result);
21
22 @override
23 Parser copy() => new EpsilonParser(_result);
24
25 @override
26 bool hasEqualProperties(Parser other) {
27 return other is EpsilonParser
28 && super.hasEqualProperties(other)
29 && _result == other._result;
30 }
31 }
32
33 /**
34 * Returns a parser that consumes nothing and fails.
35 *
36 * For example, `failure()` always fails, no matter what input it is given.
37 */
38 Parser failure([String message = 'unable to parse']) {
39 return new FailureParser(message);
40 }
41
42 /**
43 * A parser that consumes nothing and fails.
44 */
45 class FailureParser extends Parser {
46 final String _message;
47
48 FailureParser(this._message);
49
50 @override
51 Result parseOn(Context context) => context.failure(_message);
52
53 @override
54 String toString() => '${super.toString()}[$_message]';
55
56 @override
57 Parser copy() => new FailureParser(_message);
58
59 @override
60 bool hasEqualProperties(Parser other) {
61 return other is FailureParser
62 && super.hasEqualProperties(other)
63 && _message == other._message;
64 }
65 }
66
67 /**
68 * Returns a parser that is not defined, but that can be set at a later
69 * point in time.
70 *
71 * For example, the following code sets up a parser that points to itself
72 * and that accepts a sequence of a's ended with the letter b.
73 *
74 * var p = undefined();
75 * p.set(char('a').seq(p).or(char('b')));
76 */
77 SettableParser undefined([String message = 'undefined parser']) {
78 return failure(message).settable();
79 }
80
81 /**
82 * A parser that is not defined, but that can be set at a later
83 * point in time.
84 */
85 class SettableParser extends DelegateParser {
86 SettableParser(parser) : super(parser);
87
88 /**
89 * Sets the receiver to delegate to [parser].
90 */
91 void set(Parser parser) => replace(children[0], parser);
92
93 @override
94 Parser copy() => new SettableParser(_delegate);
95 }
OLDNEW
« no previous file with comments | « petitparser/lib/src/core/parser.dart ('k') | petitparser/lib/src/core/predicates.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698