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

One block for a set of two or more production rules? #55

Open
maxrdz opened this issue Mar 5, 2024 · 0 comments
Open

One block for a set of two or more production rules? #55

maxrdz opened this issue Mar 5, 2024 · 0 comments

Comments

@maxrdz
Copy link

maxrdz commented Mar 5, 2024

I have a set of rules under one production in my CFG that both have basically duplicated blocks of code, and could be handled in one. Is there a way to do this? The following example is what my code looks like:

numeric_with_modulus: DCNumericType {
    numeric_type_token[mut nt] Percent number[n] => {
        // do something 
    }
    numeric_with_explicit_cast[mut nt] Percent number[n] => {
        // do something very similar
    }
}

Would be nice to have something like this:

numeric_with_modulus: DCNumericType {
    numeric_type_token[mut nt] Percent number[n] |
    numeric_with_explicit_cast[mut nt] Percent number[n] => {
        // do the similar thing :p
    }
}

of course, both rules would have to have the same parameters. or, same 'function' signature if that's the right term :p Since each block is a bit like a function; with the non-terminals / terminals being the parameters.

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