diff --git a/docs/md_docs.mc b/docs/md_docs.mc index 9252cc1..e050ef6 100644 --- a/docs/md_docs.mc +++ b/docs/md_docs.mc @@ -55,8 +55,8 @@ @enum MD_NodeKind: { Nil, File, + Namespace, Label, - UnnamedSet, Tag, MAX, }; @@ -108,6 +108,10 @@ whole_string: MD_String8, string_hash: MD_u64, + // Comments. + comment_before: MD_String8, + comment_after: MD_String8, + // Source code location information. filename: MD_String8, file_contents: *MD_u8, @@ -118,36 +122,36 @@ //~ Code Location Info. @struct MD_CodeLoc: { - filename: MD_String8, - line: MD_u32, - column: MD_u32, + filename: MD_String8, + line: MD_u32, + column: MD_u32, }; //////////////////////////////// -//~ Warning Levels +//~ Message Levels @enum MD_MessageKind: { - Error, - Warning, + Error, + Warning, } //////////////////////////////// //~ String-To-Node table @enum MD_NodeTableCollisionRule: { - Chain, - Overwrite, + Chain, + Overwrite, } @struct MD_NodeTableSlot: { - next: *MD_NodeTableSlot, - hash: MD_u64, - node: *MD_Node, + next: *MD_NodeTableSlot, + hash: MD_u64, + node: *MD_Node, }; @struct MD_NodeTable: { - table_size: MD_u64, - table: **MD_NodeTableSlot, + table_size: MD_u64, + table: **MD_NodeTableSlot, }; //////////////////////////////// @@ -194,6 +198,8 @@ Newline, WhitespaceMax, + MD_TokenKind_NonASCII, + MAX, }; @@ -215,40 +221,40 @@ //~ Parsing State @struct MD_Error: { - next: *MD_Error; - string: MD_String8; - filename: MD_String8; - node: *MD_Node; + next: *MD_Error, + string: MD_String8, + filename: MD_String8, + node: *MD_Node, + catastrophic: MD_b32, + location: MD_CodeLoc, }; @struct MD_ParseCtx: { - first_root: *MD_Node, - last_root: *MD_Node, - first_error: *MD_Error, - last-error: *MD_Error, - at: *MD_u8, - filename: MD_String8, - file_contents: MD_String8, + first_root: *MD_Node, + last_root: *MD_Node, + first_error: *MD_Error, + last_error: *MD_Error, + at: *MD_u8, + filename: MD_String8, + file_contents: MD_String8, + namespace_table: MD_NodeTable, + selected_namespace: *MD_Node, + catastrophic_error: MD_b32, }; @struct MD_ParseResult: { - node: *MD_Node; - first_error: *MD_Error; - bytes_parse: MD_u64; + node: *MD_Node; + first_error: *MD_Error; + bytes_parse: MD_u64; }; //////////////////////////////// //~ Expression and Type-Expression parser helper types. -@enum MD_ExprKind: { - // VERY_IMPORTANT_NOTE(rjf): If this enum is ever changed, ensure that - // it is kept in-sync with the MD_ExprPrecFromExprKind and the following - // functions: - // - // MD_BinaryExprKindFromNode - // MD_PreUnaryExprKindFromNode - // MD_PostUnaryExprKindFromNode +// VERY_IMPORTANT_NOTE(rjf): If this enum is ever changed, ensure that +// it is kept in-sync with the MD_ExprPrecFromExprKind function. +@enum MD_ExprKind: { Nil, // NOTE(rjf): Atom @@ -296,9 +302,11 @@ // NOTE(rjf): Type Pointer, Array, - + Volatile, + Const, + MAX, -} +}; @typedef(MD_i32) MD_ExprPrec; @@ -326,16 +334,14 @@ Directory, }; - @struct MD_FileInfo: { flags: MD_FileFlags; filename: MD_String8; file_size: MD_u64; }; -@struct MD_FileIter: { - state: MD_u64, -}; +@opaque +@struct MD_FileIter: {}; //////////////////////////////// //~ Basic Utilities @@ -344,6 +350,10 @@ c, }; +@macro MD_StaticAssert: { + c, +}; + @macro MD_ArrayCount: { a, }; @@ -376,6 +386,11 @@ return: MD_b32, }; +@func MD_CharIsReservedSymbol: { + c: MD_u8, + return: MD_b32, +}; + @func MD_CharIsSpace: { c: MD_u8, return: MD_b32, @@ -493,18 +508,18 @@ }; -@func MD_String8 MD_PushStringCopy: { +@func MD_PushStringCopy: { string: MD_String8, return: MD_String8, }; -@func MD_String8 MD_PushStringFV: { +@func MD_PushStringFV: { fmt: *char, args: va_list, return: MD_String8, }; -@func MD_String8 MD_PushStringF: { +@func MD_PushStringF: { fmt: *char, "...", return: MD_String8, @@ -719,12 +734,12 @@ @func MD_ParseWholeString: { filename: MD_String8, contents: MD_String8, - return: *MD_Node, + return: MD_ParseResult, }; @func MD_ParseWholeFile: { filename: MD_String8, - return: *MD_Node, + return: MD_ParseResult, }; //////////////////////////////// @@ -781,7 +796,7 @@ first: *MD_Node, last: *MD_Node, string: MD_String8, - return: MD_Node, + return: *MD_Node, }; @func MD_NodeFromIndex: { @@ -854,20 +869,6 @@ return: MD_i64, }; -@func MD_ChildCountFromNodeAndString: { - node: *MD_Node, - string: MD_String8, - flags: MD_StringMatchFlags, - return: MD_i64, -}; - -@func MD_TagCountFromNodeAndString: { - node: *MD_Node, - string: MD_String8, - flags: MD_StringMatchFlags, - return: MD_i64, -}; - @macro MD_EachNode: { it, first, }; //////////////////////////////// @@ -984,11 +985,6 @@ node: *MD_Node, }; -@func MD_OutputExpr: { - file: *FILE, - expr: *MD_Expr, -}; - //////////////////////////////// //~ C Language Generation @@ -1013,6 +1009,21 @@ type: *MD_Expr, }; +@func MD_OutputExpr: { + file: *FILE, + expr: *MD_Expr, +}; + +@func MD_OutputExpr_C: { + file: *FILE, + expr: *MD_Expr, +}; + +@func MD_OutputType: { + file: *FILE, + type: *MD_Expr, +}; + @func MD_OutputType_C_LHS: { file: *FILE, type: *MD_Expr, diff --git a/source/md.h b/source/md.h index 1a3db0e..42e2950 100644 --- a/source/md.h +++ b/source/md.h @@ -621,6 +621,8 @@ struct MD_FileIter #define MD_Assert(c) if (!(c)) { *(volatile MD_u64 *)0 = 0; } #define MD_StaticAssert(c,label) MD_u8 MD_static_assert_##label[(c)?(1):(-1)] #define MD_ArrayCount(a) (sizeof(a) / sizeof((a)[0])) + +//~ Characters MD_FUNCTION MD_b32 MD_CharIsAlpha(MD_u8 c); MD_FUNCTION MD_b32 MD_CharIsAlphaUpper(MD_u8 c); MD_FUNCTION MD_b32 MD_CharIsAlphaLower(MD_u8 c); @@ -698,7 +700,6 @@ MD_FUNCTION MD_NodeTableSlot *MD_NodeTable_Lookup(MD_NodeTable *table, MD_String MD_FUNCTION MD_b32 MD_NodeTable_Insert(MD_NodeTable *table, MD_NodeTableCollisionRule collision_rule, MD_String8 string, MD_Node *node); //~ Parsing -MD_FUNCTION MD_Token MD_ZeroToken(void); MD_FUNCTION MD_b32 MD_TokenKindIsWhitespace(MD_TokenKind kind); MD_FUNCTION MD_b32 MD_TokenKindIsComment(MD_TokenKind kind); MD_FUNCTION MD_b32 MD_TokenKindIsRegular(MD_TokenKind kind); @@ -738,17 +739,12 @@ MD_FUNCTION MD_b32 MD_NodeHasTag(MD_Node *node, MD_String8 tag_string); MD_FUNCTION MD_CodeLoc MD_CodeLocFromNode(MD_Node *node); MD_FUNCTION MD_i64 MD_ChildCountFromNode(MD_Node *node); MD_FUNCTION MD_i64 MD_TagCountFromNode(MD_Node *node); -MD_FUNCTION MD_i64 MD_ChildCountFromNodeAndString(MD_Node *node, MD_String8 string, MD_StringMatchFlags flags); -MD_FUNCTION MD_i64 MD_TagCountFromNodeAndString(MD_Node *node, MD_String8 string, MD_StringMatchFlags flags); // NOTE(rjf): For-Loop Helper #define MD_EachNode(it, first) MD_Node *it = (first); !MD_NodeIsNil(it); it = it->next //~ Error/Warning Helpers MD_FUNCTION void MD_NodeMessage(MD_Node *node, MD_MessageKind kind, MD_String8 str); -MD_FUNCTION void MD_NodeError(MD_Node *node, MD_String8 str); -MD_FUNCTION void MD_NodeWarning(MD_Node *node, MD_String8 str); MD_FUNCTION void MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...); -MD_FUNCTION void MD_NodeErrorF(MD_Node *node, char *fmt, ...); //~ Tree Comparison/Verification MD_FUNCTION MD_b32 MD_NodeMatch(MD_Node *a, MD_Node *b, MD_StringMatchFlags str_flags, MD_NodeMatchFlags node_flags); @@ -770,6 +766,8 @@ MD_FUNCTION MD_b32 MD_ExprDeepMatch(MD_Expr *a, MD_Expr *b, MD_StringMatc //~ Generation MD_FUNCTION void MD_OutputTree(FILE *file, MD_Node *node); + +//~ C Language Generation MD_FUNCTION void MD_OutputTree_C_String(FILE *file, MD_Node *node); MD_FUNCTION void MD_OutputTree_C_Struct(FILE *file, MD_Node *node); MD_FUNCTION void MD_OutputTree_C_Decl(FILE *file, MD_Node *node); @@ -780,6 +778,7 @@ MD_FUNCTION void MD_OutputType(FILE *file, MD_Expr *expr); MD_FUNCTION void MD_OutputType_C_LHS(FILE *file, MD_Expr *type); MD_FUNCTION void MD_OutputType_C_RHS(FILE *file, MD_Expr *type); +// TODO(allen): needs another pass //~ Command Line Argument Helper MD_FUNCTION MD_CommandLine MD_CommandLine_Start(int argument_count, char **arguments); MD_FUNCTION MD_b32 MD_CommandLine_Flag(MD_CommandLine *cmdln, MD_String8 string); diff --git a/source/md_impl.c b/source/md_impl.c index 9952670..db7147a 100644 --- a/source/md_impl.c +++ b/source/md_impl.c @@ -1028,14 +1028,6 @@ MD_NodeTable_Insert(MD_NodeTable *table, MD_NodeTableCollisionRule collision_rul return !!slot; } -MD_FUNCTION_IMPL MD_Token -MD_ZeroToken(void) -{ - MD_Token token; - _MD_MemoryZero(&token, sizeof(token)); - return token; -} - MD_FUNCTION_IMPL MD_b32 MD_TokenKindIsWhitespace(MD_TokenKind kind) { @@ -2311,18 +2303,6 @@ MD_NodeMessage(MD_Node *node, MD_MessageKind kind, MD_String8 str) MD_StringExpand(str)); } -MD_FUNCTION_IMPL void -MD_NodeError(MD_Node *node, MD_String8 str) -{ - MD_NodeMessage(node, MD_MessageKind_Error, str); -} - -MD_FUNCTION_IMPL void -MD_NodeWarning(MD_Node *node, MD_String8 str) -{ - MD_NodeMessage(node, MD_MessageKind_Warning, str); -} - MD_FUNCTION_IMPL void MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...) { @@ -2332,15 +2312,6 @@ MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...) va_end(args); } -MD_FUNCTION_IMPL void -MD_NodeErrorF(MD_Node *node, char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - MD_NodeError(node, MD_PushStringFV(fmt, args)); - va_end(args); -} - MD_GLOBAL MD_Expr _md_nil_expr = { &_md_nil_node,