Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

And and Xand to go along with Or and Xor? #146

Open
Shadowblitz16 opened this issue Jan 26, 2020 · 1 comment
Open

And and Xand to go along with Or and Xor? #146

Shadowblitz16 opened this issue Jan 26, 2020 · 1 comment

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented Jan 26, 2020

is it possible to create a And and Xand method to go along with Or and Xor?

if so can it be implemented?
and if it can't be implemented how would I go about making a check method so I can easily?

public static Parser<string>  Not(this Parser<string> first)                        => ParseCheck(!Check(first));
public static Parser<string>  And(this Parser<string> first, Parser<string> second) => ParseCheck(Check(first) && Check(second));
public static Parser<string>   Or(this Parser<string> first, Parser<string> second) => ParseCheck(Check(first) || Check(second));

private Parser<string> ParseCheck(bool v)
{
    throw new NotImplementedException();
}

private bool Check(Parser<string> first)
{
    throw new NotImplementedException();
}
@delreluca
Copy link
Contributor

What should the semantics of And be? If both parsers consume different parts of the input, Sprache will have to run both parsers, stop if any of them returns an error, and then decide for either the left or right one for continuation. So there actually exist two forms, AndLeft and AndRight.

Not already exists in Sprache, but it will return a null result, but you could use Except as alternative, just need to specify a base case parser (any character or something like that).

Your Check signature cannot work, as there is no input to evaluate in the arguments. Your ParseCheck can be implemented by using Where and an appropriate base case parser (e.g. from cs in Parse.AnyChar.Many() from _ in Parse.End() select new string(cs.ToArray()))).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants