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

rules & enums & final switch usage #156

Open
Robert-M-Muench opened this issue May 18, 2015 · 3 comments
Open

rules & enums & final switch usage #156

Robert-M-Muench opened this issue May 18, 2015 · 3 comments

Comments

@Robert-M-Muench
Copy link

Hi, I have written a quite complex set of templates, mixins, and conversions to derive an enum from the rules, that can be used in a final switch statement so that the compiler will catch cases that are not handled.

Like this:

// generate ENUM with all our rules for final switch
mixin(generateEnum!MyGrammer("rules"));

// reduce string rule name to enum member, special handling of base rule
auto rule_name = p.name.replaceFirst("MyGrammer.","");
if(rule_name == "MyGrammer") {rule_name = "empty";}

// convert string to enum type
final switch (rule_name.to!rules) {
    case rules.empty: ... 
    case rules.pBlock: ...
    case rules.pValues: ...
    ...

I think being able to use final switch with a PEG to handle cases would be a very useful generic pattern.

  1. Is there a better way to get the same effect with what's already available in PEG?
  2. How about adding something like this to PEG so that one can reference an enum directly?
@PhilippeSigaud
Copy link
Collaborator

PhilippeSigaud commented May 18, 2015 via email

@Robert-M-Muench
Copy link
Author

Hi Philippe, you created such a nice tool with PEG and don't use D anymore? Hmm... what happend? Your coding years shouldn't have passed... we need everyone that creates cool D stuff.

I haven't looked into the PEG code (yet) but would expect that it's not very easy. Do you have any notes, design information etc. that could help to get into it?

@PhilippeSigaud
Copy link
Collaborator

Hi Philippe, you created such a nice tool with PEG and don't use D
anymore? Hmm... what happend? Your coding years shouldn't have passed...

Oh, just Real Life (tm). Job changes, interesting work opportunities, more
responsibility, more children, etc. Coding is (was) a hobby for me, not my
day job.

I haven't looked into the PEG code (yet) but would expect that it's not
very easy. Do you have any notes, design information etc. that could help
to get into it?

Halas no. Just many wiki pages on the github site and the git history, but
the latter is not very informative.

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