progress on sanity_tests.c, adding back md_str8_styllize

Eventually a heavy reduction of base & OS should be provided via libgen or done here to reduce the overall surface area of the library for the user.
Base and os were dragged from raddbg and the original metadesk didn't need as many definitions.
This commit is contained in:
ed
2025-02-13 09:53:46 -05:00
parent 28d0c85771
commit 3e064f6443
15 changed files with 390 additions and 252 deletions
+2 -7
View File
@@ -1,11 +1,6 @@
# Metadesk Library: RAD Debugger's Standalone Fork # Metadesk Library
This is a fork that aims to make the latest version of metadesk available from the [RAD Debugger](https://github.com/EpicGamesExt/raddebugger) accessible as a library. WIP: This hosts the raddbg's verion of mdesk module lifeted for use as a library. Intent is to get it working with tests & examples as the original was able to, then reduce the surface area of the base & os mdoules that it originally was dependent on to a minimal size. Before dependencies removal the modules will be hosted on a separate repo as a frozen state of their "libification".
**Note: This repo is under heavy WIP. Currently getting the code from RAD's (Epic Games) Debugger over to a standalone state while at the same time studying it.**
**Update:** This will contain just the minimal lib. Extra additions or the ability to generate variants are available at: [metadesk_libgen](https://github.com/Ed94/metadesk_libgen)
docs will be updated referencing content procued by Ryan Fleury and content based on studying or resolving this library for this repo.
## Documentation ## Documentation
+2 -2
View File
@@ -106,11 +106,11 @@ void temp_arena_end(MD_TempArena temp);
//- rjf: push helper macros //- rjf: push helper macros
#ifndef md_push_array_ #ifndef md_push_array
#define md_push_array__no_zero_aligned(a, T, c, align) (T *)md_arena_push((a), sizeof(T) * (c), (align)) #define md_push_array__no_zero_aligned(a, T, c, align) (T *)md_arena_push((a), sizeof(T) * (c), (align))
#define md_push_array__aligned(a, T, c, align) (T *)md_memory_zero(md_push_array__no_zero_aligned(a, T, c, align), sizeof(T) * (c)) #define md_push_array__aligned(a, T, c, align) (T *)md_memory_zero(md_push_array__no_zero_aligned(a, T, c, align), sizeof(T) * (c))
#define md_push_array__no_zero(a, T, c) md_push_array__no_zero_aligned(a, T, c, md_max(8, md_align_of(T))) #define md_push_array__no_zero(a, T, c) md_push_array__no_zero_aligned(a, T, c, md_max(8, md_align_of(T)))
#define md_push_array_(a, T, c) md_push_array__aligned (a, T, c, md_max(8, md_align_of(T))) #define md_push_array(a, T, c) md_push_array__aligned (a, T, c, md_max(8, md_align_of(T)))
#endif #endif
// Inlines // Inlines
+1 -1
View File
@@ -85,7 +85,7 @@ md_force_inline MD_CmdLine md_cmd_line_from_string_list__arena(MD_Arena* are
inline MD_CmdLineOpt* md_cmd_line_opt_from_string(MD_CmdLine *cmd_line, MD_String8 name) { return md_cmd_line_opt_from_slot(md_cmd_line_slot_from_string(cmd_line, name), name); } inline MD_CmdLineOpt* md_cmd_line_opt_from_string(MD_CmdLine *cmd_line, MD_String8 name) { return md_cmd_line_opt_from_slot(md_cmd_line_slot_from_string(cmd_line, name), name); }
inline MD_B32 md_cmd_line_has_flag (MD_CmdLine *cmd_line, MD_String8 name) { MD_CmdLineOpt *var = md_cmd_line_opt_from_string(cmd_line, name); return(var != 0); } inline MD_B32 md_cmd_line_has_flag (MD_CmdLine *cmd_line, MD_String8 name) { MD_CmdLineOpt *var = md_cmd_line_opt_from_string(cmd_line, name); return(var != 0); }
inline MD_B32 md_cmd_line_has_argument (MD_CmdLine *cmd_line, MD_String8 name) { MD_CmdLineOpt *var = md_cmd_line_opt_from_string(cmd_line, name); return(var != 0 && var->value_strings.md_node_count > 0); } inline MD_B32 md_cmd_line_has_argument (MD_CmdLine *cmd_line, MD_String8 name) { MD_CmdLineOpt *var = md_cmd_line_opt_from_string(cmd_line, name); return(var != 0 && var->value_strings.node_count > 0); }
inline MD_String8List inline MD_String8List
md_cmd_line_strings(MD_CmdLine *cmd_line, MD_String8 name) { md_cmd_line_strings(MD_CmdLine *cmd_line, MD_String8 name) {
+1 -1
View File
@@ -56,7 +56,7 @@ void
md_log_scope_begin(void) { md_log_scope_begin(void) {
if (md_log_active != 0) { if (md_log_active != 0) {
MD_U64 pos = md_arena_pos(md_log_active->arena); MD_U64 pos = md_arena_pos(md_log_active->arena);
MD_LogScope* scope = md_push_array_(md_log_active->arena, MD_LogScope, 1); MD_LogScope* scope = md_push_array(md_log_active->arena, MD_LogScope, 1);
scope->pos = pos; scope->pos = pos;
md_sll_stack_push(md_log_active->top_scope, scope); md_sll_stack_push(md_log_active->top_scope, scope);
} }
+1 -1
View File
@@ -58,7 +58,7 @@ md_log_alloc(MD_AllocatorInfo ainfo, MD_U64 md_arena_block_size) {
md_arena_block_size = MD_LOG_DEFAULT_ARENA_BLOCK_SIZE; md_arena_block_size = MD_LOG_DEFAULT_ARENA_BLOCK_SIZE;
} }
MD_Arena* arena = md_arena_alloc(.backing = ainfo, .block_size = md_arena_block_size); MD_Arena* arena = md_arena_alloc(.backing = ainfo, .block_size = md_arena_block_size);
MD_Log* log = md_push_array_(arena, MD_Log, 1); MD_Log* log = md_push_array(arena, MD_Log, 1);
log->arena = arena; log->arena = arena;
return log; return log;
} }
+3 -3
View File
@@ -37,7 +37,7 @@
#endif #endif
#ifndef md_thousand #ifndef md_thousand
#define thousand(n) ((n) * 1000) #define md_thousand(n) ((n) * 1000)
#endif #endif
#ifndef md_million #ifndef md_million
#define md_million(n) ((n) * 1000000) #define md_million(n) ((n) * 1000000)
@@ -801,9 +801,9 @@ md_sll__queue_pop_nz(void* nil, void** f, void* f_next, void** l)
#ifndef md_zero_struct #ifndef md_zero_struct
# if MD_LANG_CPP # if MD_LANG_CPP
# define md_zero_struct {} # define md_zero_struct() {}
# else # else
# define md_zero_struct {0} # define md_zero_struct() {0}
# endif # endif
#endif #endif
+2 -2
View File
@@ -672,7 +672,7 @@ md_str8_path_list_resolve_dots_in_place(MD_String8List* path, MD_PathStyle style
eliminate_stack_top: eliminate_stack_top:
{ {
path->md_node_count -= 1; path->node_count -= 1;
path->total_size -= stack->node->string.size; path->total_size -= stack->node->string.size;
md_sll_stack_pop(stack); md_sll_stack_pop(stack);
@@ -1377,7 +1377,7 @@ md_fuzzy_match_find__ainfo(MD_AllocatorInfo ainfo, MD_String8 needle, MD_String8
} }
if (find_pos < haystack.size) { if (find_pos < haystack.size) {
MD_Rng1U64 range = md_r1u64(find_pos, find_pos+needle_n->string.size); MD_Rng1U64 range = md_r1u64(find_pos, find_pos+needle_n->string.size);
MD_FuzzyMatchRangeNode* n = md_push_array_(scratch.arena, MD_FuzzyMatchRangeNode, 1); MD_FuzzyMatchRangeNode* n = md_push_array(scratch.arena, MD_FuzzyMatchRangeNode, 1);
n->range = range; n->range = range;
md_sll_queue_push(result.first, result.last, n); md_sll_queue_push(result.first, result.last, n);
result.count += 1; result.count += 1;
+7 -7
View File
@@ -616,7 +616,7 @@ void md_str8_list_concat_in_place (MD_String8List* list, MD
inline MD_String8Node* inline MD_String8Node*
md_str8_list_push_node(MD_String8List* list, MD_String8Node* node) { md_str8_list_push_node(MD_String8List* list, MD_String8Node* node) {
md_sll_queue_push(list->first, list->last, node); md_sll_queue_push(list->first, list->last, node);
list->md_node_count += 1; list->node_count += 1;
list->total_size += node->string.size; list->total_size += node->string.size;
return(node); return(node);
} }
@@ -624,7 +624,7 @@ md_str8_list_push_node(MD_String8List* list, MD_String8Node* node) {
inline MD_String8Node* inline MD_String8Node*
md_str8_list_push_node_set_string(MD_String8List* list, MD_String8Node* node, MD_String8 string) { md_str8_list_push_node_set_string(MD_String8List* list, MD_String8Node* node, MD_String8 string) {
md_sll_queue_push(list->first, list->last, node); md_sll_queue_push(list->first, list->last, node);
list->md_node_count += 1; list->node_count += 1;
list->total_size += string.size; list->total_size += string.size;
node->string = string; node->string = string;
return(node); return(node);
@@ -633,7 +633,7 @@ md_str8_list_push_node_set_string(MD_String8List* list, MD_String8Node* node, MD
inline MD_String8Node* inline MD_String8Node*
md_str8_list_push_node_front(MD_String8List* list, MD_String8Node* node) { md_str8_list_push_node_front(MD_String8List* list, MD_String8Node* node) {
md_sll_queue_push_front(list->first, list->last, node); md_sll_queue_push_front(list->first, list->last, node);
list->md_node_count += 1; list->node_count += 1;
list->total_size += node->string.size; list->total_size += node->string.size;
return(node); return(node);
} }
@@ -641,7 +641,7 @@ md_str8_list_push_node_front(MD_String8List* list, MD_String8Node* node) {
inline MD_String8Node* inline MD_String8Node*
md_str8_list_push_node_front_set_string(MD_String8List* list, MD_String8Node* node, MD_String8 string) { md_str8_list_push_node_front_set_string(MD_String8List* list, MD_String8Node* node, MD_String8 string) {
md_sll_queue_push_front(list->first, list->last, node); md_sll_queue_push_front(list->first, list->last, node);
list->md_node_count += 1; list->node_count += 1;
list->total_size += string.size; list->total_size += string.size;
node->string = string; node->string = string;
return(node); return(node);
@@ -791,7 +791,7 @@ md_str8_list_from_flags__ainfo(MD_AllocatorInfo ainfo, MD_String8List* list, MD_
inline MD_String8Array inline MD_String8Array
md_str8_array_from_list__ainfo(MD_AllocatorInfo ainfo, MD_String8List* list) { md_str8_array_from_list__ainfo(MD_AllocatorInfo ainfo, MD_String8List* list) {
MD_String8Array array; MD_String8Array array;
array.count = list->md_node_count; array.count = list->node_count;
array.v = md_alloc_array_no_zero(ainfo, MD_String8, array.count); array.v = md_alloc_array_no_zero(ainfo, MD_String8, array.count);
MD_U64 idx = 0; MD_U64 idx = 0;
for(MD_String8Node *n = list->first; n != 0; n = n->next, idx += 1) { for(MD_String8Node *n = list->first; n != 0; n = n->next, idx += 1) {
@@ -1124,7 +1124,7 @@ MD_API MD_FuzzyMatchRangeList md_fuzzy_match_range_list_copy__ainfo(MD_Allocator
#define md_fuzzy_match_range_list_copy(allocator, src) _Generic(allocator, MD_Arena*: md_fuzzy_match_range_list_copy__arena, MD_AllocatorInfo: md_fuzzy_match_range_list_copy__ainfo) md_generic_call(allocator, src) #define md_fuzzy_match_range_list_copy(allocator, src) _Generic(allocator, MD_Arena*: md_fuzzy_match_range_list_copy__arena, MD_AllocatorInfo: md_fuzzy_match_range_list_copy__ainfo) md_generic_call(allocator, src)
md_force_inline MD_FuzzyMatchRangeList md_fuzzy_match_find__arena (MD_Arena *arena, MD_String8 needle, MD_String8 haystack) { return md_fuzzy_match_find__ainfo (md_arena_allocator(arena), needle, haystack); } md_force_inline MD_FuzzyMatchRangeList md_fuzzy_match_find__arena (MD_Arena *arena, MD_String8 needle, MD_String8 haystack) { return md_fuzzy_match_find__ainfo (md_arena_allocator(arena), needle, haystack); }
md_force_inline MD_FuzzyMatchRangeList md_fuzzy_match_range_list_copy__arena(MD_Arena* arena, MD_FuzzyMatchRangeList* src) s{ return md_fuzzy_match_range_list_copy__ainfo(md_arena_allocator(arena), src); } md_force_inline MD_FuzzyMatchRangeList md_fuzzy_match_range_list_copy__arena(MD_Arena* arena, MD_FuzzyMatchRangeList* src) { return md_fuzzy_match_range_list_copy__ainfo(md_arena_allocator(arena), src); }
//////////////////////////////// ////////////////////////////////
//~ NOTE(allen): Serialization Helpers //~ NOTE(allen): Serialization Helpers
@@ -1221,7 +1221,7 @@ md_str8_serial_begin__ainfo(MD_AllocatorInfo ainfo, MD_String8List* srl) {
MD_String8Node* node = md_alloc_array(ainfo, MD_String8Node, 1); MD_String8Node* node = md_alloc_array(ainfo, MD_String8Node, 1);
node->string.str = md_alloc_array_no_zero(ainfo, MD_U8, 0); node->string.str = md_alloc_array_no_zero(ainfo, MD_U8, 0);
srl->first = srl->last = node; srl->first = srl->last = node;
srl->md_node_count = 1; srl->node_count = 1;
srl->total_size = 0; srl->total_size = 0;
} }
+123 -1
View File
@@ -6,6 +6,128 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
MD_String8
md_str8_stylize(MD_Arena* arena, MD_String8 string, MD_IdentifierStyle word_style, MD_String8 separator)
{
MD_String8 result = md_zero_struct();
MD_String8List words = md_zero_struct();
MD_B32 break_on_uppercase = 0;
{
break_on_uppercase = 1;
for (MD_U64 i = 0; i < string.size; i += 1)
{
if ( ! md_char_is_alpha(string.str[i]) && ! md_char_is_digit(string.str[i])) {
break_on_uppercase = 0;
break;
}
}
}
MD_B32 making_word = 0;
MD_String8 word = md_zero_struct();
for (MD_U64 i = 0; i < string.size;)
{
if (making_word)
{
if ( (break_on_uppercase && md_char_is_upper(string.str[i])) || string.str[i] == '_' || md_char_is_space(string.str[i]) || i == string.size - 1)
{
if (i == string.size - 1) {
word.size += 1;
}
making_word = 0;
md_str8_list_push(arena, &words, word);
}
else
{
word.size += 1;
i += 1;
}
}
else
{
if(md_char_is_alpha(string.str[i]))
{
making_word = 1;
word.str = string.str + i;
word.size = 1;
}
i += 1;
}
}
result.size = words.total_size;
if (words.node_count > 1) {
result.size += separator.size*(words.node_count-1);
}
result.str = md_push_array(arena, MD_U8*, result.size);
{
MD_U64 write_pos = 0;
for(MD_String8Node *node = words.first; node; node = node->next)
{
// NOTE(rjf): Write word string to result.
{
MD_MemoryCopy(result.str + write_pos, node->string.str, node->string.size);
// NOTE(rjf): Transform string based on word style.
switch(word_style)
{
case MD_IdentifierStyle_UpperCamelCase:
{
result.str[write_pos] = MD_CharToUpper(result.str[write_pos]);
for(MD_u64 i = write_pos+1; i < write_pos + node->string.size; i += 1)
{
result.str[i] = MD_CharToLower(result.str[i]);
}
}break;
case MD_IdentifierStyle_LowerCamelCase:
{
MD_b32 is_first = (node == words.first);
result.str[write_pos] = (is_first ?
MD_CharToLower(result.str[write_pos]) :
MD_CharToUpper(result.str[write_pos]));
for(MD_u64 i = write_pos+1; i < write_pos + node->string.size; i += 1)
{
result.str[i] = MD_CharToLower(result.str[i]);
}
}break;
case MD_IdentifierStyle_UpperCase:
{
for(MD_u64 i = write_pos; i < write_pos + node->string.size; i += 1)
{
result.str[i] = MD_CharToUpper(result.str[i]);
}
}break;
case MD_IdentifierStyle_LowerCase:
{
for(MD_u64 i = write_pos; i < write_pos + node->string.size; i += 1)
{
result.str[i] = MD_CharToLower(result.str[i]);
}
}break;
default: break;
}
write_pos += node->string.size;
}
if(node->next)
{
MD_MemoryCopy(result.str + write_pos, separator.str, separator.size);
write_pos += separator.size;
}
}
}
return result;
}
//////////////////////////////// ////////////////////////////////
// MD_Context // MD_Context
@@ -648,7 +770,7 @@ void md_parse__work_push(MD_ParseWorkKind work_kind, MD_Node* work_parent, MD_Pa
{ {
MD_ParseWorkNode* work_node = work_free; MD_ParseWorkNode* work_node = work_free;
if (work_node == 0) { if (work_node == 0) {
work_node = md_push_array_(scratch->arena, MD_ParseWorkNode, 1); work_node = md_push_array(scratch->arena, MD_ParseWorkNode, 1);
} }
else { else {
md_sll_stack_pop(work_free); md_sll_stack_pop(work_free);
+13 -1
View File
@@ -6,6 +6,18 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
// String Identifier Style
typedef enum MD_IdentifierStyle MD_IdentifierStyle;
enum MD_IdentifierStyle
{
MD_IdentifierStyle_UpperCamelCase,
MD_IdentifierStyle_LowerCamelCase,
MD_IdentifierStyle_UpperCase,
MD_IdentifierStyle_LowerCase,
};
MD_API MD_String8 md_str8_stylize(MD_Arena* arena, MD_String8 string, MD_IdentifierStyle style, MD_String8 separator);
//////////////////////////////// ////////////////////////////////
//~ rjf: Messages //~ rjf: Messages
@@ -593,7 +605,7 @@ MD_API MD_ParseResult md_parse_from_text__arena(MD_Arena* arena, MD_Strin
MD_API MD_ParseResult md_parse_from_text__ainfo(MD_AllocatorInfo ainfo, MD_String8 filename, MD_String8 text); MD_API MD_ParseResult md_parse_from_text__ainfo(MD_AllocatorInfo ainfo, MD_String8 filename, MD_String8 text);
#define md_parse_from_text(allocator, filename, text) _Generic(allocator, MD_Arena*: md_parse_from_text__arena, MD_AllocatorInfo: md_parse_from_text__ainfo, default: md_assert_generic_sel_fail) md_generic_call(allocator, filename, text) #define md_parse_from_text(allocator, filename, text) _Generic(allocator, MD_Arena*: md_parse_from_text__arena, MD_AllocatorInfo: md_parse_from_text__ainfo, default: md_assert_generic_sel_fail) md_generic_call(allocator, filename, text)
#define tree_from_string(allocator, string) (md_parse_from_text((allocator), md_str8_zero(), (string)).root) #define md_tree_from_string(allocator, string) (md_parse_from_text((allocator), md_str8_zero(), (string)).root)
md_force_inline MD_ParseResult md_parse_from_text__arena(MD_Arena* arena, MD_String8 filename, MD_String8 text) { return md_parse_from_text__ainfo(md_arena_allocator(arena), filename, text); } md_force_inline MD_ParseResult md_parse_from_text__arena(MD_Arena* arena, MD_String8 filename, MD_String8 text) { return md_parse_from_text__ainfo(md_arena_allocator(arena), filename, text); }
+7 -7
View File
@@ -491,7 +491,7 @@ MD_U64
md_os_now_microseconds(void) { md_os_now_microseconds(void) {
struct timespec t; struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t); clock_gettime(CLOCK_MONOTONIC, &t);
MD_U64 result = t.tv_sec * md_million(1) + (t.tv_nsec / thousand(1)); MD_U64 result = t.tv_sec * md_million(1) + (t.tv_nsec / md_thousand(1));
return result; return result;
} }
@@ -544,7 +544,7 @@ md_os_local_time_from_universal(MD_DateTime* date_time)
void void
md_os_sleep_milliseconds(MD_U32 msec) { md_os_sleep_milliseconds(MD_U32 msec) {
usleep(msec * thousand(1)); usleep(msec * md_thousand(1));
} }
//////////////////////////////// ////////////////////////////////
@@ -753,7 +753,7 @@ md_os_condition_variable_wait(MD_OS_Handle cv, MD_OS_Handle mutex, MD_U64 endt_u
struct timespec endt_timespec; struct timespec endt_timespec;
endt_timespec.tv_sec = endt_us / md_million(1); endt_timespec.tv_sec = endt_us / md_million(1);
endt_timespec.tv_nsec = thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1)); endt_timespec.tv_nsec = md_thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1));
int wait_result = pthread_cond_timedwait(&cv_entity->cv.cond_handle, &mutex_entity->mutex_handle, &endt_timespec); int wait_result = pthread_cond_timedwait(&cv_entity->cv.cond_handle, &mutex_entity->mutex_handle, &endt_timespec);
MD_B32 result = (wait_result != ETIMEDOUT); MD_B32 result = (wait_result != ETIMEDOUT);
@@ -775,7 +775,7 @@ md_os_condition_variable_wait_rw_r(MD_OS_Handle cv, MD_OS_Handle mutex_rw, MD_U6
struct timespec endt_timespec; struct timespec endt_timespec;
endt_timespec.tv_sec = endt_us / md_million(1); endt_timespec.tv_sec = endt_us / md_million(1);
endt_timespec.tv_nsec = thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1)); endt_timespec.tv_nsec = md_thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1));
MD_B32 result = 0; MD_B32 result = 0;
for(;;) for(;;)
@@ -814,7 +814,7 @@ md_os_condition_variable_wait_rw_w(MD_OS_Handle cv, MD_OS_Handle mutex_rw, MD_U6
struct timespec endt_timespec; struct timespec endt_timespec;
endt_timespec.tv_sec = endt_us / md_million(1); endt_timespec.tv_sec = endt_us / md_million(1);
endt_timespec.tv_nsec = thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1)); endt_timespec.tv_nsec = md_thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1));
MD_B32 result = 0; MD_B32 result = 0;
for(;;) for(;;)
@@ -927,7 +927,7 @@ md_os_safe_call(MD_OS_ThreadFunctionType* func, MD_OS_ThreadFunctionType* fail_h
{ {
// rjf: push handler to chain // rjf: push handler to chain
MD_OS_LNX_SafeCallChain chain = {0}; MD_OS_LNX_SafeCallChain chain = {0};
SLLStackPush(md_os_lnx_safe_call_chain, &chain); sll_stack_push(md_os_lnx_safe_call_chain, &chain);
chain.fail_handler = fail_handler; chain.fail_handler = fail_handler;
chain.ptr = ptr; chain.ptr = ptr;
@@ -1030,7 +1030,7 @@ main(int argc, char **argv)
{ {
info->machine_name.size = size; info->machine_name.size = size;
info->machine_name.str = md_push_array__no_zero(md_os_lnx_state.arena, MD_U8, info->machine_name.size + 1); info->machine_name.str = md_push_array__no_zero(md_os_lnx_state.arena, MD_U8, info->machine_name.size + 1);
MemoryCopy(info->machine_name.str, buffer, info->machine_name.size); memory_copy(info->machine_name.str, buffer, info->machine_name.size);
info->machine_name.str[info->machine_name.size] = 0; info->machine_name.str[info->machine_name.size] = 0;
} }
+1 -1
View File
@@ -105,7 +105,7 @@ inline MD_DateTime
md_os_lnx_date_time_from_tm(tm in, MD_U32 msec) { md_os_lnx_date_time_from_tm(tm in, MD_U32 msec) {
MD_DateTime dt = {0}; MD_DateTime dt = {0};
dt.sec = in.tm_sec; dt.sec = in.tm_sec;
dt.md_min = in.tm_min; dt.min = in.tm_min;
dt.hour = in.tm_hour; dt.hour = in.tm_hour;
dt.day = in.tm_mday-1; dt.day = in.tm_mday-1;
+5 -2
View File
@@ -1,3 +1,6 @@
#ifdef INTELLISENSE_DIRECTIVES
# include "os_win32.h"
#endif
// Copyright (c) 2024 Epic Games Tools // Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
@@ -786,7 +789,7 @@ md_os_process_launch(MD_OS_ProcessLaunchParams* params)
MD_String8List all_opts = params->env; MD_String8List all_opts = params->env;
if (params->inherit_env != 0) if (params->inherit_env != 0)
{ {
if (all_opts.md_node_count != 0) if (all_opts.node_count != 0)
{ {
md_memory_zero_struct(&all_opts); md_memory_zero_struct(&all_opts);
for (MD_String8Node *n = params->env.first; n != 0; n = n->next) { for (MD_String8Node *n = params->env.first; n != 0; n = n->next) {
@@ -1486,7 +1489,7 @@ w32_entry_point_caller(int argc, WCHAR** wargv)
//- rjf: extract arguments //- rjf: extract arguments
MD_Arena* args_arena = md_arena_alloc(.backing = md_varena_alloc(.reserve_size = MD_MB(1), .commit_size = MD_KB(32))); MD_Arena* args_arena = md_arena_alloc(.backing = md_varena_alloc(.reserve_size = MD_MB(1), .commit_size = MD_KB(32)));
char** argv = md_push_array_(args_arena, char*, argc); char** argv = md_push_array(args_arena, char*, argc);
for (int i = 0; i < argc; i += 1) for (int i = 0; i < argc; i += 1)
{ {
MD_String16 arg16 = md_str16_cstring((MD_U16 *)wargv[i]); MD_String16 arg16 = md_str16_cstring((MD_U16 *)wargv[i]);
+2 -2
View File
@@ -101,7 +101,7 @@ md_os_w32_date_time_from_system_time(MD_DateTime* out, SYSTEMTIME* in)
out->day = in->wDay; out->day = in->wDay;
out->hour = in->wHour; out->hour = in->wHour;
out->md_min = in->wMinute; out->min = in->wMinute;
out->sec = in->wSecond; out->sec = in->wSecond;
out->msec = in->wMilliseconds; out->msec = in->wMilliseconds;
} }
@@ -114,7 +114,7 @@ md_os_w32_system_time_from_date_time(SYSTEMTIME* out, MD_DateTime* in)
out->wDay = in->day; out->wDay = in->day;
out->wHour = in->hour; out->wHour = in->hour;
out->wMinute = in->md_min; out->wMinute = in->min;
out->wSecond = in->sec; out->wSecond = in->sec;
out->wMilliseconds = in->msec; out->wMilliseconds = in->msec;
} }
+154 -148
View File
@@ -79,8 +79,7 @@ match_parsed_with_node(MD_Arena* arena, MD_String8 string, MD_Node* tree)
static MD_B32 static MD_B32
token_match(MD_String8 text, MD_Token token, MD_String8 string, MD_TokenFlags flags) token_match(MD_String8 text, MD_Token token, MD_String8 string, MD_TokenFlags flags)
{ {
return md_str8_match(string, md_str8_substr(text, token.range), 0) &&& token.flags == flags; return md_str8_match(string, md_str8_substr(text, token.range), 0) && token.flags == flags;
// return MD_S8Match(string, token.string, 0) && token.kind == kind;
} }
int main(void) int main(void)
@@ -171,7 +170,7 @@ int main(void)
md_node_push_child(sub, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("3"))); md_node_push_child(sub, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("3")));
md_node_push_child(tree, sub); md_node_push_child(tree, sub);
} }
MD_PushChild(tree, make_test_node(MD_NodeKind_Main, md_str8_lit("c"))); MD_PushChild(tree, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("c")));
test_result(matched_parsed_with_node(string, tree)); test_result(matched_parsed_with_node(string, tree));
} }
@@ -180,7 +179,7 @@ int main(void)
MD_Node* tree = make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("foo")); MD_Node* tree = make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("foo"));
MD_Node* params = make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("")); MD_Node* params = make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit(""));
MD_Node* size = make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("size")); MD_Node* size = make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("size"));
md_node_push_child(size, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier md_str8_lit("u64"))); md_node_push_child(size, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("u64")));
md_node_push_child(params, size); md_node_push_child(params, size);
md_node_push_child(tree, params); md_node_push_child(tree, params);
md_node_push_child(tree, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("->"))); md_node_push_child(tree, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("->")));
@@ -200,32 +199,41 @@ int main(void)
test("Set Border Flags") test("Set Border Flags")
{ {
{ {
MD_TokenizeResult lexed = md_token_array_from_chunk_list() MD_String8 str = md_str8_lit("(0, 100)");
MD_ParseResult parse = md_parse MD_ParseOneNode(arena, md_str8_lit("(0, 100)"), 0); MD_TokenizeResult lexed = md_tokenize_from_text(arena, str);
MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens);
test_result(parse.root->flags & MD_NodeFlag_HasParenLeft && test_result(parse.root->flags & MD_NodeFlag_HasParenLeft &&
parse.root->flags & MD_NodeFlag_HasParenRight); parse.root->flags & MD_NodeFlag_HasParenRight);
} }
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("(0, 100]"), 0); MD_String8 str = md_str8_lit("(0, 100]");
MD_TokenizeResult lexed = md_tokenize_from_text(arena, str);
MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens);
test_result(parse.root->flags & MD_NodeFlag_HasParenLeft && test_result(parse.root->flags & MD_NodeFlag_HasParenLeft &&
parse.root->flags & MD_NodeFlag_HasBracketRight); parse.root->flags & MD_NodeFlag_HasBracketRight);
} }
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("[0, 100)"), 0); MD_String8 str = md_str8_lit("[0, 100)");
MD_TokenizeResult lexed = md_tokenize_from_text(arena, str);
MD_ParseResult parse = md_parse_from_text_tokens(arena, fmd_str8_zero(), str, lexed.tokens);
test_result(parse.root->flags & MD_NodeFlag_HasBracketLeft && test_result(parse.root->flags & MD_NodeFlag_HasBracketLeft &&
parse.root->flags & MD_NodeFlag_HasParenRight); parse.root->flags & MD_NodeFlag_HasParenRight);
} }
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("[0, 100]"), 0); MD_String8 str = md_str8_lit("[0, 100]");
MD_TokenizeResult lexed = md_tokenize_from_text(arena, str);
MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens);
test_result(parse.root->flags & MD_NodeFlag_HasBracketLeft && test_result(parse.root->flags & MD_NodeFlag_HasBracketLeft &&
parse.root->flags & MD_NodeFlag_HasBracketRight); parse.root->flags & MD_NodeFlag_HasBracketRight);
} }
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("{0, 100}"), 0); MD_String8 str = md_str8_lit("{0, 100}");
MD_TokenizeResult lexed = md_tokenize_from_text(arena, str);
MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens);
test_result(parse.root->flags & MD_NodeFlag_HasBraceLeft && test_result(parse.root->flags & MD_NodeFlag_HasBraceLeft &&
parse.root->flags & MD_NodeFlag_HasBraceRight); parse.root->flags & MD_NodeFlag_HasBraceRight);
} }
@@ -234,92 +242,90 @@ int main(void)
test("Node Separator Flags") test("Node Separator Flags")
{ {
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("(a, b)"), 0); MD_String8 str = md_str8_lit("(a, b)");
test_result(parse.root->first_child->flags & MD_NodeFlag_IsBeforeComma); MD_TokenizeResult lexed = md_tokenize_from_text(arena, str);
test_result(parse.root->first_child->next->flags & MD_NodeFlag_IsAfterComma); MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens);
test_result(parse.root->first->flags & MD_NodeFlag_IsBeforeComma);
test_result(parse.root->first->next->flags & MD_NodeFlag_IsAfterComma);
} }
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("(a; b)"), 0); MD_String8 str = md_str8_lit("(a; b)");
test_result(parse.root->first_child->flags & MD_NodeFlag_IsBeforeSemicolon); MD_TokenizeResult lexed = md_tokenize_from_text(arena, str);
test_result(parse.root->first_child->next->flags & MD_NodeFlag_IsAfterSemicolon); MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens);
test_result(parse.root->first->flags & MD_NodeFlag_IsBeforeSemicolon);
test_result(parse.root->first->next->flags & MD_NodeFlag_IsAfterSemicolon);
} }
} }
test("Node Text Flags") test("Node Text Flags")
{ {
TestResult(MD_ParseOneNode(arena, md_str8_lit("123"), 0).node->flags &MD_NodeFlag_Numeric); test_result(md_tree_from_string(arena, md_str8_lit("123_456_789"))->flags & MD_NodeFlag_Numeric);
TestResult(MD_ParseOneNode(arena, md_str8_lit("123_456_789"), 0).node->flags &MD_NodeFlag_Numeric); test_result(md_tree_from_string(arena, md_str8_lit("abc") )->flags & MD_NodeFlag_Identifier);
TestResult(MD_ParseOneNode(arena, md_str8_lit("abc"), 0).node->flags &MD_NodeFlag_Identifier);
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("\"foo\""), 0); MD_Node* root = md_tree_from_string(arena, md_str8_lit("\"foo\""));
TestResult(parse.root->flags & MD_NodeFlag_StringLiteral && test_result(root->flags & MD_NodeFlag_StringLiteral &&
parse.root->flags & MD_NodeFlag_StringDoubleQuote); root->flags & MD_NodeFlag_StringDoubleQuote);
} }
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("'foo'"), 0); MD_Node* root = md_tree_from_string(arena, md_str8_lit("'foo'"));
TestResult(parse.root->flags & NodeFlag_StringLiteral && test_result(root->flags & MD_NodeFlag_StringLiteral &&
parse.root->flags & NodeFlag_StringSingleQuote); root->flags & MD_NodeFlag_StringSingleQuote);
} }
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`foo`"), 0); MD_Node* root = md_tree_from_string(arena, md_str8_lit("`foo`"), 0);
TestResult(parse.root->flags & NodeFlag_StringLiteral && test_result(root->flags & MD_NodeFlag_StringLiteral &&
parse.root->flags & NodeFlag_StringTick); root->flags & MD_NodeFlag_StringTick);
} }
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("\"\"\"foo\"\"\""), 0); MD_Node* root = md_tree_from_string(arena, md_str8_lit("\"\"\"foo\"\"\""), 0);
TestResult(parse.root->flags & NodeFlag_StringLiteral && test_result(parse.root->flags & MD_NodeFlag_StringLiteral &&
parse.root->flags & NodeFlag_StringDoubleQuote && parse.root->flags & MD_NodeFlag_StringDoubleQuote &&
parse.root->flags & NodeFlag_StringTriplet); parse.root->flags & MD_NodeFlag_StringTriplet);
} }
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("'''foo'''"), 0); MD_Node* root = md_tree_from_string(arena, md_str8_lit("'''foo'''"), 0);
TestResult(parse.root->flags & NodeFlag_StringLiteral && test_result(parse.root->flags & MD_NodeFlag_StringLiteral &&
parse.root->flags & NodeFlag_StringSingleQuote && parse.root->flags & MD_NodeFlag_StringSingleQuote &&
parse.root->flags & NodeFlag_StringTriplet); parse.root->flags & MD_NodeFlag_StringTriplet);
} }
{ {
MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("```foo```"), 0); MD_Node* root = md_tree_from_string(arena, md_str8_lit("```foo```"), 0);
TestResult(parse.root->flags & NodeFlag_StringLiteral && test_result(parse.root->flags & MD_NodeFlag_StringLiteral &&
parse.root->flags & NodeFlag_StringTick && parse.root->flags & MD_NodeFlag_StringTick &&
parse.root->flags & NodeFlag_StringTriplet); parse.root->flags & MD_NodeFlag_StringTriplet);
} }
} }
test("Style Strings") test("Style Strings")
{ {
{ {
MD_String8 str = md_str8_style(arena, MD_S8Lit("THIS_IS_A_TEST"), MD_String8 str = md_str8_style(arena, MD_S8Lit("THIS_IS_A_TEST"), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" "));
MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" ")); test_result(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0));
TestResult(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0));
} }
{ {
MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("this_is_a_test"), MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("this_is_a_test"), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" "));
MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" ")); test_result(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0));
TestResult(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0));
} }
{ {
MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("ThisIsATest"), MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("ThisIsATest"), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" "));
MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" ")); test_result(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0));
TestResult(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0));
} }
{ {
MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("Here is another test."), MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("Here is another test."), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(""));
MD_IdentifierStyle_UpperCamelCase, MD_S8Lit("")); test_result(MD_S8Match(str, MD_S8Lit("HereIsAnotherTest."), 0));
TestResult(MD_S8Match(str, MD_S8Lit("HereIsAnotherTest."), 0));
} }
} }
test("Enum Strings") test("Enum Strings")
{ {
TestResult(MD_S8Match(MD_StringFromNodeKind(MD_NodeKind_Main), MD_S8Lit("Main"), 0)); test_result(MD_S8Match(MD_StringFromNodeKind(MD_NodeKind_Main), MD_S8Lit("Main"), 0));
TestResult(MD_S8Match(MD_StringFromNodeKind(MD_NodeKind_Main), MD_S8Lit("Main"), 0)); test_result(MD_S8Match(MD_StringFromNodeKind(MD_NodeKind_Main), MD_S8Lit("Main"), 0));
MD_String8List list = MD_StringListFromNodeFlags(arena, MD_String8List list = MD_StringListFromNodeFlags(arena,
MD_NodeFlag_StringLiteral | MD_NodeFlag_StringLiteral |
MD_NodeFlag_HasParenLeft | MD_NodeFlag_HasParenLeft |
MD_NodeFlag_IsBeforeSemicolon); MD_NodeFlag_IsBeforeSemicolon);
MD_B32 match = 1; MD_B32 match = 1;
for(MD_String8Node *node = list.first; node; node = node->next) for(MD_String8Node *node = list.first; node; node = node->next)
md_str8_lit
if(!md_str8_match(node->string, md_str8_lit("StringLiteral"), 0) && if(!md_str8_match(node->string, md_str8_lit("StringLiteral"), 0) &&
!md_str8_match(node->string, md_str8_lit("HasParenLeft"), 0) && !md_str8_match(node->string, md_str8_lit("HasParenLeft"), 0) &&
!md_str8_match(node->string, md_str8_lit("IsBeforeSemicolon"), 0)) !md_str8_match(node->string, md_str8_lit("IsBeforeSemicolon"), 0))
@@ -328,7 +334,7 @@ int main(void)
break; break;
} }
} }
TestResult(match); test_result(match);
} }
test("Node Comments") test("Node Comments")
@@ -338,17 +344,17 @@ int main(void)
{ {
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("/*foobar*/ (a b c)"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("/*foobar*/ (a b c)"), 0);
TestResult(parse.node->kind == NodeKind_Main && test_result(parse.node->kind == NodeKind_Main &&
MD_S8Match(parse.node->prev_comment, MD_S8Lit("foobar"), 0)); MD_S8Match(parse.node->prev_comment, MD_S8Lit("foobar"), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("// foobar\n(a b c)"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("// foobar\n(a b c)"), 0);
TestResult(parse.node->kind == NodeKind_Main && test_result(parse.node->kind == NodeKind_Main &&
MD_S8Match(parse.node->prev_comment, MD_S8Lit(" foobar"), 0)); MD_S8Match(parse.node->prev_comment, MD_S8Lit(" foobar"), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("// foobar\n\n(a b c)"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("// foobar\n\n(a b c)"), 0);
TestResult(parse.node->kind == NodeKind_Main && test_result(parse.node->kind == NodeKind_Main &&
MD_S8Match(parse.node->prev_comment, MD_S8Lit(""), 0)); MD_S8Match(parse.node->prev_comment, MD_S8Lit(""), 0));
} }
} }
@@ -357,22 +363,22 @@ int main(void)
{ {
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c) /*foobar*/"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c) /*foobar*/"), 0);
TestResult(parse.node->kind == NodeKind_Main && test_result(parse.node->kind == NodeKind_Main &&
MD_S8Match(parse.node->next_comment, MD_S8Lit("foobar"), 0)); MD_S8Match(parse.node->next_comment, MD_S8Lit("foobar"), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c) // foobar"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c) // foobar"), 0);
TestResult(parse.node->kind == NodeKind_Main && test_result(parse.node->kind == NodeKind_Main &&
MD_S8Match(parse.node->next_comment, MD_S8Lit(" foobar"), 0)); MD_S8Match(parse.node->next_comment, MD_S8Lit(" foobar"), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c)\n// foobar"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c)\n// foobar"), 0);
TestResult(parse.node->kind == NodeKind_Main && test_result(parse.node->kind == NodeKind_Main &&
MD_S8Match(parse.node->next_comment, MD_S8Lit(""), 0)); MD_S8Match(parse.node->next_comment, MD_S8Lit(""), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c)\n\n// foobar"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c)\n\n// foobar"), 0);
TestResult(parse.node->kind == NodeKind_Main && test_result(parse.node->kind == NodeKind_Main &&
MD_S8Match(parse.node->next_comment, MD_S8Lit(""), 0)); MD_S8Match(parse.node->next_comment, MD_S8Lit(""), 0));
} }
} }
@@ -415,12 +421,12 @@ int main(void)
columns_match = 0; columns_match = 0;
} }
} }
TestResult(columns_match); test_result(columns_match);
} }
{ {
ParseResult parse = MD_ParseWholeFile(arena, MD_S8Lit("__does_not_exist.mdesk")); ParseResult parse = MD_ParseWholeFile(arena, MD_S8Lit("__does_not_exist.mdesk"));
TestResult(parse.node->kind == NodeKind_File && parse.errors.first != 0); test_result(parse.node->kind == NodeKind_File && parse.errors.first != 0);
} }
} }
@@ -453,7 +459,7 @@ int main(void)
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1) for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1)
{ {
MD_MapSlot *slot = MD_MapLookup(&map, keys[i]); MD_MapSlot *slot = MD_MapLookup(&map, keys[i]);
TestResult(slot && slot->val == (void *)i); test_result(slot && slot->val == (void *)i);
} }
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1) for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1)
{ {
@@ -462,7 +468,7 @@ int main(void)
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1) for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1)
{ {
MD_MapSlot *slot = MD_MapLookup(&map, keys[i]); MD_MapSlot *slot = MD_MapLookup(&map, keys[i]);
TestResult(slot && slot->val == (void *)(i + 10)); test_result(slot && slot->val == (void *)(i + 10));
} }
} }
} }
@@ -485,60 +491,60 @@ int main(void)
nodes[i] = result.node; nodes[i] = result.node;
} }
TestResult(MD_S8Match(nodes[0]->string, MD_S8Lit("foo-bar"), 0)); test_result(MD_S8Match(nodes[0]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[1]->string, MD_S8Lit("foo-bar"), 0)); test_result(MD_S8Match(nodes[1]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[2]->string, MD_S8Lit("foo-bar"), 0)); test_result(MD_S8Match(nodes[2]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[3]->string, MD_S8Lit("foo-bar"), 0)); test_result(MD_S8Match(nodes[3]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[4]->string, MD_S8Lit("foo-bar"), 0)); test_result(MD_S8Match(nodes[4]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[5]->string, MD_S8Lit("foo-bar"), 0)); test_result(MD_S8Match(nodes[5]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[0]->raw_string, samples[0], 0)); test_result(MD_S8Match(nodes[0]->raw_string, samples[0], 0));
TestResult(MD_S8Match(nodes[1]->raw_string, samples[1], 0)); test_result(MD_S8Match(nodes[1]->raw_string, samples[1], 0));
TestResult(MD_S8Match(nodes[2]->raw_string, samples[2], 0)); test_result(MD_S8Match(nodes[2]->raw_string, samples[2], 0));
TestResult(MD_S8Match(nodes[3]->raw_string, samples[3], 0)); test_result(MD_S8Match(nodes[3]->raw_string, samples[3], 0));
TestResult(MD_S8Match(nodes[4]->raw_string, samples[4], 0)); test_result(MD_S8Match(nodes[4]->raw_string, samples[4], 0));
TestResult(MD_S8Match(nodes[5]->raw_string, samples[5], 0)); test_result(MD_S8Match(nodes[5]->raw_string, samples[5], 0));
} }
test("String escaping") test("String escaping")
{ {
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`\\``"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`\\``"), 0);
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\\`"), 0)); test_result(MD_S8Match(parse.node->string, MD_S8Lit("\\`"), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("``` \\``` ```"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("``` \\``` ```"), 0);
TestResult(MD_S8Match(parse.node->string, MD_S8Lit(" \\``` "), 0)); test_result(MD_S8Match(parse.node->string, MD_S8Lit(" \\``` "), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`````\\````"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`````\\````"), 0);
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("``\\`"), 0)); test_result(MD_S8Match(parse.node->string, MD_S8Lit("``\\`"), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`\\'`"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`\\'`"), 0);
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\\'"), 0)); test_result(MD_S8Match(parse.node->string, MD_S8Lit("\\'"), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("''' \\''' '''"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("''' \\''' '''"), 0);
TestResult(MD_S8Match(parse.node->string, MD_S8Lit(" \\''' "), 0)); test_result(MD_S8Match(parse.node->string, MD_S8Lit(" \\''' "), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("'''''\\''''"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("'''''\\''''"), 0);
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("''\\'"), 0)); test_result(MD_S8Match(parse.node->string, MD_S8Lit("''\\'"), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`\\\"`"), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`\\\"`"), 0);
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\\\""), 0)); test_result(MD_S8Match(parse.node->string, MD_S8Lit("\\\""), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("\"\"\" \\\"\"\" \"\"\""), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("\"\"\" \\\"\"\" \"\"\""), 0);
TestResult(MD_S8Match(parse.node->string, MD_S8Lit(" \\\"\"\" "), 0)); test_result(MD_S8Match(parse.node->string, MD_S8Lit(" \\\"\"\" "), 0));
} }
{ {
ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("\"\"\"\"\"\\\"\"\"\""), 0); ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("\"\"\"\"\"\\\"\"\"\""), 0);
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\"\"\\\""), 0)); test_result(MD_S8Match(parse.node->string, MD_S8Lit("\"\"\\\""), 0));
} }
} }
@@ -551,18 +557,18 @@ int main(void)
Node *group_first = node->first_child; Node *group_first = node->first_child;
Node *group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterSemicolon); Node *group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterSemicolon);
TestResult(MD_S8Match(group_first->string, MD_S8Lit("x"), 0)); test_result(MD_S8Match(group_first->string, MD_S8Lit("x"), 0));
TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("y"), 0)); test_result(MD_S8Match(group_first->next->string, MD_S8Lit("y"), 0));
TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("z"), 0)); test_result(MD_S8Match(group_first->next->next->string, MD_S8Lit("z"), 0));
TestResult(group_opl == group_first->next->next->next); test_result(group_opl == group_first->next->next->next);
group_first = group_opl; group_first = group_opl;
group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterSemicolon); group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterSemicolon);
TestResult(MD_S8Match(group_first->string, MD_S8Lit("a"), 0)); test_result(MD_S8Match(group_first->string, MD_S8Lit("a"), 0));
TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("b"), 0)); test_result(MD_S8Match(group_first->next->string, MD_S8Lit("b"), 0));
TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("c"), 0)); test_result(MD_S8Match(group_first->next->next->string, MD_S8Lit("c"), 0));
TestResult(group_opl == group_first->next->next->next); test_result(group_opl == group_first->next->next->next);
} }
{ {
@@ -573,24 +579,24 @@ int main(void)
group_first = node->first_child; group_first = node->first_child;
group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterComma); group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterComma);
TestResult(MD_S8Match(group_first->string, MD_S8Lit("a"), 0)); test_result(MD_S8Match(group_first->string, MD_S8Lit("a"), 0));
TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("b"), 0)); test_result(MD_S8Match(group_first->next->string, MD_S8Lit("b"), 0));
TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("c"), 0)); test_result(MD_S8Match(group_first->next->next->string, MD_S8Lit("c"), 0));
TestResult(group_opl == group_first->next->next->next); test_result(group_opl == group_first->next->next->next);
group_first = group_opl; group_first = group_opl;
group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterComma); group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterComma);
TestResult(MD_S8Match(group_first->string, MD_S8Lit("d"), 0)); test_result(MD_S8Match(group_first->string, MD_S8Lit("d"), 0));
TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("e"), 0)); test_result(MD_S8Match(group_first->next->string, MD_S8Lit("e"), 0));
TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("f"), 0)); test_result(MD_S8Match(group_first->next->next->string, MD_S8Lit("f"), 0));
TestResult(group_opl == group_first->next->next->next); test_result(group_opl == group_first->next->next->next);
group_first = group_opl; group_first = group_opl;
group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterComma); group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterComma);
TestResult(MD_S8Match(group_first->string, MD_S8Lit("g"), 0)); test_result(MD_S8Match(group_first->string, MD_S8Lit("g"), 0));
TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("h"), 0)); test_result(MD_S8Match(group_first->next->string, MD_S8Lit("h"), 0));
TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("i"), 0)); test_result(MD_S8Match(group_first->next->next->string, MD_S8Lit("i"), 0));
TestResult(group_opl == group_first->next->next->next); test_result(group_opl == group_first->next->next->next);
} }
} }
@@ -613,57 +619,57 @@ int main(void)
MD_PushChild(tree, a); MD_PushChild(tree, a);
MD_PushChild(tree, d); MD_PushChild(tree, d);
ParseResult result = MD_ParseWholeString(arena, file_name, text); ParseResult result = MD_ParseWholeString(arena, file_name, text);
TestResult(result.errors.first == 0); test_result(result.errors.first == 0);
TestResult(MD_NodeDeepMatch(tree, result.node, 0)); test_result(MD_NodeDeepMatch(tree, result.node, 0));
} }
// finished unscoped set // finished unscoped set
{ {
MD_String8 text = MD_S8Lit("a:\nb:\nc"); MD_String8 text = MD_S8Lit("a:\nb:\nc");
ParseResult result = MD_ParseWholeString(arena, file_name, text); ParseResult result = MD_ParseWholeString(arena, file_name, text);
TestResult(result.errors.first == 0); test_result(result.errors.first == 0);
TestResult(result.node->first_child == result.node->last_child); test_result(result.node->first_child == result.node->last_child);
} }
// unfinished unscoped set // unfinished unscoped set
{ {
MD_String8 text = MD_S8Lit("a:\nb:\n\n"); MD_String8 text = MD_S8Lit("a:\nb:\n\n");
ParseResult result = MD_ParseWholeString(arena, file_name, text); ParseResult result = MD_ParseWholeString(arena, file_name, text);
TestResult(result.errors.first != 0); test_result(result.errors.first != 0);
} }
{ {
MD_String8 text = MD_S8Lit("a:\nb:\n"); MD_String8 text = MD_S8Lit("a:\nb:\n");
ParseResult result = MD_ParseWholeString(arena, file_name, text); ParseResult result = MD_ParseWholeString(arena, file_name, text);
TestResult(result.errors.first != 0); test_result(result.errors.first != 0);
} }
{ {
MD_String8 text = MD_S8Lit("a:\nb:"); MD_String8 text = MD_S8Lit("a:\nb:");
ParseResult result = MD_ParseWholeString(arena, file_name, text); ParseResult result = MD_ParseWholeString(arena, file_name, text);
TestResult(result.errors.first != 0); test_result(result.errors.first != 0);
} }
// labeled scoped set in unscoped set // labeled scoped set in unscoped set
{ {
MD_String8 text = MD_S8Lit("a: b: {\nx\n} c"); MD_String8 text = MD_S8Lit("a: b: {\nx\n} c");
ParseResult result = MD_ParseWholeString(arena, file_name, text); ParseResult result = MD_ParseWholeString(arena, file_name, text);
TestResult(result.errors.first == 0); test_result(result.errors.first == 0);
TestResult(MD_ChildCountFromNode(result.node) == 1); test_result(MD_ChildCountFromNode(result.node) == 1);
TestResult(MD_ChildCountFromNode(result.node->first_child) == 2); test_result(MD_ChildCountFromNode(result.node->first_child) == 2);
} }
{ {
MD_String8 text = MD_S8Lit("a: b: {\nx\n}\nc"); MD_String8 text = MD_S8Lit("a: b: {\nx\n}\nc");
ParseResult result = MD_ParseWholeString(arena, file_name, text); ParseResult result = MD_ParseWholeString(arena, file_name, text);
TestResult(result.errors.first == 0); test_result(result.errors.first == 0);
TestResult(MD_ChildCountFromNode(result.node) == 2); test_result(MD_ChildCountFromNode(result.node) == 2);
TestResult(MD_ChildCountFromNode(result.node->first_child) == 1); test_result(MD_ChildCountFromNode(result.node->first_child) == 1);
} }
// scoped set is not unscoped // scoped set is not unscoped
{ {
MD_String8 text = MD_S8Lit("a: {\nx\ny\n} c"); MD_String8 text = MD_S8Lit("a: {\nx\ny\n} c");
ParseResult result = MD_ParseWholeString(arena, file_name, text); ParseResult result = MD_ParseWholeString(arena, file_name, text);
TestResult(result.errors.first == 0); test_result(result.errors.first == 0);
TestResult(result.node->first_child != result.node->last_child); test_result(result.node->first_child != result.node->last_child);
} }
} }
@@ -673,19 +679,19 @@ int main(void)
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@foo bar")); ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@foo bar"));
TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("foo"), 0)); test_result(MD_NodeHasTag(result.node->first_child, MD_S8Lit("foo"), 0));
} }
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@+ bar")); ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@+ bar"));
TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("+"), 0)); test_result(MD_NodeHasTag(result.node->first_child, MD_S8Lit("+"), 0));
} }
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@'a b c' bar")); ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@'a b c' bar"));
TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("a b c"), 0)); test_result(MD_NodeHasTag(result.node->first_child, MD_S8Lit("a b c"), 0));
} }
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@100 bar")); ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@100 bar"));
TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("100"), 0)); test_result(MD_NodeHasTag(result.node->first_child, MD_S8Lit("100"), 0));
} }
} }
@@ -696,27 +702,27 @@ int main(void)
// tagged in scoped set always legal // tagged in scoped set always legal
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:{@tag {bar}}\n")); ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:{@tag {bar}}\n"));
TestResult(result.errors.first == 0); test_result(result.errors.first == 0);
} }
// tagged label in unscoped set legal // tagged label in unscoped set legal
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:@tag bar\n")); ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:@tag bar\n"));
TestResult(result.errors.first == 0); test_result(result.errors.first == 0);
} }
// unlabeled scoped set in unscoped set illegal // unlabeled scoped set in unscoped set illegal
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:bar {bar}\n")); ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:bar {bar}\n"));
TestResult(result.errors.first != 0); test_result(result.errors.first != 0);
} }
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:bar @tag {bar}\n")); ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:bar @tag {bar}\n"));
TestResult(result.errors.first != 0); test_result(result.errors.first != 0);
} }
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:@tag {bar}\n")); ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:@tag {bar}\n"));
TestResult(result.errors.first != 0); test_result(result.errors.first != 0);
} }
} }
@@ -735,7 +741,7 @@ int main(void)
for (int i = 0; i < MD_ArrayCount(test_strings); i += 1, string += 1) for (int i = 0; i < MD_ArrayCount(test_strings); i += 1, string += 1)
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, *string); ParseResult result = MD_ParseWholeString(arena, file_name, *string);
TestResult((result.errors.first == 0) && test_result((result.errors.first == 0) &&
(result.node->first_child == result.node->last_child) && (result.node->first_child == result.node->last_child) &&
(result.node->first_child->flags & NodeFlag_Numeric)); (result.node->first_child->flags & NodeFlag_Numeric));
} }
@@ -761,7 +767,7 @@ int main(void)
for (int i = 0; i < MD_ArrayCount(test_strings); i += 1, string += 1) for (int i = 0; i < MD_ArrayCount(test_strings); i += 1, string += 1)
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, *string); ParseResult result = MD_ParseWholeString(arena, file_name, *string);
TestResult((result.errors.first == 0) && test_result((result.errors.first == 0) &&
(result.node->first_child == result.node->last_child) && (result.node->first_child == result.node->last_child) &&
(result.node->first_child->flags & NodeFlag_Numeric)); (result.node->first_child->flags & NodeFlag_Numeric));
} }
@@ -774,26 +780,26 @@ int main(void)
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, ParseResult result = MD_ParseWholeString(arena, file_name,
MD_S8Lit("foo: '(' )")); MD_S8Lit("foo: '(' )"));
TestResult(result.errors.first != 0); test_result(result.errors.first != 0);
} }
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, ParseResult result = MD_ParseWholeString(arena, file_name,
MD_S8Lit("foo ':' ( )")); MD_S8Lit("foo ':' ( )"));
TestResult(result.errors.first == 0); test_result(result.errors.first == 0);
TestResult(MD_ChildCountFromNode(result.node) == 3); test_result(MD_ChildCountFromNode(result.node) == 3);
} }
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, ParseResult result = MD_ParseWholeString(arena, file_name,
MD_S8Lit("'@'bar foo")); MD_S8Lit("'@'bar foo"));
TestResult(result.errors.first == 0); test_result(result.errors.first == 0);
TestResult(MD_ChildCountFromNode(result.node) == 3); test_result(MD_ChildCountFromNode(result.node) == 3);
} }
{ {
ParseResult result = MD_ParseWholeString(arena, file_name, ParseResult result = MD_ParseWholeString(arena, file_name,
MD_S8Lit("foo: '(' ')'")); MD_S8Lit("foo: '(' ')'"));
TestResult(result.errors.first == 0); test_result(result.errors.first == 0);
TestResult(MD_ChildCountFromNode(result.node) == 1); test_result(MD_ChildCountFromNode(result.node) == 1);
TestResult(MD_ChildCountFromNode(result.node->first_child) == 2); test_result(MD_ChildCountFromNode(result.node->first_child) == 2);
} }
} }
@@ -807,7 +813,7 @@ int main(void)
MD_DebugDumpFromNode(arena, &actual_strings, parse.node, MD_DebugDumpFromNode(arena, &actual_strings, parse.node,
0, MD_S8Lit(" "), MD_GenerateFlags_Tree); 0, MD_S8Lit(" "), MD_GenerateFlags_Tree);
MD_String8 actual = MD_S8ListJoin(arena, actual_strings, 0); MD_String8 actual = MD_S8ListJoin(arena, actual_strings, 0);
TestResult(MD_S8Match(expected, actual, 0)); test_result(MD_S8Match(expected, actual, 0));
} }
{ {
MD_String8 code = MD_S8Lit("@foo(1, 2, 3) a: { x y }"); MD_String8 code = MD_S8Lit("@foo(1, 2, 3) a: { x y }");
@@ -817,7 +823,7 @@ int main(void)
MD_DebugDumpFromNode(arena, &actual_strings, parse.node, MD_DebugDumpFromNode(arena, &actual_strings, parse.node,
0, MD_S8Lit(" "), MD_GenerateFlags_Tree); 0, MD_S8Lit(" "), MD_GenerateFlags_Tree);
MD_String8 actual = MD_S8ListJoin(arena, actual_strings, 0); MD_String8 actual = MD_S8ListJoin(arena, actual_strings, 0);
TestResult(MD_S8Match(expected, actual, 0)); test_result(MD_S8Match(expected, actual, 0));
} }
{ {
MD_String8 code = MD_S8Lit("// foo\na"); MD_String8 code = MD_S8Lit("// foo\na");
@@ -827,7 +833,7 @@ int main(void)
MD_DebugDumpFromNode(arena, &actual_strings, parse.node, 0, MD_S8Lit(" "), MD_DebugDumpFromNode(arena, &actual_strings, parse.node, 0, MD_S8Lit(" "),
MD_GenerateFlags_Tree|MD_GenerateFlag_Comments); MD_GenerateFlags_Tree|MD_GenerateFlag_Comments);
MD_String8 actual = MD_S8ListJoin(arena, actual_strings, 0); MD_String8 actual = MD_S8ListJoin(arena, actual_strings, 0);
TestResult(MD_S8Match(expected, actual, 0)); test_result(MD_S8Match(expected, actual, 0));
} }
{ {
MD_String8 code = MD_S8Lit("@foo @bar @baz a: { b c d e f }"); MD_String8 code = MD_S8Lit("@foo @bar @baz a: { b c d e f }");
@@ -836,7 +842,7 @@ int main(void)
MD_ReconstructionFromNode(arena, &reconstruction_strs, parse1.node, 0, MD_S8Lit(" ")); MD_ReconstructionFromNode(arena, &reconstruction_strs, parse1.node, 0, MD_S8Lit(" "));
MD_String8 reconstruction = MD_S8ListJoin(arena, reconstruction_strs, 0); MD_String8 reconstruction = MD_S8ListJoin(arena, reconstruction_strs, 0);
ParseResult parse2 = MD_ParseOneNode(arena, reconstruction, 0); ParseResult parse2 = MD_ParseOneNode(arena, reconstruction, 0);
TestResult(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags)); test_result(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags));
} }
{ {
MD_String8 code = MD_S8Lit("@foo(x: y: z) @bar(a: b: c) @baz(1: 2: 3) abcdefg: { b: 4, c d: 5; e; f, }"); MD_String8 code = MD_S8Lit("@foo(x: y: z) @bar(a: b: c) @baz(1: 2: 3) abcdefg: { b: 4, c d: 5; e; f, }");
@@ -845,7 +851,7 @@ int main(void)
MD_ReconstructionFromNode(arena, &reconstruction_strs, parse1.node, 0, MD_S8Lit(" ")); MD_ReconstructionFromNode(arena, &reconstruction_strs, parse1.node, 0, MD_S8Lit(" "));
MD_String8 reconstruction = MD_S8ListJoin(arena, reconstruction_strs, 0); MD_String8 reconstruction = MD_S8ListJoin(arena, reconstruction_strs, 0);
ParseResult parse2 = MD_ParseOneNode(arena, reconstruction, 0); ParseResult parse2 = MD_ParseOneNode(arena, reconstruction, 0);
TestResult(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags)); test_result(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags));
} }
{ {
MD_String8 code = MD_S8Lit("@foo(x: y: z)\n" MD_String8 code = MD_S8Lit("@foo(x: y: z)\n"
@@ -864,7 +870,7 @@ int main(void)
MD_ReconstructionFromNode(arena, &reconstruction_strs, parse1.node, 0, MD_S8Lit(" ")); MD_ReconstructionFromNode(arena, &reconstruction_strs, parse1.node, 0, MD_S8Lit(" "));
MD_String8 reconstruction = MD_S8ListJoin(arena, reconstruction_strs, 0); MD_String8 reconstruction = MD_S8ListJoin(arena, reconstruction_strs, 0);
ParseResult parse2 = MD_ParseOneNode(arena, reconstruction, 0); ParseResult parse2 = MD_ParseOneNode(arena, reconstruction, 0);
TestResult(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags)); test_result(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags));
} }
} }