Exemplo n.º 1
0
def handle_empty_compound(atok, t, l, b, dummy):
    n = neighbors(atok, t)
    left, right = expand_to_line_or_statement(atok, t, l, b)
    if token.DEDENT == left.type:
        left = next_token(atok, left)
    if t.string == "elif" and left.string != "elif":
        left = next_token(atok, left)
    if left is t and right.string == ":":
        rh = next_token(atok, right)
        while rh and (rh.line.isspace() or rh.start[0] == right.start[0]):
            rh = next_token(atok, rh)
        temporary = left.line
        ls = temporary[:len(temporary) - len(temporary.lstrip())]
        temporary = rh.line if rh else ""
        rs = temporary[:len(temporary) - len(temporary.lstrip())]
        if len(ls) >= len(rs):
            return True, right.endpos, " pass ", False
        else:
            return (False, )

    # these needs to be updated
    elif t.string == "if" and right is t:
        return True, right.endpos, " " + dummy + " else " + dummy, True
    else:
        return (False, )
def line_partial(code,offset):	
	atok = asttokens.ASTTokens(parse=False, source_text=code)
	origin = atok.get_token_from_offset(offset)
	left, right = expand_to_line_or_statement(atok,origin)
	m = ModificationHandler(code)
	m.modify_from(0,(0, left.startpos),"")
	if right.string == ":":
			m.modify_from(0,(right.endpos,len(code)+1),"pass")
	else:
			m.modify_from(0,(right.endpos,len(code)+1),"")
	m.update()
	return partially_parse(m.current_code,m)
def parse_line_from_offset(code, offset):
	print("\n\n hello world  here\n\n")
	atok =  asttokens.ASTTokens(parse=False, source_text= code )
	origin = atok.get_token_from_offset(offset)
	print("off their origin ")
	left, right = expand_to_line_or_statement(atok,origin)
	print("often expands the underlying ", left, right)
	area = code[left.startpos:right.endpos]

	#print("area is ",area)
	print(asttokens.ASTTokens(parse=False, source_text=area).tokens)
	return build_tree(area)