Skip to content

Commit

Permalink
Cleanup sequence code generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed Jan 4, 2025
1 parent 530bb83 commit d09230a
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 68 deletions.
14 changes: 8 additions & 6 deletions bin/generate_sequence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Future<void> generateImplementation(int index) async {
// Constructor function.
out.writeln('/// Creates a [Parser] that consumes the $index parsers passed '
'as argument in ');
out.writeln('/// sequence and returns a [Record] with $index positional '
out.writeln('/// sequence and returns a [Record] with the $index positional '
'parse results.');
out.writeln('///');
out.writeln('/// For example,');
Expand All @@ -60,11 +60,13 @@ Future<void> generateImplementation(int index) async {
out.writeln('/// for the input `\'${characters.join()}\'`.');
out.writeln('@useResult');
out.writeln('Parser<(${resultTypes.join(', ')})> '
'seq$index<${resultTypes.join(', ')}>(');
for (var i = 0; i < index; i++) {
out.writeln('Parser<${resultTypes[i]}> ${parserNames[i]},');
}
out.writeln(') => SequenceParser$index<${resultTypes.join(', ')}>('
'seq$index<${resultTypes.join(', ')}>('
'${[
for (var i = 0; i < index; i++)
'Parser<${resultTypes[i]}> ${parserNames[i]}'
].join(', ')}'
') => ');
out.writeln('SequenceParser$index<${resultTypes.join(', ')}>('
'${parserNames.join(', ')});');
out.writeln();

Expand Down
7 changes: 2 additions & 5 deletions lib/src/parser/combinator/generated/sequence_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ import '../../action/map.dart';
import '../../utils/sequential.dart';

/// Creates a [Parser] that consumes the 2 parsers passed as argument in
/// sequence and returns a [Record] with 2 positional parse results.
/// sequence and returns a [Record] with the 2 positional parse results.
///
/// For example,
/// the parser `seq2(char('a'), char('b'))`
/// returns `('a', 'b')`
/// for the input `'ab'`.
@useResult
Parser<(R1, R2)> seq2<R1, R2>(
Parser<R1> parser1,
Parser<R2> parser2,
) =>
Parser<(R1, R2)> seq2<R1, R2>(Parser<R1> parser1, Parser<R2> parser2) =>
SequenceParser2<R1, R2>(parser1, parser2);

/// Extensions on a [Record] with 2 positional [Parser]s.
Expand Down
7 changes: 2 additions & 5 deletions lib/src/parser/combinator/generated/sequence_3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ import '../../action/map.dart';
import '../../utils/sequential.dart';

/// Creates a [Parser] that consumes the 3 parsers passed as argument in
/// sequence and returns a [Record] with 3 positional parse results.
/// sequence and returns a [Record] with the 3 positional parse results.
///
/// For example,
/// the parser `seq3(char('a'), char('b'), char('c'))`
/// returns `('a', 'b', 'c')`
/// for the input `'abc'`.
@useResult
Parser<(R1, R2, R3)> seq3<R1, R2, R3>(
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
) =>
Parser<R1> parser1, Parser<R2> parser2, Parser<R3> parser3) =>
SequenceParser3<R1, R2, R3>(parser1, parser2, parser3);

/// Extensions on a [Record] with 3 positional [Parser]s.
Expand Down
10 changes: 3 additions & 7 deletions lib/src/parser/combinator/generated/sequence_4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ import '../../action/map.dart';
import '../../utils/sequential.dart';

/// Creates a [Parser] that consumes the 4 parsers passed as argument in
/// sequence and returns a [Record] with 4 positional parse results.
/// sequence and returns a [Record] with the 4 positional parse results.
///
/// For example,
/// the parser `seq4(char('a'), char('b'), char('c'), char('d'))`
/// returns `('a', 'b', 'c', 'd')`
/// for the input `'abcd'`.
@useResult
Parser<(R1, R2, R3, R4)> seq4<R1, R2, R3, R4>(
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
) =>
Parser<(R1, R2, R3, R4)> seq4<R1, R2, R3, R4>(Parser<R1> parser1,
Parser<R2> parser2, Parser<R3> parser3, Parser<R4> parser4) =>
SequenceParser4<R1, R2, R3, R4>(parser1, parser2, parser3, parser4);

/// Extensions on a [Record] with 4 positional [Parser]s.
Expand Down
13 changes: 6 additions & 7 deletions lib/src/parser/combinator/generated/sequence_5.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ import '../../action/map.dart';
import '../../utils/sequential.dart';

/// Creates a [Parser] that consumes the 5 parsers passed as argument in
/// sequence and returns a [Record] with 5 positional parse results.
/// sequence and returns a [Record] with the 5 positional parse results.
///
/// For example,
/// the parser `seq5(char('a'), char('b'), char('c'), char('d'), char('e'))`
/// returns `('a', 'b', 'c', 'd', 'e')`
/// for the input `'abcde'`.
@useResult
Parser<(R1, R2, R3, R4, R5)> seq5<R1, R2, R3, R4, R5>(
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
Parser<R5> parser5,
) =>
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
Parser<R5> parser5) =>
SequenceParser5<R1, R2, R3, R4, R5>(
parser1, parser2, parser3, parser4, parser5);

