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

Until(Func<char, bool>) and Where(Func<string, bool>) #145

Open
Shadowblitz16 opened this issue Jan 25, 2020 · 0 comments
Open

Until(Func<char, bool>) and Where(Func<string, bool>) #145

Shadowblitz16 opened this issue Jan 25, 2020 · 0 comments

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented Jan 25, 2020

is there a way to do this with the framework?
Until is kinda useless because we can't compare the current char or string to a char, char[], string or string[].

{
    public static class MyParser
    {
        internal static Parser<string> Str(this Parser<char> self) => self.Many().Select(s => string.Concat(s));

        internal static Parser<char>   OneOf(params char[] n) => Parse.AnyChar.Until(c => n.ContainsOne(c));
        internal static Parser<char>   AnyOf(params char[] n) => Parse.AnyChar.Where(c => n.ContainsAny(c));
        internal static Parser<char>   AllOf(params char[] n) => Parse.AnyChar.Where(c => n.ContainsAll(c));
        
        internal static Parser<string> While(this Parser<char> self, Func<string, bool> pred) => self.Str().Where(pred);
        internal static Parser<string> Until(this Parser<char> self, Func<string, bool> pred) => self.Str().Until(pred);

    }

if not can this be added?

EDIT2:

@Shadowblitz16 Shadowblitz16 changed the title Until(Predicate<char>) and Until(Predicate<string>) Until(Func<char, bool>) and Where(Func<string, bool>) Jan 26, 2020
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

1 participant