Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit 9c919e2

Browse files
committed
C++ is probably the worst language ever invented
1 parent f1d91e9 commit 9c919e2

File tree

6 files changed

+433
-326
lines changed

6 files changed

+433
-326
lines changed

4coder_fleury_colors.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ F4_GetColor(Application_Links *app, ColorCtx ctx)
174174
color = F4_ARGBFromID(table, fleury_color_index_constant);
175175
}break;
176176

177+
case F4_Index_NoteKind_Decl:
178+
{
179+
FillFromFlag(F4_SyntaxFlag_Constants);
180+
color = F4_ARGBFromID(table, fleury_color_index_decl);
181+
}break;
182+
177183
default: color = 0xffff00ff; break;
178184
}
179185

4coder_fleury_colors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CUSTOM_ID(colors, fleury_color_index_function);
1717
CUSTOM_ID(colors, fleury_color_index_macro);
1818
CUSTOM_ID(colors, fleury_color_index_constant);
1919
CUSTOM_ID(colors, fleury_color_index_comment_tag);
20+
CUSTOM_ID(colors, fleury_color_index_decl);
2021
CUSTOM_ID(colors, fleury_color_cursor_macro);
2122
CUSTOM_ID(colors, fleury_color_cursor_power_mode);
2223
CUSTOM_ID(colors, fleury_color_cursor_inactive);

4coder_fleury_index.cpp

Lines changed: 126 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,10 @@ F4_Index_PeekTokenSubKind(F4_Index_ParseCtx *ctx, int sub_kind, Token **token_ou
517517
return result;
518518
}
519519

520-
internal void
520+
internal b32
521521
F4_Index_SeekToken(F4_Index_ParseCtx *ctx, String_Const_u8 string)
522522
{
523+
b32 found = 0;
523524
Token_Iterator_Array it_restore = ctx->it;
524525
for(;;)
525526
{
@@ -529,6 +530,7 @@ F4_Index_SeekToken(F4_Index_ParseCtx *ctx, String_Const_u8 string)
529530
String_Const_u8 token_string = F4_Index_StringFromToken(ctx, token);
530531
if(string_match(token_string, string))
531532
{
533+
found = 1;
532534
break;
533535
}
534536
}
@@ -541,7 +543,11 @@ F4_Index_SeekToken(F4_Index_ParseCtx *ctx, String_Const_u8 string)
541543
break;
542544
}
543545
}
544-
ctx->it = it_restore;
546+
if(found == 0)
547+
{
548+
ctx->it = it_restore;
549+
}
550+
return found;
545551
}
546552

547553
internal void
@@ -571,7 +577,8 @@ F4_Index_SkipSoftTokens(F4_Index_ParseCtx *ctx, b32 preproc)
571577
Token *token = token_it_read(&ctx->it);
572578
if(preproc)
573579
{
574-
if(!(token->flags & TokenBaseFlag_PreprocessorBody))
580+
if(!(token->flags & TokenBaseFlag_PreprocessorBody) ||
581+
token->kind == TokenBaseKind_Preprocessor)
575582
{
576583
break;
577584
}
@@ -592,6 +599,122 @@ F4_Index_SkipSoftTokens(F4_Index_ParseCtx *ctx, b32 preproc)
592599
}
593600
}
594601

