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

Nested patterns and scalars #70

Open
forflo opened this issue Aug 23, 2016 · 1 comment
Open

Nested patterns and scalars #70

forflo opened this issue Aug 23, 2016 · 1 comment
Labels

Comments

@forflo
Copy link

forflo commented Aug 23, 2016

Is it possible to mix instances of var and nested patterns in the binding part of a constructor pattern? For example, is the following code allowed:

Case(C<ExpLogical>(
         C<ExpRelation>(
             C<ExpCharacter>(charVal),
             C<ExpName>(name),
             relOp),
         C<ExpAttribute>(attrName),
         logOp)){

where attrName, name, charVal, logOp and relOp are instances of the var template and Exp* have the layout:

namespace mch {
    template <> struct bindings<ExpUNot> {
        Members(ExpUNot::operand1_);
    };

    template <> struct bindings<ExpCharacter> {
        Members(ExpCharacter::value_);
    };

    template <> struct bindings<ExpAttribute> {
        Members(ExpAttribute::name_);
    };

    template <> struct bindings<ExpLogical> {
        Members(ExpLogical::operand1_,
                ExpLogical::operand2_,
                ExpLogical::fun_);
    };

    template <> struct bindings<ExpFunc> {
        Members(ExpFunc::name_,
                ExpFunc::argv_);
    };

    template <> struct bindings<ExpName> {
        //TODO: add prefix
        Members(//ExpName::prefix_, // unique_ptr<ExpName>
                ExpName::name_,
                ExpName::indices_);
    };

    template <> struct bindings<ExpRelation> {
        Members(ExpRelation::operand1_,
                ExpRelation::operand2_,
                ExpRelation::fun_);
    };
};

Here some Context. I need to search an Expression AST for a very specific pattern. Without the ExpRelation::fun_ and ExpLogical::fun_ bindings it worked quite well, but when I first began to experiment with the first code snippet instead of the simpler

Case(C<ExpLogical>(
         C<ExpRelation>(
             C<ExpCharacter>(charVal),
             C<ExpName>(name)),
         C<ExpAttribute>(attrName))){

no pattern seemed to match anymore.

@solodon4
Copy link
Owner

Hi Florian,
Yes, all patterns are essentially the same to the library - it doesn't know a particular pattern is a var (variable pattern) or C (constructor pattern). It simply assumes they would model corresponding concept, which they do and forwards the computations accordingly. Can you perhaps extract a small repro of what doesn't work and what you expect it to do?

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