Exemple #1
0
    def match(self, tree):
        m = astmatch.match(self.get_pattern(), tree)
        if m:
            result = {}
            for col in m.column:
                field_name = col.column_name[0].node.field
                language = col.language[0].node.value
                weight = col.weight[0].node.value

                result[field_name] = (language, weight)

            return result
        else:
            return None
Exemple #2
0
    def match(self, tree):
        m = astmatch.match(self.get_pattern(), tree)
        if m:
            if m.value[0].node.typmods:
                typmods = []

                for tm in m.value[0].node.typmods:
                    typmods.append(tm.value)
            else:
                typmods = None
            typname = m.value[0].node.name
            return (typname, typmods)
        else:
            return None
Exemple #3
0
    def test_common_ast_match(self):
        assert match.match(self.pat1, self.tree1)
        assert not match.match(self.pat2, self.tree1)

        result = match.match(self.pat3, self.tree1)
        assert result.important_constant[0].node.value == 1
        assert result.important_constant2[0].node.value == 'value'

        result = match.match(self.pat4, self.tree2)
        assert sorted([c.node.value for c in result.recursive]) == [2, 3, 4, 5]

        # tree3 won't match because pat4 wants '+' op everywhere
        assert not match.match(self.pat4, self.tree3)

        # but the single constant matches just fine
        result = match.match(self.pat4, self.tree4)
        assert result and result.recursive[0].node.value == 'one and only'
Exemple #4
0
 def match(self, tree: irast.Base) -> Optional[List[irast.Base]]:
     m = astmatch.match(self.get_pattern(), tree)
     if m:
         return [mg.node for mg in m.expr]
     else:
         return None
Exemple #5
0
 def match(self, tree):
     m = astmatch.match(self.get_pattern(), tree)
     if m:
         return [mg.node for mg in m.expr]
     else:
         return None
Exemple #6
0
 def match(self, tree):
     m = astmatch.match(self.get_pattern(), tree)
     if m:
         return m.value[0].node.val
     else:
         return None