@@ -1034,11 +1034,13 @@ public static TextParser<U> Value<T, U>(this TextParser<T> parser, U value)
1034
1034
/// <typeparam name="T">The type of value being parsed.</typeparam>
1035
1035
/// <param name="parser">The parser.</param>
1036
1036
/// <param name="predicate">The predicate to apply.</param>
1037
+ /// <param name="message">An optional error message when parsing fails.</param>
1037
1038
/// <returns>The resulting parser.</returns>
1038
- public static TokenListParser < TKind , T > Where < TKind , T > ( this TokenListParser < TKind , T > parser , Func < T , bool > predicate )
1039
+ public static TokenListParser < TKind , T > Where < TKind , T > ( this TokenListParser < TKind , T > parser , Func < T , bool > predicate , string message = "unsatisfied condition" )
1039
1040
{
1040
1041
if ( parser == null ) throw new ArgumentNullException ( nameof ( parser ) ) ;
1041
1042
if ( predicate == null ) throw new ArgumentNullException ( nameof ( predicate ) ) ;
1043
+ if ( message == null ) throw new ArgumentNullException ( nameof ( message ) ) ;
1042
1044
1043
1045
return input =>
1044
1046
{
@@ -1049,7 +1051,7 @@ public static TokenListParser<TKind, T> Where<TKind, T>(this TokenListParser<TKi
1049
1051
if ( predicate ( rt . Value ) )
1050
1052
return rt ;
1051
1053
1052
- return TokenListParserResult . Empty < TKind , T > ( input , "unsatisfied condition" ) ;
1054
+ return TokenListParserResult . Empty < TKind , T > ( input , message ) ;
1053
1055
} ;
1054
1056
}
1055
1057
@@ -1060,11 +1062,13 @@ public static TokenListParser<TKind, T> Where<TKind, T>(this TokenListParser<TKi
1060
1062
/// <typeparam name="T">The type of value being parsed.</typeparam>
1061
1063
/// <param name="parser">The parser.</param>
1062
1064
/// <param name="predicate">The predicate to apply.</param>
1065
+ /// <param name="message">An optional error message when parsing fails.</param>
1063
1066
/// <returns>The resulting parser.</returns>
1064
- public static TextParser < T > Where < T > ( this TextParser < T > parser , Func < T , bool > predicate )
1067
+ public static TextParser < T > Where < T > ( this TextParser < T > parser , Func < T , bool > predicate , string message = "unsatisfied condition" )
1065
1068
{
1066
1069
if ( parser == null ) throw new ArgumentNullException ( nameof ( parser ) ) ;
1067
1070
if ( predicate == null ) throw new ArgumentNullException ( nameof ( predicate ) ) ;
1071
+ if ( message == null ) throw new ArgumentNullException ( nameof ( message ) ) ;
1068
1072
1069
1073
return input =>
1070
1074
{
@@ -1075,7 +1079,7 @@ public static TextParser<T> Where<T>(this TextParser<T> parser, Func<T, bool> pr
1075
1079
if ( predicate ( rt . Value ) )
1076
1080
return rt ;
1077
1081
1078
- return Result . Empty < T > ( input , "unsatisfied condition" ) ;
1082
+ return Result . Empty < T > ( input , message ) ;
1079
1083
} ;
1080
1084
}
1081
1085
0 commit comments