Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Code_Index_Nest*
- generic_parse_paren(Application_Links *app, Code_Index_File *index, Generic_Parse_State *state){
- Token *token = token_it_read(&state->it);
- Code_Index_Nest *result = push_array_zero(state->arena, Code_Index_Nest, 1);
- result->kind = CodeIndexNest_Paren;
- result->open = Ii64(token);
- result->close = Ii64(max_i64);
- result->file = index;
- i64 manifested_characters_on_line = 0;
- {
- u8 *ptr = state->prev_line_start;
- u8 *end_ptr = state->contents.str + token->pos;
- // NOTE(allen): Initial whitespace
- for (;ptr < end_ptr; ptr += 1){
- if (!character_is_whitespace(*ptr)){
- break;
- }
- }
- // NOTE(allen): Manifested characters
- manifested_characters_on_line = (i64)(end_ptr - ptr) + token->size;
- }
- state->paren_counter += 1;
- generic_parse_inc(state);
- for (;;){
- generic_parse_skip_soft_tokens(index, state);
- token = token_it_read(&state->it);
- if (token == 0 || state->finished){
- break;
- }
- if (state->in_preprocessor){
- if (!HasFlag(token->flags, TokenBaseFlag_PreprocessorBody) ||
- token->kind == TokenBaseKind_Preprocessor){
- break;
- }
- }
- else{
- if (token->kind == TokenBaseKind_Preprocessor){
- Code_Index_Nest *nest = generic_parse_preprocessor(app, index, state);
- nest->line_number = get_line_number_from_pos(app, index->buffer, token->pos);
- code_index_push_nest(&index->nest_list, nest);
- continue;
- }
- }
- if (token->kind == TokenBaseKind_ParentheticalClose){
- result->is_closed = true;
- result->close = Ii64(token);
- result->line_number = get_line_number_from_pos(app, index->buffer, token->pos);
- generic_parse_inc(state);
- break;
- }
- if (token->kind == TokenBaseKind_ScopeClose){
- break;
- }
- if (token->kind == TokenBaseKind_ScopeOpen){
- Code_Index_Nest *nest = generic_parse_scope(app, index, state);
- nest->parent = result;
- nest->line_number = get_line_number_from_pos(app, index->buffer, token->pos);
- code_index_push_nest(&result->nest_list, nest);
- continue;
- }
- if (token->kind == TokenBaseKind_ParentheticalOpen){
- Code_Index_Nest *nest = generic_parse_paren(app, index, state);
- nest->parent = result;
- nest->line_number = get_line_number_from_pos(app, index->buffer, token->pos);
- code_index_push_nest(&result->nest_list, nest);
- continue;
- }
- generic_parse_inc(state);
- }
- result->nest_array = code_index_nest_ptr_array_from_list(state->arena, &result->nest_list);
- state->paren_counter -= 1;
- return(result);
- }
- // NOTE(Skytrias): mainly changed
- function f32
- layout_index_x_shift(Application_Links *app, Layout_Reflex *reflex, Code_Index_Nest *nest, i64 pos, f32 space_advance, b32 *unresolved_dependence){
- f32 result = 0.f;
- if (nest != 0){
- switch (nest->kind){
- case CodeIndexNest_Scope:
- case CodeIndexNest_Preprocessor:
- case CodeIndexNest_Paren:
- {
- result = layout_index_x_shift(app, reflex, nest->parent, pos, space_advance, unresolved_dependence);
- // NOTE(Skytrias): check before and after to see if the next scope is on the same line, if yes skip indent
- bool inside = false;
- if (nest->parent != 0) {
- inside = nest->line_number == nest->parent->line_number;
- }
- if (inside && nest->next != 0) {
- inside = nest->line_number == nest->next->line_number;
- }
- if (!inside && (nest->open.min < pos && nest->open.max <= pos &&
- (!nest->is_closed || pos < nest->close.min))){
- result += 4.f*space_advance;
- }
- }break;
- case CodeIndexNest_Statement:
- {
- result = layout_index_x_shift(app, reflex, nest->parent, pos, space_advance, unresolved_dependence);
- if (nest->open.min < pos && nest->open.max <= pos &&
- (!nest->is_closed || pos < nest->close.min)){
- result += 4.f*space_advance;
- }
- }break;
- }
- }
- return(result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement