Skip to content

Commit fc676d0

Browse files
committed
Add some more @useResult to parser constructors.
1 parent 8e141f3 commit fc676d0

File tree

8 files changed

+34
-0
lines changed

8 files changed

+34
-0
lines changed

lib/src/debug/profile.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:meta/meta.dart';
2+
13
import '../core/parser.dart';
24
import '../parser/action/continuation.dart';
35
import '../reflection/transform.dart';
@@ -24,6 +26,7 @@ import '../shared/types.dart';
2426
///
2527
/// The optional [output] callback can be used to receive [ProfileFrame]
2628
/// objects with the full profiling information at the end of the parse.
29+
@useResult
2730
Parser<T> profile<T>(Parser<T> root,
2831
{VoidCallback<ProfileFrame> output = print, Predicate<Parser>? predicate}) {
2932
final frames = <ProfileFrame>[];

lib/src/debug/progress.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:meta/meta.dart';
2+
13
import '../context/context.dart';
24
import '../core/parser.dart';
35
import '../parser/action/continuation.dart';
@@ -27,6 +29,7 @@ import '../shared/types.dart';
2729
///
2830
/// The optional [output] callback can be used to continuously receive
2931
/// [ProgressFrame] updates with the current progress information.
32+
@useResult
3033
Parser<T> progress<T>(Parser<T> root,
3134
{VoidCallback<ProgressFrame> output = print,
3235
Predicate<Parser>? predicate}) {

lib/src/debug/trace.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:meta/meta.dart';
2+
13
import '../context/context.dart';
24
import '../context/result.dart';
35
import '../core/parser.dart';
@@ -32,6 +34,7 @@ import '../shared/types.dart';
3234
///
3335
/// The optional [output] callback can be used to continuously receive
3436
/// [TraceEvent] objects with current enter and exit data.
37+
@useResult
3538
Parser<T> trace<T>(Parser<T> root,
3639
{VoidCallback<TraceEvent> output = print, Predicate<Parser>? predicate}) {
3740
TraceEvent? parent;

lib/src/definition/grammar.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ abstract class GrammarDefinition<R> {
7171
/// The optional [start] reference specifies a different starting production
7272
/// into the grammar. The optional [arguments] list parametrizes the called
7373
/// production.
74+
@useResult
7475
Parser<T> build<T>({Function? start, List<Object> arguments = const []}) {
7576
if (start != null) {
7677
return resolve(Function.apply(start, arguments));

lib/src/definition/reference.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:meta/meta.dart';
2+
13
import '../core/parser.dart';
24
import 'internal/reference.dart';
35
import 'internal/undefined.dart';
@@ -11,6 +13,7 @@ import 'resolve.dart';
1113
/// using one of the strongly typed alternatives [ref0], [ref1], [ref2], ...
1214
/// instead.
1315
@Deprecated('Use [ref0], [ref1], [ref2], ... instead.')
16+
@useResult
1417
Parser<T> ref<T>(
1518
Function function, [
1619
dynamic arg1 = undefined,
@@ -37,12 +40,14 @@ Parser<T> ref<T>(
3740
///
3841
/// If you function takes arguments, consider one of the typed alternatives
3942
/// [ref1], [ref2], [ref3], ... instead.
43+
@useResult
4044
Parser<T> ref0<T>(Parser<T> Function() function) =>
4145
ReferenceParser<T>(function, const []);
4246

4347
/// Reference to a production [function] parametrized with 1 argument.
4448
///
4549
/// See [ref0] for a detailed description.
50+
@useResult
4651
Parser<T> ref1<T, A1>(
4752
Parser<T> Function(A1) function,
4853
A1 arg1,
@@ -52,6 +57,7 @@ Parser<T> ref1<T, A1>(
5257
/// Reference to a production [function] parametrized with 2 arguments.
5358
///
5459
/// See [ref0] for a detailed description.
60+
@useResult
5561
Parser<T> ref2<T, A1, A2>(
5662
Parser<T> Function(A1, A2) function,
5763
A1 arg1,
@@ -62,6 +68,7 @@ Parser<T> ref2<T, A1, A2>(
6268
/// Reference to a production [function] parametrized with 3 arguments.
6369
///
6470
/// See [ref0] for a detailed description.
71+
@useResult
6572
Parser<T> ref3<T, A1, A2, A3>(
6673
Parser<T> Function(A1, A2, A3) function,
6774
A1 arg1,
@@ -73,6 +80,7 @@ Parser<T> ref3<T, A1, A2, A3>(
7380
/// Reference to a production [function] parametrized with 4 arguments.
7481
///
7582
/// See [ref0] for a detailed description.
83+
@useResult
7684
Parser<T> ref4<T, A1, A2, A3, A4>(
7785
Parser<T> Function(A1, A2, A3, A4) function,
7886
A1 arg1,
@@ -85,6 +93,7 @@ Parser<T> ref4<T, A1, A2, A3, A4>(
8593
/// Reference to a production [function] parametrized with 5 arguments.
8694
///
8795
/// See [ref0] for a detailed description.
96+
@useResult
8897
Parser<T> ref5<T, A1, A2, A3, A4, A5>(
8998
Parser<T> Function(A1, A2, A3, A4, A5) function,
9099
A1 arg1,
@@ -98,6 +107,7 @@ Parser<T> ref5<T, A1, A2, A3, A4, A5>(
98107
/// Reference to a production [function] parametrized with 6 arguments.
99108
///
100109
/// See [ref0] for a detailed description.
110+
@useResult
101111
Parser<T> ref6<T, A1, A2, A3, A4, A5, A6>(
102112
Parser<T> Function(A1, A2, A3, A4, A5, A6) function,
103113
A1 arg1,
@@ -112,6 +122,7 @@ Parser<T> ref6<T, A1, A2, A3, A4, A5, A6>(
112122
/// Reference to a production [function] parametrized with 7 arguments.
113123
///
114124
/// See [ref0] for a detailed description.
125+
@useResult
115126
Parser<T> ref7<T, A1, A2, A3, A4, A5, A6, A7>(
116127
Parser<T> Function(A1, A2, A3, A4, A5, A6, A7) function,
117128
A1 arg1,
@@ -127,6 +138,7 @@ Parser<T> ref7<T, A1, A2, A3, A4, A5, A6, A7>(
127138
/// Reference to a production [function] parametrized with 8 arguments.
128139
///
129140
/// See [ref0] for a detailed description.
141+
@useResult
130142
Parser<T> ref8<T, A1, A2, A3, A4, A5, A6, A7, A8>(
131143
Parser<T> Function(A1, A2, A3, A4, A5, A6, A7, A8) function,
132144
A1 arg1,
@@ -144,6 +156,7 @@ Parser<T> ref8<T, A1, A2, A3, A4, A5, A6, A7, A8>(
144156
/// Reference to a production [function] parametrized with 9 arguments.
145157
///
146158
/// See [ref0] for a detailed description.
159+
@useResult
147160
Parser<T> ref9<T, A1, A2, A3, A4, A5, A6, A7, A8, A9>(
148161
Parser<T> Function(A1, A2, A3, A4, A5, A6, A7, A8, A9) function,
149162
A1 arg1,

lib/src/expression/builder.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:meta/meta.dart';
2+
13
import '../core/parser.dart';
24
import '../definition/resolve.dart';
35
import '../parser/combinator/settable.dart';
@@ -65,13 +67,15 @@ class ExpressionBuilder<T> {
6567
final SettableParser<T> _loopback = undefined();
6668

6769
/// Creates a new group of operators that share the same priority.
70+
@useResult
6871
ExpressionGroup<T> group() {
6972
final group = ExpressionGroup<T>(_loopback);
7073
_groups.add(group);
7174
return group;
7275
}
7376

7477
/// Builds the expression parser.
78+
@useResult
7579
Parser<T> build() {
7680
final parser = _groups.fold<Parser<T>>(
7781
failure('Highest priority group should define a primitive parser.'),

lib/src/reflection/optimize.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import 'package:meta/meta.dart';
2+
13
import '../core/parser.dart';
24
import '../parser/combinator/settable.dart';
35
import 'transform.dart';
46

57
/// Returns a copy of [parser] with all settable parsers removed.
8+
@useResult
69
@Deprecated('Use `resolve(Parser)` instead.')
710
Parser<T> removeSettables<T>(Parser<T> parser) {
811
return transformParser(parser, <R>(each) {
@@ -14,6 +17,7 @@ Parser<T> removeSettables<T>(Parser<T> parser) {
1417
}
1518

1619
/// Returns a copy of [parser] with all duplicates parsers collapsed.
20+
@useResult
1721
Parser<T> removeDuplicates<T>(Parser<T> parser) {
1822
final uniques = <Parser>{};
1923
return transformParser(parser, <R>(source) {

lib/src/reflection/transform.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:meta/meta.dart';
2+
13
import '../core/parser.dart';
24
import 'iterable.dart';
35

@@ -10,6 +12,7 @@ typedef TransformationHandler = Parser<T> Function<T>(Parser<T> parser);
1012
/// The implementation first creates a copy of each parser reachable in the
1113
/// input grammar; then the resulting grammar is traversed until all references
1214
/// to old parsers are replaced with the transformed ones.
15+
@useResult
1316
Parser<T> transformParser<T>(Parser<T> parser, TransformationHandler handler) {
1417
final mapping = Map<Parser, Parser>.identity();
1518
for (final each in allParser(parser)) {

0 commit comments

Comments
 (0)