Beispiel #1
0
    def gather(self, node):
        """ return list of AnonObjs containing the info we need """
        tv = Treeverser(node)
        matches = tv.gatherMatches(self.TRYEX_PATTERN)

        infos = []
        for match in matches:
            info = AnonObj()
            info.node = match.node
            info.try_word = match.try_word
            info.try_colon = match.try_colon
            info.try_suite = match.try_suite[0]
            if "exc_clause" in match:
                info.exc_clause = match.exc_clause
                for node in gatherSubNodesD(info.exc_clause):
                    if getNodeKind(node) == "NAME" and node.value == "as":
                        info.exc_as = node
                        as_idx = getNodeIndex(node)
                        info.exc_as_name = node.parent.children[as_idx + 1]

            info.exc_word = match.exc_word
            if "exc_what" in match:
                info.exc_what = match.exc_what[0]
            info.exc_colon = match.exc_colon
            info.exc_suite = match.exc_suite[0]

            if "fin_word" in match:
                info.fin_word = match.fin_word
                info.fin_colon = match.fin_colon
                info.fin_suite = match.fin_suite[0]

            infos.append(info)
        return infos
 def gather( self, node ):
     tv = Treeverser( node )
     matches = tv.gatherMatches( self.SELF_PATTERN )
     infos = []
     for match in matches:
         match.right = match.right[ 0 ]
     return matches
Beispiel #3
0
 def gather(self, node):
     tv = Treeverser(node)
     matches = tv.gatherMatches(self.PATTERN)
     for match in matches:
         match.comp_op = match.comp_op[0] if isinstance(
             match.comp_op, list) else match.comp_op
     return matches
 def gather(self, node):
     tv = Treeverser(node)
     matches = tv.gatherMatches(self.FUNC_PATTERN)
     for match in matches:
         if match.get("args", None):
             match.args = match.args[0]
     return matches
Beispiel #5
0
 def gather(self, node):
     tv = Treeverser(node)
     matches = tv.gatherMatches(self.ASSN_PATTERN)
     for match in matches:
         match.left = match.left[0]
         match.right = match.right[0]
     return matches
Beispiel #6
0
 def gather(self, node):
     tv = Treeverser(node)
     matches = tv.gatherMatches(self.PATTERN)
     for match in matches:
         match.test = match.test[0]
         match.suite = match.suite[0]
     return matches
Beispiel #7
0
 def gather( self, node ):
     tv = Treeverser( node )
     matches = tv.gatherMatches( self.COMP_PATTERN )
     for match in matches:
         match.item_value = match.item_value[ 0 ]
         match.locals = match.locals[ 0 ]
         match.looper = match.looper[ 0 ]
         if "test" in match:
             match.test = match.test[ 0 ]
     return matches
Beispiel #8
0
 def gather(self, node):
     tv = Treeverser(node)
     matches = tv.gatherMatches(self.PATTERN)
     matches = [
         m for m in matches
         if findOutNode(m.node, self.isTestFuncNode, None)
     ]
     for match in matches:
         if 'comp_op' in match:
             match.comp_op = match.comp_op[0]
     return matches
Beispiel #9
0
 def gather(self, node):
     tv = Treeverser(node)
     matches = tv.gatherMatches(self.PATTERN)
     infos = []
     for match in matches:
         match.from_word = match.from_word
         match.module = match.module[0]
         match.import_word = match.import_word
         if match.lpar:
             match.lpar = match.lpar[0]
         match.imported = match.imported[0]
         if match.rpar:
             match.rpar = match.rpar[0]
     return matches
Beispiel #10
0
    def gather(self, node):
        """ return list of AnonObjs containing the info we need """
        tv = Treeverser(node)
        matches = tv.gatherMatches(self.PATTERN)
        infos = []
        for match in matches:
            info = AnonObj(node=match.node)

            info.args = []
            for match_arg in match.args:
                arg_info = AnonObj(node=match_arg)
                info.args.append(arg_info)

            infos.append(info)
        return infos
Beispiel #11
0
def fixSemicolons(nodes):
    STMT_PATTERN = """
        simple_stmt < stmt=any newl='\\n' >
    """

    tv = Treeverser(nodes)
    matches = tv.gatherMatches(STMT_PATTERN)
    infos = []
    for match in matches:
        if getNodeKind(match.stmt) != "STRING":  # stmt is not a comment
            par_node = match.newl.parent
            newl_idx = par_node.children.index(match.newl)
            if getNodeKind(par_node.children[newl_idx - 1]) != "SEMI":
                par_node.insert_child(newl_idx, makeLeaf("SEMI", ";", ''))

    return infos
Beispiel #12
0
    def gather(self, node):
        tv = Treeverser(node)
        matches = tv.gatherMatches(self.IF_PATTERN)
        infos = []
        for match in matches:

            info = AnonObj(if_clause=None, elif_clauses=[], else_clause=None)

            info.if_clause = self.gatherIfStatement(match)

            info.elif_clauses = self.gatherElifStatements(match)

            node = match.get("else", None)
            if node:
                info.else_clause = self.gatherElseStatement(match)

            infos.append(info)
        return infos
Beispiel #13
0
 def gather(self, node):
     tv = Treeverser(node)
     matches = tv.gatherMatches(self.PATTERN)
     return matches
Beispiel #14
0
 def gather(self, node):
     tv = Treeverser(node)
     matches = tv.gatherMatches(self.FORLOOP_PATTERN)
     for match in matches:
         match.for_suite = match.for_suite[0]
     return matches