Advertisement
Skytrias

code index changes

Jan 11th, 2020
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.49 KB | None | 0 0
  1. function Code_Index_Nest*
  2. generic_parse_paren(Application_Links *app, Code_Index_File *index, Generic_Parse_State *state){
  3.     Token *token = token_it_read(&state->it);
  4.     Code_Index_Nest *result = push_array_zero(state->arena, Code_Index_Nest, 1);
  5.     result->kind = CodeIndexNest_Paren;
  6.     result->open = Ii64(token);
  7.     result->close = Ii64(max_i64);
  8.     result->file = index;
  9.    
  10.     i64 manifested_characters_on_line = 0;
  11.     {
  12.         u8 *ptr = state->prev_line_start;
  13.         u8 *end_ptr = state->contents.str + token->pos;
  14.         // NOTE(allen): Initial whitespace
  15.        
  16.         for (;ptr < end_ptr; ptr += 1){
  17.             if (!character_is_whitespace(*ptr)){
  18.                 break;
  19.             }
  20.         }
  21.        
  22.         // NOTE(allen): Manifested characters
  23.         manifested_characters_on_line = (i64)(end_ptr - ptr) + token->size;
  24.     }
  25.    
  26.     state->paren_counter += 1;
  27.    
  28.     generic_parse_inc(state);
  29.     for (;;){
  30.         generic_parse_skip_soft_tokens(index, state);
  31.         token = token_it_read(&state->it);
  32.         if (token == 0 || state->finished){
  33.             break;
  34.         }
  35.        
  36.         if (state->in_preprocessor){
  37.             if (!HasFlag(token->flags, TokenBaseFlag_PreprocessorBody) ||
  38.                 token->kind == TokenBaseKind_Preprocessor){
  39.                 break;
  40.             }
  41.         }
  42.         else{
  43.             if (token->kind == TokenBaseKind_Preprocessor){
  44.                 Code_Index_Nest *nest = generic_parse_preprocessor(app, index, state);
  45.                 nest->line_number = get_line_number_from_pos(app, index->buffer, token->pos);
  46.                 code_index_push_nest(&index->nest_list, nest);
  47.                 continue;
  48.             }
  49.         }
  50.        
  51.         if (token->kind == TokenBaseKind_ParentheticalClose){
  52.             result->is_closed = true;
  53.             result->close = Ii64(token);
  54.             result->line_number = get_line_number_from_pos(app, index->buffer, token->pos);
  55.             generic_parse_inc(state);
  56.             break;
  57.         }
  58.        
  59.         if (token->kind == TokenBaseKind_ScopeClose){
  60.             break;
  61.         }
  62.        
  63.         if (token->kind == TokenBaseKind_ScopeOpen){
  64.             Code_Index_Nest *nest = generic_parse_scope(app, index, state);
  65.             nest->parent = result;
  66.             nest->line_number = get_line_number_from_pos(app, index->buffer, token->pos);
  67.             code_index_push_nest(&result->nest_list, nest);
  68.             continue;
  69.         }
  70.        
  71.         if (token->kind == TokenBaseKind_ParentheticalOpen){
  72.             Code_Index_Nest *nest = generic_parse_paren(app, index, state);
  73.             nest->parent = result;
  74.             nest->line_number = get_line_number_from_pos(app, index->buffer, token->pos);
  75.             code_index_push_nest(&result->nest_list, nest);
  76.             continue;
  77.         }
  78.        
  79.         generic_parse_inc(state);
  80.     }
  81.    
  82.     result->nest_array = code_index_nest_ptr_array_from_list(state->arena, &result->nest_list);
  83.    
  84.     state->paren_counter -= 1;
  85.    
  86.     return(result);
  87. }
  88.  
  89.  
  90.  
  91. // NOTE(Skytrias): mainly changed
  92. function f32
  93. layout_index_x_shift(Application_Links *app, Layout_Reflex *reflex, Code_Index_Nest *nest, i64 pos, f32 space_advance, b32 *unresolved_dependence){
  94.     f32 result = 0.f;
  95.    
  96.     if (nest != 0){
  97.         switch (nest->kind){
  98.             case CodeIndexNest_Scope:
  99.             case CodeIndexNest_Preprocessor:
  100.             case CodeIndexNest_Paren:
  101.             {
  102.                 result = layout_index_x_shift(app, reflex, nest->parent, pos, space_advance, unresolved_dependence);
  103.                
  104.                 // NOTE(Skytrias): check before and after to see if the next scope is on the same line, if yes skip indent
  105.                 bool inside = false;
  106.                
  107.                 if (nest->parent != 0) {
  108.                     inside = nest->line_number == nest->parent->line_number;
  109.                 }
  110.                
  111.                 if (inside && nest->next != 0) {
  112.                     inside = nest->line_number == nest->next->line_number;
  113.                 }
  114.                
  115.                 if (!inside && (nest->open.min < pos && nest->open.max <= pos &&
  116.                                 (!nest->is_closed || pos < nest->close.min))){
  117.                     result += 4.f*space_advance;
  118.                 }
  119.             }break;
  120.            
  121.             case CodeIndexNest_Statement:
  122.             {
  123.                 result = layout_index_x_shift(app, reflex, nest->parent, pos, space_advance, unresolved_dependence);
  124.                 if (nest->open.min < pos && nest->open.max <= pos &&
  125.                     (!nest->is_closed || pos < nest->close.min)){
  126.                     result += 4.f*space_advance;
  127.                 }
  128.             }break;
  129.         }
  130.     }
  131.     return(result);
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement