def isolate_query_ctes(full_text, text_before_cursor):
 if (not full_text):
  return (full_text, text_before_cursor, tuple())
 (ctes, remainder) = extract_ctes(full_text)
 if (not ctes):
  return (full_text, text_before_cursor, ())
 current_position = len(text_before_cursor)
 meta = []
 for cte in ctes:
  if (cte.start < current_position < cte.stop):
   text_before_cursor = full_text[cte.start:current_position]
   full_text = full_text[cte.start:cte.stop]
   return (full_text, text_before_cursor, meta)
  cols = (ColumnMetadata(name, None, ()) for name in cte.columns)
  meta.append(TableMetadata(cte.name, cols))
 full_text = full_text[ctes[(-1)].stop:]
 text_before_cursor = text_before_cursor[ctes[(-1)].stop:current_position]
 return (full_text, text_before_cursor, tuple(meta))

def isolate_query_ctes ( full_text , text_before_cursor ) : if ( not full_text ) : return ( full_text , text_before_cursor , tuple ( ) ) ( ctes , remainder ) = extract_ctes ( full_text ) if ( not ctes ) : return ( full_text , text_before_cursor , ( ) ) current_position = len ( text_before_cursor ) meta = [ ] for cte in ctes : if ( cte . start < current_position < cte . stop ) : text_before_cursor = full_text [ cte . start : current_position ] full_text = full_text [ cte . start : cte . stop ] return ( full_text , text_before_cursor , meta ) cols = ( ColumnMetadata ( name , None , ( ) ) for name in cte . columns ) meta . append ( TableMetadata ( cte . name , cols ) ) full_text = full_text [ ctes [ ( - 1 ) ] . stop : ] text_before_cursor = text_before_cursor [ ctes [ ( - 1 ) ] . stop : current_position ] return ( full_text , text_before_cursor , tuple ( meta ) )
simplify a query by converting ctes into table metadata objects .