Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nblumhardt committed Jul 5, 2021
1 parent 652c72e commit ee30214
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Sprache/Parse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Global

namespace Sprache
{
Expand Down Expand Up @@ -284,7 +287,7 @@ public static Parser<IEnumerable<T>> Many<T>(this Parser<T> parser)
/// unqualified counterparts.
/// </para>
/// </remarks>
/// <seealso cref="XOr"/>
/// <seealso cref="XOr{T}"/>
public static Parser<IEnumerable<T>> XMany<T>(this Parser<T> parser)
{
if (parser == null) throw new ArgumentNullException(nameof(parser));
Expand Down Expand Up @@ -389,7 +392,7 @@ public static Parser<T> Ref<T>(Func<Parser<T>> reference)
if (i.Memos.ContainsKey(p))
{
var pResult = i.Memos[p] as IResult<T>;
var pResult = (IResult<T>)i.Memos[p];
if (pResult.WasSuccessful)
return pResult;
throw new ParseException(pResult.ToString());
Expand Down Expand Up @@ -593,7 +596,7 @@ public static Parser<T> Return<T>(T value)
/// <returns></returns>
public static Parser<IEnumerable<T>> Until<T, U>(this Parser<T> parser, Parser<U> until)
{
return parser.Except(until).Many().Then(r => until.Return(r));
return parser.Except(until).Many().Then(until.Return);
}

/// <summary>
Expand All @@ -610,7 +613,7 @@ public static Parser<T> Where<T>(this Parser<T> parser, Func<T, bool> predicate)

return i => parser(i).IfSuccess(s =>
predicate(s.Value) ? s : Result.Failure<T>(i,
string.Format("Unexpected {0}.", s.Value),
$"Unexpected {s.Value}.",
new string[0]));
}

Expand Down Expand Up @@ -686,9 +689,9 @@ public static Parser<T> Where<T>(this Parser<T> parser, Func<T, bool> predicate)
if (op == null) throw new ArgumentNullException(nameof(op));
if (operand == null) throw new ArgumentNullException(nameof(operand));
if (apply == null) throw new ArgumentNullException(nameof(apply));
return or(op.Then(opvalue =>
return or(op.Then(opValue =>
operand.Then(operandValue =>
ChainOperatorRest(apply(opvalue, firstOperand, operandValue), op, operand, apply, or))),
ChainOperatorRest(apply(opValue, firstOperand, operandValue), op, operand, apply, or))),
Return(firstOperand));
}

Expand Down Expand Up @@ -742,10 +745,10 @@ public static Parser<T> Where<T>(this Parser<T> parser, Func<T, bool> predicate)
if (op == null) throw new ArgumentNullException(nameof(op));
if (operand == null) throw new ArgumentNullException(nameof(operand));
if (apply == null) throw new ArgumentNullException(nameof(apply));
return or(op.Then(opvalue =>
return or(op.Then(opValue =>
operand.Then(operandValue =>
ChainRightOperatorRest(operandValue, op, operand, apply, or)).Then(r =>
Return(apply(opvalue, lastOperand, r)))),
Return(apply(opValue, lastOperand, r)))),
Return(lastOperand));
}

Expand Down

0 comments on commit ee30214

Please sign in to comment.