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

Support zeroOrMore for Rule2+ #122

Open
kiritsuku opened this issue Dec 28, 2014 · 6 comments
Open

Support zeroOrMore for Rule2+ #122

kiritsuku opened this issue Dec 28, 2014 · 6 comments
Labels

Comments

@kiritsuku
Copy link

The following code

def f: RuleN[Int :: Int :: Int :: HNil] = ???
def g = rule { zeroOrMore(f) }

results in the following error:

- The optional, zeroOrMore, oneOrMore and times modifiers can only be used on rules of type 
     Rule0, Rule1[T] and Rule[I, O <: I]!

This restriction is tedious, why does it exist? I worked around the problem by nesting the return value:

def f: RuleN[(Int :: Int :: Int :: HNil) :: HNil] = ???

But this requires further overhead by constructing the return value and by destructing it afterwards. Are there other workarounds?

@sirthias
Copy link
Owner

sirthias commented Jan 2, 2015

Currently the typing is like this (one of the three possible cases):

zeroOrMore(RuleN[A :: HNil]): RuleN[Seq[A] :: HNil]

or shorter

zeroOrMore(Rule1[A]): Rule1[Seq[A]]

What would you like the type of

zeroOrMore(RuleN[A :: B :: C :: HNil])

to be?

@kiritsuku
Copy link
Author

Looking in more detail to the types, I can see why it does not work but it is still a very weird limitation and one that makes handling rules that produce multiple values a lot harder.

@sirthias
Copy link
Owner

sirthias commented Jan 5, 2015

What you want is this:

zeroOrMore(RuleN[T :: HNil]): RuleN[Seq[T] :: HNil]
zeroOrMore(RuleN[T :: T :: HNil]): RuleN[Seq[T] :: HNil]
zeroOrMore(RuleN[T :: T :: T :: HNil]): RuleN[Seq[T] :: HNil]
...

which I think is actually a reasonable request.
I'm going to reopen the ticket.

@sirthias sirthias reopened this Jan 5, 2015
@kiritsuku
Copy link
Author

Actually, what I want is

zeroOrMore(RuleN[A :: B :: C :: ... :: HNil]): RuleN[Seq[A :: B :: C :: ... :: HNil] :: HNil]

i.e. return multiple values (of different type) every time the rule is called.

@sirthias
Copy link
Owner

sirthias commented Jan 7, 2015

If that's what you want you can simply group your values into a tuple, no?

@kiritsuku
Copy link
Author

Yes indeed I can do that. Another thing I overlooked.

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

No branches or pull requests

2 participants