def partially_parse(code, m = None, atok = None,rethrow_exception = False):
	m = m if m is not None else ModificationHandler(code)
	#print(code)
	timestamp = m.get_timestamp()
	try:
		root,atok = build_tree(code) 
		r = RepairMissing(atok,m,timestamp)
		return root,atok,m,r
	except Exception as e_first: 
		atok =  atok  if atok  else asttokens.ASTTokens(parse=False, source_text= code)
		# print(m)
		m = filter_everything(atok,m, timestamp)
		m.update()
		#print("after filtering",m.history)
		atok = asttokens.ASTTokens(parse=False, source_text= m.current_code)
		r = RepairMissing(atok,m,m.get_timestamp())
		r.work()
		m.update()
		#print("she's after repair",m.history)
		try:
			root,atok = build_tree(m.current_code) 
			return root,atok,m,r
		except Exception as e:
			print(" go to the field\n",m.current_code)
			print(" error was\n",str(e),"\n",e)
			if rethrow_exception :
				raise e
			return None,None,None,None
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)
def build_without_higher(code,mode = True):
	atok =  asttokens.ASTTokens(parse=False, source_text=code)
	m = ModificationHandler(code)
	m = filter_everything(m,atok)
	m.update()
	root,atok = build_tree(m.current_code) 
	return root,atok,m
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 build_tree(code: str):
    atok = asttokens.ASTTokens(parse=True, source_text=code)
    root = transformers.ParentChildNodeTransformer().visit(atok.tree)
    return root, atok
Пример #6
0
def extract_all_class_names(code):
    atok = asttokens.ASTTokens(parse=False, source_text=code)
    return [(atok.next_token(x).string, x.type) for x in atok.tokens
            if x.type == 1 and x.string == "class"]