This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
4coder_fleury_table_comments.cpp
124 lines (105 loc) · 4.98 KB
/
4coder_fleury_table_comments.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
enum F4_TableMarkerKind
{
F4_TableMarkerKind_Null,
F4_TableMarkerKind_IdentifierSlot,
F4_TableMarkerKind_SymbolSlot,
};
struct F4_TableMarker
{
F4_TableMarkerKind kind;
u8 specific_symbol;
int wanted_size;
};
static void
F4_ApplyTableMarkers(Application_Links *app, Buffer_ID buffer, View_ID view, Text_Layout_ID text_layout_id,
F4_TableMarker *markers, int marker_count)
{
Scratch_Block scratch(app);
Token_Array token_array = get_token_array_from_buffer(app, buffer);
Range_i64 visible_range = text_layout_get_visible_range(app, text_layout_id);
i64 first_index = token_index_from_pos(&token_array, visible_range.first);
Token_Iterator_Array it = token_iterator_index(0, &token_array, first_index);
Token *token = 0;
for(;;)
{
token = token_it_read(&it);
if(token->pos >= visible_range.one_past_last || !token || !token_it_inc_non_whitespace(&it))
{
break;
}
}
static void
F4_DoTableComments(Application_Links *app, Buffer_ID buffer, View_ID view,
Text_Layout_ID text_layout_id)
{
ProfileScope(app, "[Fleury] Table Comments");
String_Const_u8 table_comment_signifier = string_u8_litexpr("//t");
Token_Array token_array = get_token_array_from_buffer(app, buffer);
Range_i64 visible_range = text_layout_get_visible_range(app, text_layout_id);
Scratch_Block scratch(app);
if(token_array.tokens != 0)
{
i64 first_index = token_index_from_pos(&token_array, visible_range.first);
Token_Iterator_Array it = token_iterator_index(0, &token_array, first_index);
Token *comment_token = 0;
for(;;)
{
comment_token = token_it_read(&it);
if(comment_token->pos >= visible_range.one_past_last || !comment_token || !token_it_inc_non_whitespace(&it))
{
break;
}
if(comment_token->kind == TokenBaseKind_Comment)
{
u8 token_buffer[256] = {0};
if(buffer_read_range(app, buffer, Ii64(comment_token->pos, comment_token->pos + comment_token->size), token_buffer))
{
String_Const_u8 str = { token_buffer, (u64)comment_token->size };
//~ NOTE(rjf): Determine table markers.
int marker_count = 0;
F4_TableMarker markers[256] = {};
for(int i = 0; i < str.size && marker_count < ArrayCount(markers); i += 1)
{
F4_TableMarker *marker = markers + marker_count;
marker->kind = F4_TableMarkerKind_Null;
switch(str.str[i])
{
case '$':
{
marker_count += 1;
marker->kind = F4_TableMarkerKind_IdentifierSlot;
}break;
case '`':
{
marker_count += 1;
marker->kind = F4_TableMarkerKind_SymbolSlot;
marker->specific_symbol = 0;
}break;
case '(': case ')': case '[': case ']': case '{': case '}':
case '+': case '-': case '*': case '/': case '%': case '=':
case '#': case '@': case '!': case '~': case '^': case '&':
case '|': case '_': case '<': case '>': case '.': case ',':
{
marker_count += 1;
marker->kind = F4_TableMarkerKind_SymbolSlot;
marker->specific_symbol = str.str[i];
}break;
default: break;
}
if(marker->kind)
{
marker->wanted_size = 0;
for(int j = i+1; j < str.size; j += 1)
{
if(str.str[j] <= 32)
{
marker->wanted_size += 1;
}
}
}
}
}
}
}
}
}