602+
internal void
603+
F4_Index_SkipOpTokens(F4_Index_ParseCtx *ctx)
604+
{
605+
int paren_nest = 0;
606+
for(;!ctx->done;)
607+
{
608+
Token *token = token_it_read(&ctx->it);
609+
if(token->kind == TokenBaseKind_ParentheticalOpen)
610+
{
611+
paren_nest += 1;
612+
}
613+
else if(token->kind == TokenBaseKind_ParentheticalClose)
614+
{
615+
paren_nest -= 1;
616+
if(paren_nest < 0)
617+
{
618+
paren_nest = 0;
619+
}
620+
}
621+
else if(token->kind != TokenBaseKind_Operator && paren_nest == 0)
622+
{
623+
break;
624+
}
625+
F4_Index_ParseCtx_Inc(ctx, F4_Index_TokenSkipFlag_SkipWhitespace);
626+
}
627+
}
628+
629+
function b32
630+
F4_Index_ParsePattern(F4_Index_ParseCtx *ctx, char *fmt, ...)
631+
{
632+
b32 parsed = 1;
633+
634+
F4_Index_ParseCtx ctx_restore = *ctx;
635+
F4_Index_TokenSkipFlags flags = F4_Index_TokenSkipFlag_SkipWhitespace;
636+
637+
va_list args;
638+
va_start(args, fmt);
639+
for(int i = 0; fmt[i];)
640+
{
641+
if(fmt[i] == '%')
642+
{
643+
switch(fmt[i+1])
644+
{
645+
case 't':
646+
{
647+
char *cstring = va_arg(args, char *);
648+
String8 string = SCu8((u8 *)cstring, cstring_length(cstring));
649+
parsed = parsed && F4_Index_RequireToken(ctx, string, flags);
650+
}break;
651+
652+
case 'k':
653+
{
654+
Token_Base_Kind kind = va_arg(args, Token_Base_Kind);
655+
Token **output_token = va_arg(args, Token **);
656+
parsed = parsed && F4_Index_RequireTokenKind(ctx, kind, output_token, flags);
657+
}break;
658+
659+
case 'b':
660+
{
661+
i16 kind = va_arg(args, i16);
662+
Token **output_token = va_arg(args, Token **);
663+
parsed = parsed && F4_Index_RequireTokenSubKind(ctx, kind, output_token, flags);
664+
}break;
665+
666+
case 'n':
667+
{
668+
F4_Index_NoteKind kind = va_arg(args, F4_Index_NoteKind);
669+
F4_Index_Note **output_note = va_arg(args, F4_Index_Note **);
670+
Token *token = 0;
671+
parsed = parsed && F4_Index_RequireTokenKind(ctx, TokenBaseKind_Identifier, &token, flags);
672+
parsed = parsed && !!token;
673+
if (parsed)
674+
{
675+
String8 token_string = F4_Index_StringFromToken(ctx, token);
676+
F4_Index_Note *note = F4_Index_LookupNote(token_string, 0);
677+
if (note && note->kind == kind)
678+
{
679+
*output_note = note;
680+
parsed = 1;
681+
}
682+
else
683+
{
684+
parsed = 0;
685+
}
686+
}
687+
}break;
688+
689+
case 's':
690+
{
691+
F4_Index_SkipSoftTokens(ctx, 0);
692+
}break;
693+
694+
case 'o':
695+
{
696+
F4_Index_SkipOpTokens(ctx);
697+
}break;
698+
699+
default: break;
700+
}
701+
i += 1;
702+
}
703+
else
704+
{
705+
i += 1;
706+
}
707+
}
708+
709+
va_end(args);
710+
711+
if(parsed == 0)
712+
{
713+
*ctx = ctx_restore;
714+
}
715+
return parsed;
716+
}
717+
595718
internal void
596719
F4_Index_Tick(Application_Links *app)
597720
{

4coder_fleury_index.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum F4_Index_NoteKind
1414
F4_Index_NoteKind_Macro,
1515
F4_Index_NoteKind_CommentTag,
1616
F4_Index_NoteKind_CommentToDo,
17-
F4_Index_NoteKind_MAX,
17+
F4_Index_NoteKind_COUNT
1818
};
1919

2020
typedef u32 F4_Index_NoteFlags;
@@ -109,9 +109,20 @@ internal b32 F4_Index_RequireTokenSubKind(F4_Index_ParseCtx *ctx, int sub_kind,
109109
internal b32 F4_Index_PeekToken(F4_Index_ParseCtx *ctx, String_Const_u8 string);
110110
internal b32 F4_Index_PeekTokenKind(F4_Index_ParseCtx *ctx, Token_Base_Kind kind, Token **token_out);
111111
internal b32 F4_Index_PeekTokenSubKind(F4_Index_ParseCtx *ctx, int sub_kind, Token **token_out);
112-
internal void F4_Index_SeekToken(F4_Index_ParseCtx *ctx, String_Const_u8 string);
112+
internal b32 F4_Index_SeekToken(F4_Index_ParseCtx *ctx, String_Const_u8 string);
113113
internal void F4_Index_ParseComment(F4_Index_ParseCtx *ctx, Token *token);
114+
internal void F4_Index_SkipSoftTokens(F4_Index_ParseCtx *ctx, b32 preproc);
115+
internal void F4_Index_SkipOpTokens(F4_Index_ParseCtx *ctx);
114116
internal String_Const_u8 F4_Index_StringFromToken(F4_Index_ParseCtx* ctx, Token* token);
115117
internal void F4_Index_Tick(Application_Links *app);
116118

119+
// Format:
120+
// %t -> token, requires char * specifying token string
121+
// %k -> token kind, requires Token_Base_Kind and Token ** for output token
122+
// %b -> token subkind, requires token subkind and Token ** for output token
123+
// %n -> note, requires F4_Index_NoteKind and F4_Index_Note ** for output note
124+
// %s -> soft group, requires no arguments
125+
// %o -> operator group,requires no arguments
126+
function b32 F4_Index_ParsePattern(F4_Index_ParseCtx *ctx, char *fmt, ...);
127+
117128
#endif // FCODER_FLEURY_INDEX_H

0 commit comments

Comments
 (0)