dlang-community / Pegged

A Parsing Expression Grammar (PEG) module, using the D programming language.
534 stars 66 forks source link

Actions in an OR rule #96

Closed callumenator closed 11 years ago

callumenator commented 11 years ago

This:

R:
Rule <-
    / 'a' { function ParseTree(ParseTree a){return a;} }
    / 'b' { function ParseTree(ParseTree a){return a;} }

works.

This:

R:
Rule <-
    / 'a' { (a) {return a;} }
    / 'b' { (a) {return a;} }

won't compile, with the error: template instance or!(action,action) or!(action,action) is nested in both action!(literal,lambda2) and action!(literal,lambda4)

The lambdas are delegates I guess, and apparently this is not allowed. Do you guys know a workaround for this? It kinda limits the usefulness of lambdas as actions.

PhilippeSigaud commented 11 years ago

Yeah, DMD bug I guess.

(ParseTree a) { return a;}
(ParseTree a) { return a;}

works. Also:

(a) { return a;}
(ParseTree a) { return a;}

or:

(ParseTree a) { return a;}
(a) { return a;}

but not:

(a) { return a;}
(a) { return a;}
callumenator commented 11 years ago

Oh if

(ParseTree a) { return a;}
(ParseTree a) { return a;}

works thats ok, that's still concise. Maybe it tries to close over an a in the second case. Thanks!