2024-10-25 02:04:11 -07:00
|
|
|
// This file was generated automatially by gencpp's unreal.cpp (See: https://github.com/Ed94/gencpp)
|
2024-10-21 19:39:40 -07:00
|
|
|
|
|
|
|
#ifdef __clang__
|
2024-10-27 18:44:34 -07:00
|
|
|
# pragma clang diagnostic push
|
|
|
|
# pragma clang diagnostic ignored "-Wunused-const-variable"
|
|
|
|
# pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
|
|
|
# pragma clang diagnostic ignored "-Wswitch"
|
|
|
|
# pragma clang diagnostic ignored "-Wunused-variable"
|
|
|
|
# pragma clang diagnostic ignored "-Wunknown-pragmas"
|
|
|
|
# pragma clang diagnostic ignored "-Wvarargs"
|
|
|
|
# pragma clang diagnostic ignored "-Wunused-function"
|
2024-12-15 11:14:02 -08:00
|
|
|
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
|
|
|
# pragma clang diagnostic ignored "-W#pragma-messages"
|
|
|
|
# pragma clang diagnostic ignored "-Wstatic-in-inline"
|
2024-10-21 19:39:40 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
2024-10-27 18:44:34 -07:00
|
|
|
# pragma GCC diagnostic push
|
|
|
|
# pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
|
|
|
# pragma GCC diagnostic ignored "-Wcomment"
|
|
|
|
# pragma GCC diagnostic ignored "-Wswitch"
|
|
|
|
# pragma GCC diagnostic ignored "-Wunused-variable"
|
2024-10-21 19:39:40 -07:00
|
|
|
#endif
|
|
|
|
|
2024-10-25 02:04:11 -07:00
|
|
|
#include "gen.scanner.hpp"
|
|
|
|
|
2024-10-21 19:39:40 -07:00
|
|
|
GEN_NS_BEGIN
|
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
#pragma region Scanner
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
Code scan_file( char const* path )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 15:22:59 -08:00
|
|
|
FileInfo file;
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
FileError error = file_open_mode( & file, EFileMode_READ, path );
|
|
|
|
if ( error != EFileError_NONE )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 15:22:59 -08:00
|
|
|
GEN_FATAL( "scan_file: Could not open: %s", path );
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
ssize fsize = file_size( & file );
|
|
|
|
if ( fsize <= 0 )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 15:22:59 -08:00
|
|
|
GEN_FATAL("scan_file: %s is empty", path );
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
StrBuilder str = strbuilder_make_reserve( get_context()->Allocator_Temp, fsize );
|
|
|
|
file_read( & file, str, fsize );
|
|
|
|
strbuilder_get_header(str)->Length = fsize;
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
|
|
|
|
// Its designed so that the directive should be the first thing in the file.
|
|
|
|
// Anything that comes before it will also be omitted.
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 15:22:59 -08:00
|
|
|
#define current (*scanner)
|
|
|
|
#define matched 0
|
|
|
|
#define move_fwd() do { ++ scanner; -- left; } while (0)
|
|
|
|
const Str directive_start = txt( "ifdef" );
|
|
|
|
const Str directive_end = txt( "endif" );
|
|
|
|
const Str def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
bool found_directive = false;
|
|
|
|
char const* scanner = (char const*)str;
|
|
|
|
s32 left = fsize;
|
|
|
|
while ( left )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 15:22:59 -08:00
|
|
|
// Processing directive.
|
|
|
|
if ( current == '#' )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 15:22:59 -08:00
|
|
|
move_fwd();
|
|
|
|
while ( left && char_is_space( current ) )
|
|
|
|
move_fwd();
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
if ( ! found_directive )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 15:22:59 -08:00
|
|
|
if ( left && c_str_compare_len( scanner, directive_start.Ptr, directive_start.Len ) == matched )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 15:22:59 -08:00
|
|
|
scanner += directive_start.Len;
|
|
|
|
left -= directive_start.Len;
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
while ( left && char_is_space( current ) )
|
|
|
|
move_fwd();
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
if ( left && c_str_compare_len( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
|
|
|
|
{
|
|
|
|
scanner += def_intellisense.Len;
|
|
|
|
left -= def_intellisense.Len;
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
found_directive = true;
|
|
|
|
}
|
|
|
|
}
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
// Skip to end of line
|
|
|
|
while ( left && current != '\r' && current != '\n' )
|
|
|
|
move_fwd();
|
|
|
|
move_fwd();
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
if ( left && current == '\n' )
|
|
|
|
move_fwd();
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
continue;
|
2024-10-27 18:44:34 -07:00
|
|
|
}
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
if ( left && c_str_compare_len( scanner, directive_end.Ptr, directive_end.Len ) == matched )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 15:22:59 -08:00
|
|
|
scanner += directive_end.Len;
|
|
|
|
left -= directive_end.Len;
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
// Skip to end of line
|
|
|
|
while ( left && current != '\r' && current != '\n' )
|
|
|
|
move_fwd();
|
|
|
|
move_fwd();
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
if ( left && current == '\n' )
|
|
|
|
move_fwd();
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
// sptr skip_size = fsize - left;
|
|
|
|
if ( (scanner + 2) >= ( (char const*) str + fsize ) )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 15:22:59 -08:00
|
|
|
mem_move( str, scanner, left );
|
|
|
|
strbuilder_get_header(str)->Length = left;
|
2024-10-21 19:39:40 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
mem_move( str, scanner, left );
|
|
|
|
strbuilder_get_header(str)->Length = left;
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
break;
|
|
|
|
}
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
move_fwd();
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
2024-12-15 15:22:59 -08:00
|
|
|
#undef move_fwd
|
|
|
|
#undef matched
|
|
|
|
#undef current
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
file_close( & file );
|
|
|
|
return untyped_str( strbuilder_to_str(str) );
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
CodeBody parse_file( const char* path ) {
|
|
|
|
FileContents file = file_read_contents( get_context()->Allocator_Temp, true, path );
|
|
|
|
Str content = { (char const*)file.data, file.size };
|
|
|
|
CodeBody code = parse_global_body( content );
|
|
|
|
log_fmt("\nParsed: %s\n", path);
|
|
|
|
return code;
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) {
|
|
|
|
FileContents content = file_read_contents( allocator, file_zero_terminate, path );
|
|
|
|
Arena csv_arena = arena_init_from_memory(content.data, content.size);
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
CSV_Column result;
|
|
|
|
csv_parse( & result.ADT, rcast(char*, content.data), allocator, false );
|
|
|
|
result.Content = result.ADT.nodes[0].nodes;
|
|
|
|
return result;
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path) {
|
|
|
|
FileContents content = file_read_contents( allocator, file_zero_terminate, path );
|
|
|
|
Arena csv_arena = arena_init_from_memory(content.data, content.size);
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
CSV_Columns2 result;
|
|
|
|
csv_parse( & result.ADT, rcast(char*, content.data), allocator, false );
|
|
|
|
result.Col_1 = result.ADT.nodes[0].nodes;
|
|
|
|
result.Col_2 = result.ADT.nodes[1].nodes;
|
|
|
|
return result;
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
#pragma endregion Scanner
|
2024-10-21 19:39:40 -07:00
|
|
|
|
|
|
|
GEN_NS_END
|
|
|
|
|
|
|
|
#ifdef __clang__
|
2024-10-27 18:44:34 -07:00
|
|
|
# pragma clang diagnostic pop
|
2024-10-21 19:39:40 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
2024-10-27 18:44:34 -07:00
|
|
|
# pragma GCC diagnostic pop
|
2024-10-21 19:39:40 -07:00
|
|
|
#endif
|