Пример #1
0
def simplify_depth(node):
    if len(node.children) == 1 and \
       any([isinstance(node, ntype) for ntype in [exp, logic, order, add, mul, 
                                                  unary, atom, stmt.stmt, 
                                                  stmt.stmts, block.decls]]):
        return [node.children[0]]
    elif any([parser.istoken(node, t) for t in ["[", "]", "(", ")", ";", "|",
                                                ":", ":="]]):
        return []
    else:
        return [node]
Пример #2
0
def simplify_depth(node):
    if len(node.children) == 1 and \
       any([isinstance(node, ntype) for ntype in [exp, logic, order, add, mul,
                                                  unary, atom, stmt.stmt,
                                                  stmt.stmts, block.decls]]):
        return [node.children[0]]
    elif any([
            parser.istoken(node, t)
            for t in ["[", "]", "(", ")", ";", "|", ":", ":="]
    ]):
        return []
    else:
        return [node]
Пример #3
0
 def check(self, ctx):
     token = self.children[0]
     ttype = type(token)
     if ctx.pos == len(ctx.nodes):
         return ttype == lex.caret
     elif ttype == lex.left_paren:
         return self.children[1].match(
             context([ctx.nodes[ctx.pos]], 0, ctx.out))
     else:
         node = ctx.nodes[ctx.pos]
         if (ttype == lex.dot or \
             (ttype == lex.stringliteral and \
              parser.istoken(node, token.value)) or \
             (ttype == lex.identifier and \
              node.__class__.__name__ == token.body)):
             ctx.pos += 1
             return True
     return False
Пример #4
0
 def check(self, ctx):
     token = self.children[0]
     ttype = type(token)
     if ctx.pos == len(ctx.nodes):
         return ttype == lex.caret
     elif ttype == lex.left_paren:
         return self.children[1].match(context([ctx.nodes[ctx.pos]], 
                                               0, ctx.out))
     else:
         node = ctx.nodes[ctx.pos]
         if (ttype == lex.dot or \
             (ttype == lex.stringliteral and \
              parser.istoken(node, token.value)) or \
             (ttype == lex.identifier and \
              node.__class__.__name__ == token.body)):
             ctx.pos += 1
             return True
     return False