Expand Down
15 changes: 7 additions & 8 deletions lib/src/parser/combinator/generated/sequence_6.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ import '../../action/map.dart';
import '../../utils/sequential.dart';

/// Creates a [Parser] that consumes the 6 parsers passed as argument in
/// sequence and returns a [Record] with 6 positional parse results.
/// sequence and returns a [Record] with the 6 positional parse results.
///
/// For example,
/// the parser `seq6(char('a'), char('b'), char('c'), char('d'), char('e'), char('f'))`
/// returns `('a', 'b', 'c', 'd', 'e', 'f')`
/// for the input `'abcdef'`.
@useResult
Parser<(R1, R2, R3, R4, R5, R6)> seq6<R1, R2, R3, R4, R5, R6>(
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
Parser<R5> parser5,
Parser<R6> parser6,
) =>
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
Parser<R5> parser5,
Parser<R6> parser6) =>
SequenceParser6<R1, R2, R3, R4, R5, R6>(
parser1, parser2, parser3, parser4, parser5, parser6);

Expand Down
17 changes: 8 additions & 9 deletions lib/src/parser/combinator/generated/sequence_7.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ import '../../action/map.dart';
import '../../utils/sequential.dart';

/// Creates a [Parser] that consumes the 7 parsers passed as argument in
/// sequence and returns a [Record] with 7 positional parse results.
/// sequence and returns a [Record] with the 7 positional parse results.
///
/// For example,
/// the parser `seq7(char('a'), char('b'), char('c'), char('d'), char('e'), char('f'), char('g'))`
/// returns `('a', 'b', 'c', 'd', 'e', 'f', 'g')`
/// for the input `'abcdefg'`.
@useResult
Parser<(R1, R2, R3, R4, R5, R6, R7)> seq7<R1, R2, R3, R4, R5, R6, R7>(
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
Parser<R5> parser5,
Parser<R6> parser6,
Parser<R7> parser7,
) =>
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
Parser<R5> parser5,
Parser<R6> parser6,
Parser<R7> parser7) =>
SequenceParser7<R1, R2, R3, R4, R5, R6, R7>(
parser1, parser2, parser3, parser4, parser5, parser6, parser7);

Expand Down
19 changes: 9 additions & 10 deletions lib/src/parser/combinator/generated/sequence_8.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ import '../../action/map.dart';
import '../../utils/sequential.dart';

/// Creates a [Parser] that consumes the 8 parsers passed as argument in
/// sequence and returns a [Record] with 8 positional parse results.
/// sequence and returns a [Record] with the 8 positional parse results.
///
/// For example,
/// the parser `seq8(char('a'), char('b'), char('c'), char('d'), char('e'), char('f'), char('g'), char('h'))`
/// returns `('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')`
/// for the input `'abcdefgh'`.
@useResult
Parser<(R1, R2, R3, R4, R5, R6, R7, R8)> seq8<R1, R2, R3, R4, R5, R6, R7, R8>(
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
Parser<R5> parser5,
Parser<R6> parser6,
Parser<R7> parser7,
Parser<R8> parser8,
) =>
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
Parser<R5> parser5,
Parser<R6> parser6,
Parser<R7> parser7,
Parser<R8> parser8) =>
SequenceParser8<R1, R2, R3, R4, R5, R6, R7, R8>(
parser1, parser2, parser3, parser4, parser5, parser6, parser7, parser8);

Expand Down
21 changes: 10 additions & 11 deletions lib/src/parser/combinator/generated/sequence_9.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../../action/map.dart';
import '../../utils/sequential.dart';

/// Creates a [Parser] that consumes the 9 parsers passed as argument in
/// sequence and returns a [Record] with 9 positional parse results.
/// sequence and returns a [Record] with the 9 positional parse results.
///
/// For example,
/// the parser `seq9(char('a'), char('b'), char('c'), char('d'), char('e'), char('f'), char('g'), char('h'), char('i'))`
Expand All @@ -19,16 +19,15 @@ import '../../utils/sequential.dart';
@useResult
Parser<(R1, R2, R3, R4, R5, R6, R7, R8, R9)>
seq9<R1, R2, R3, R4, R5, R6, R7, R8, R9>(
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
Parser<R5> parser5,
Parser<R6> parser6,
Parser<R7> parser7,
Parser<R8> parser8,
Parser<R9> parser9,
) =>
Parser<R1> parser1,
Parser<R2> parser2,
Parser<R3> parser3,
Parser<R4> parser4,
Parser<R5> parser5,
Parser<R6> parser6,
Parser<R7> parser7,
Parser<R8> parser8,
Parser<R9> parser9) =>
SequenceParser9<R1, R2, R3, R4, R5, R6, R7, R8, R9>(parser1, parser2,
parser3, parser4, parser5, parser6, parser7, parser8, parser9);

Expand Down

0 comments on commit d09230a

Please sign in to comment.