Lazy variadic not working, any alternatives?
Tofu Ninja via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon May 25 22:22:25 PDT 2015
So I was writing a simple parser and I wanted a functionality
that was basically "try list of tokens in order and if any of
them fail, rewind input".
I tried using a lazy variadic function:
bool tok_and(lazy bool[] terms ...)
{
auto backup = getInputLocation();
for(int i = 0; i < terms.length; i++)
{
if(terms[i] == false)
{
rewind(backup);
return false;
}
}
return true;
}
But this does not work because of BUG9110
https://issues.dlang.org/show_bug.cgi?id=9110
Any one have an idea how to achieve similar functionality without
a bunch of boilerplate at the call site? The lazy version would
have been nice because it would have allowed for:
if(tok_and(ident(), equal(), expression())) {...}
else if(tok_and(some(), other(), grammar())) {...}
else ...
More information about the Digitalmars-d-learn
mailing list