From d09230aef45f7028bc122d5e8ac64afa81e78fcf Mon Sep 17 00:00:00 2001 From: Lukas Renggli Date: Sat, 4 Jan 2025 15:23:41 +0100 Subject: [PATCH] Cleanup sequence code generation. --- bin/generate_sequence.dart | 14 +++++++------ .../combinator/generated/sequence_2.dart | 7 ++----- .../combinator/generated/sequence_3.dart | 7 ++----- .../combinator/generated/sequence_4.dart | 10 +++------ .../combinator/generated/sequence_5.dart | 13 ++++++------ .../combinator/generated/sequence_6.dart | 15 +++++++------ .../combinator/generated/sequence_7.dart | 17 +++++++-------- .../combinator/generated/sequence_8.dart | 19 ++++++++--------- .../combinator/generated/sequence_9.dart | 21 +++++++++---------- 9 files changed, 55 insertions(+), 68 deletions(-) diff --git a/bin/generate_sequence.dart b/bin/generate_sequence.dart index a6b6888e..c854715c 100644 --- a/bin/generate_sequence.dart +++ b/bin/generate_sequence.dart @@ -49,7 +49,7 @@ Future 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,'); @@ -60,11 +60,13 @@ Future 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(); diff --git a/lib/src/parser/combinator/generated/sequence_2.dart b/lib/src/parser/combinator/generated/sequence_2.dart index 93162acb..d559a597 100644 --- a/lib/src/parser/combinator/generated/sequence_2.dart +++ b/lib/src/parser/combinator/generated/sequence_2.dart @@ -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( - Parser parser1, - Parser parser2, -) => +Parser<(R1, R2)> seq2(Parser parser1, Parser parser2) => SequenceParser2(parser1, parser2); /// Extensions on a [Record] with 2 positional [Parser]s. diff --git a/lib/src/parser/combinator/generated/sequence_3.dart b/lib/src/parser/combinator/generated/sequence_3.dart index 3797e2f2..f6082268 100644 --- a/lib/src/parser/combinator/generated/sequence_3.dart +++ b/lib/src/parser/combinator/generated/sequence_3.dart @@ -10,7 +10,7 @@ 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'))` @@ -18,10 +18,7 @@ import '../../utils/sequential.dart'; /// for the input `'abc'`. @useResult Parser<(R1, R2, R3)> seq3( - Parser parser1, - Parser parser2, - Parser parser3, -) => + Parser parser1, Parser parser2, Parser parser3) => SequenceParser3(parser1, parser2, parser3); /// Extensions on a [Record] with 3 positional [Parser]s. diff --git a/lib/src/parser/combinator/generated/sequence_4.dart b/lib/src/parser/combinator/generated/sequence_4.dart index 41070185..78be8f01 100644 --- a/lib/src/parser/combinator/generated/sequence_4.dart +++ b/lib/src/parser/combinator/generated/sequence_4.dart @@ -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( - Parser parser1, - Parser parser2, - Parser parser3, - Parser parser4, -) => +Parser<(R1, R2, R3, R4)> seq4(Parser parser1, + Parser parser2, Parser parser3, Parser parser4) => SequenceParser4(parser1, parser2, parser3, parser4); /// Extensions on a [Record] with 4 positional [Parser]s. diff --git a/lib/src/parser/combinator/generated/sequence_5.dart b/lib/src/parser/combinator/generated/sequence_5.dart index bc709a66..2778c642 100644 --- a/lib/src/parser/combinator/generated/sequence_5.dart +++ b/lib/src/parser/combinator/generated/sequence_5.dart @@ -10,7 +10,7 @@ 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'))` @@ -18,12 +18,11 @@ import '../../utils/sequential.dart'; /// for the input `'abcde'`. @useResult Parser<(R1, R2, R3, R4, R5)> seq5( - Parser parser1, - Parser parser2, - Parser parser3, - Parser parser4, - Parser parser5, -) => + Parser parser1, + Parser parser2, + Parser parser3, + Parser parser4, + Parser parser5) => SequenceParser5( parser1, parser2, parser3, parser4, parser5); diff --git a/lib/src/parser/combinator/generated/sequence_6.dart b/lib/src/parser/combinator/generated/sequence_6.dart index 71903b81..11293187 100644 --- a/lib/src/parser/combinator/generated/sequence_6.dart +++ b/lib/src/parser/combinator/generated/sequence_6.dart @@ -10,7 +10,7 @@ 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'))` @@ -18,13 +18,12 @@ import '../../utils/sequential.dart'; /// for the input `'abcdef'`. @useResult Parser<(R1, R2, R3, R4, R5, R6)> seq6( - Parser parser1, - Parser parser2, - Parser parser3, - Parser parser4, - Parser parser5, - Parser parser6, -) => + Parser parser1, + Parser parser2, + Parser parser3, + Parser parser4, + Parser parser5, + Parser parser6) => SequenceParser6( parser1, parser2, parser3, parser4, parser5, parser6); diff --git a/lib/src/parser/combinator/generated/sequence_7.dart b/lib/src/parser/combinator/generated/sequence_7.dart index 00bacc3c..4b2c3886 100644 --- a/lib/src/parser/combinator/generated/sequence_7.dart +++ b/lib/src/parser/combinator/generated/sequence_7.dart @@ -10,7 +10,7 @@ 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'))` @@ -18,14 +18,13 @@ import '../../utils/sequential.dart'; /// for the input `'abcdefg'`. @useResult Parser<(R1, R2, R3, R4, R5, R6, R7)> seq7( - Parser parser1, - Parser parser2, - Parser parser3, - Parser parser4, - Parser parser5, - Parser parser6, - Parser parser7, -) => + Parser parser1, + Parser parser2, + Parser parser3, + Parser parser4, + Parser parser5, + Parser parser6, + Parser parser7) => SequenceParser7( parser1, parser2, parser3, parser4, parser5, parser6, parser7); diff --git a/lib/src/parser/combinator/generated/sequence_8.dart b/lib/src/parser/combinator/generated/sequence_8.dart index 3711b1ca..0da50f38 100644 --- a/lib/src/parser/combinator/generated/sequence_8.dart +++ b/lib/src/parser/combinator/generated/sequence_8.dart @@ -10,7 +10,7 @@ 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'))` @@ -18,15 +18,14 @@ import '../../utils/sequential.dart'; /// for the input `'abcdefgh'`. @useResult Parser<(R1, R2, R3, R4, R5, R6, R7, R8)> seq8( - Parser parser1, - Parser parser2, - Parser parser3, - Parser parser4, - Parser parser5, - Parser parser6, - Parser parser7, - Parser parser8, -) => + Parser parser1, + Parser parser2, + Parser parser3, + Parser parser4, + Parser parser5, + Parser parser6, + Parser parser7, + Parser parser8) => SequenceParser8( parser1, parser2, parser3, parser4, parser5, parser6, parser7, parser8); diff --git a/lib/src/parser/combinator/generated/sequence_9.dart b/lib/src/parser/combinator/generated/sequence_9.dart index f4e55a13..23b23978 100644 --- a/lib/src/parser/combinator/generated/sequence_9.dart +++ b/lib/src/parser/combinator/generated/sequence_9.dart @@ -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'))` @@ -19,16 +19,15 @@ import '../../utils/sequential.dart'; @useResult Parser<(R1, R2, R3, R4, R5, R6, R7, R8, R9)> seq9( - Parser parser1, - Parser parser2, - Parser parser3, - Parser parser4, - Parser parser5, - Parser parser6, - Parser parser7, - Parser parser8, - Parser parser9, -) => + Parser parser1, + Parser parser2, + Parser parser3, + Parser parser4, + Parser parser5, + Parser parser6, + Parser parser7, + Parser parser8, + Parser parser9) => SequenceParser9(parser1, parser2, parser3, parser4, parser5, parser6, parser7, parser8, parser9);