Skip to content

Nested patterns and scalars #70

@forflo

Description

@forflo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions