Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
def parse_single_correct_line(line):
	try:
		return build_tree(line)
	except Exception as e:
		return None