2023-08-28 21:03:08 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
|
|
|
# pragma once
|
2024-12-10 13:13:14 -08:00
|
|
|
# include "helpers/push_ignores.inline.hpp"
|
|
|
|
# include "components/header_start.hpp"
|
|
|
|
# include "components/types.hpp"
|
|
|
|
# include "components/gen/ecode.hpp"
|
|
|
|
# include "components/gen/eoperator.hpp"
|
|
|
|
# include "components/gen/especifier.hpp"
|
|
|
|
# include "components/ast.hpp"
|
|
|
|
# include "components/code_types.hpp"
|
|
|
|
# include "components/ast_types.hpp"
|
|
|
|
# include "components/interface.hpp"
|
|
|
|
# include "components/inlines.hpp"
|
|
|
|
# include "components/gen/ast_inlines.hpp"
|
|
|
|
# include "components/header_end.hpp"
|
2023-08-28 21:03:08 -07:00
|
|
|
#endif
|
2023-08-21 18:40:23 -07:00
|
|
|
|
2024-12-10 13:13:14 -08:00
|
|
|
#pragma region Scanner
|
|
|
|
|
2023-08-21 17:27:00 -07:00
|
|
|
// This is a simple file reader that reads the entire file into memory.
|
|
|
|
// It has an extra option to skip the first few lines for undesired includes.
|
|
|
|
// This is done so that includes can be kept in dependency and component files so that intellisense works.
|
2024-12-10 17:45:00 -08:00
|
|
|
Code scan_file( char const* path );
|
2023-07-24 19:19:21 -07:00
|
|
|
|
2024-12-10 17:45:00 -08:00
|
|
|
inline
|
2024-12-10 13:13:14 -08:00
|
|
|
CodeBody parse_file( const char* path )
|
2023-07-24 19:19:21 -07:00
|
|
|
{
|
2024-12-10 13:13:14 -08:00
|
|
|
FileContents file = file_read_contents( GlobalAllocator, true, path );
|
|
|
|
CodeBody code = parse_global_body( { file.size, (char const*)file.data } );
|
|
|
|
log_fmt("\nParsed: %s\n", path);
|
|
|
|
return code;
|
|
|
|
}
|
2023-07-18 20:33:00 -07:00
|
|
|
|
2024-12-10 13:13:14 -08:00
|
|
|
// The follow is basic support for light csv parsing (use it as an example)
|
|
|
|
// Make something robust if its more serious.
|
|
|
|
|
|
|
|
typedef struct CSV_Column CSV_Column;
|
|
|
|
struct CSV_Column {
|
2024-12-10 17:45:00 -08:00
|
|
|
CSV_Object ADT;
|
2024-12-10 13:13:14 -08:00
|
|
|
Array<ADT_Node> Content;
|
2023-07-18 20:33:00 -07:00
|
|
|
};
|
|
|
|
|
2024-12-10 13:13:14 -08:00
|
|
|
typedef struct CSV_Columns2 CSV_Columns2;
|
|
|
|
struct CSV_Columns2 {
|
2024-12-10 17:45:00 -08:00
|
|
|
CSV_Object ADT;
|
2024-12-10 13:13:14 -08:00
|
|
|
Array<ADT_Node> Col_1;
|
|
|
|
Array<ADT_Node> Col_2;
|
|
|
|
};
|
2023-07-18 20:33:00 -07:00
|
|
|
|
2024-12-10 17:45:00 -08:00
|
|
|
inline
|
2024-12-10 13:13:14 -08:00
|
|
|
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) {
|
|
|
|
char scratch_mem[kilobytes(32)];
|
|
|
|
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
|
|
|
|
|
|
|
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
|
2023-07-18 20:33:00 -07:00
|
|
|
|
2024-12-10 13:13:14 -08:00
|
|
|
CSV_Column result;
|
2024-12-10 17:45:00 -08:00
|
|
|
csv_parse( & result.ADT, scratch_mem, allocator, false );
|
|
|
|
result.Content = result.ADT.nodes[0].nodes;
|
2024-12-10 13:13:14 -08:00
|
|
|
return result;
|
|
|
|
}
|
2023-07-18 20:33:00 -07:00
|
|
|
|
2024-12-10 17:45:00 -08:00
|
|
|
inline
|
2024-12-10 13:13:14 -08:00
|
|
|
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path) {
|
|
|
|
char scratch_mem[kilobytes(32)];
|
|
|
|
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
2023-07-18 20:33:00 -07:00
|
|
|
|
2024-12-10 13:13:14 -08:00
|
|
|
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
|
2023-07-18 20:33:00 -07:00
|
|
|
|
2024-12-10 13:13:14 -08:00
|
|
|
CSV_Columns2 result;
|
2024-12-10 17:45:00 -08:00
|
|
|
csv_parse( & result.ADT, scratch_mem, allocator, false );
|
|
|
|
result.Col_1 = result.ADT.nodes[0].nodes;
|
|
|
|
result.Col_2 = result.ADT.nodes[1].nodes;
|
2023-09-11 20:22:53 -07:00
|
|
|
return result;
|
|
|
|
}
|
2024-12-10 13:13:14 -08:00
|
|
|
|
|
|
|
#pragma endregion Scanner
|