Skip to content

Commit

Permalink
WIP nullability for Parsec
Browse files Browse the repository at this point in the history
  • Loading branch information
louthy committed Dec 17, 2024
1 parent ba50661 commit 1a192e6
Show file tree
Hide file tree
Showing 5 changed files with 774 additions and 776 deletions.
2 changes: 1 addition & 1 deletion LanguageExt.Parsec/PString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public PString SetValue(string value) =>
public PString SetIndex(int index) =>
new PString(Value, index, EndIndex, Pos, DefPos, Side, UserState);

public PString SetUserState(object state) =>
public PString SetUserState(object? state) =>
new PString(Value, Index, EndIndex, Pos, DefPos, Side, state);

public PString SetEndIndex(int endIndex) =>
Expand Down
8 changes: 4 additions & 4 deletions LanguageExt.Parsec/ParsecIO.Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ public static Parser<I,O> choicei<I, O>(Seq<Parser<I, O>> ps) =>
: inp =>
{
var results = new List<O>();
ParserError error = null;
ParserError? error = null;

foreach (var p in ps)
{
var t = p(inp);

// cok
if (t.Tag == ResultTag.Consumed && t.Reply.Tag == ReplyTag.OK)
if (t is { Tag: ResultTag.Consumed, Reply.Tag: ReplyTag.OK })
{
return t;
}

// eok
if (t.Tag == ResultTag.Empty && t.Reply.Tag == ReplyTag.OK)
{
return EmptyOK<I, O>(t.Reply.Result, t.Reply.State, mergeError(error, t.Reply.Error));
return EmptyOK<I, O>(t.Reply.Result!, t.Reply.State, mergeError(error, t.Reply.Error));
}

// cerr
Expand All @@ -64,7 +64,7 @@ public static Parser<I,O> choicei<I, O>(Seq<Parser<I, O>> ps) =>
error = mergeError(error, t.Reply.Error);
}

return EmptyError<I, O>(error, inp.TokenPos);
return EmptyError<I, O>(error!, inp.TokenPos);
};

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions LanguageExt.Parsec/ParserIOs/Indent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ static ParserResult<TOKEN, A> parseBlock<TOKEN, A>(Parser<TOKEN, A> p, int start
pres.Tag,
new Reply<TOKEN, A>(
pres.Reply.Tag,
pres.Reply.Result,
pres.Reply.Result!,
new PString<TOKEN>(inp.Value, pres.Reply.State.Index, inp.EndIndex, pres.Reply.State.UserState, pres.Reply.State.TokenPos),
pres.Reply.Error));
pres.Reply.Error!));
}
}
}
2 changes: 1 addition & 1 deletion LanguageExt.Parsec/ParserIOs/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static Parser<A, A> satisfy<A>(Func<A, bool> pred) =>

if (ns.Tag == ResultTag.Consumed)
{
if (pred(ns.Reply.Result))
if (pred(ns.Reply.Result!))
{
return ns;
}
Expand Down
Loading

0 comments on commit 1a192e6

Please sign in to comment.