mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-06 23:58:48 +00:00
[docs] document node kinds and flags; couple random tweaks
This commit is contained in:
+29
-3
@@ -72,6 +72,7 @@
|
|||||||
//~ Node types that are used to build all ASTs.
|
//~ Node types that are used to build all ASTs.
|
||||||
|
|
||||||
@doc("The basic kinds of nodes in the abstract syntax tree parsed from metadesk.")
|
@doc("The basic kinds of nodes in the abstract syntax tree parsed from metadesk.")
|
||||||
|
@see(MD_Node)
|
||||||
@enum MD_NodeKind: {
|
@enum MD_NodeKind: {
|
||||||
@doc("The Nil node is a unique node representing the lack of information, for example iterating off the end of a list, or up to the parent of a root node results in Nil.")
|
@doc("The Nil node is a unique node representing the lack of information, for example iterating off the end of a list, or up to the parent of a root node results in Nil.")
|
||||||
Nil,
|
Nil,
|
||||||
@@ -79,6 +80,12 @@
|
|||||||
@doc("A File node represents parsed metadesk source text.")
|
@doc("A File node represents parsed metadesk source text.")
|
||||||
File,
|
File,
|
||||||
|
|
||||||
|
@doc("A List node serves as the root of an externally chained list of nodes. It's children are nodes with the MD_NodeKind_Reference kind.")
|
||||||
|
List,
|
||||||
|
|
||||||
|
@doc("A Reference node is an indirection to another node. The node field 'ref_target' contains a pointer to the referenced node. These nodes are typically used for creating externally chained linked lists that gather nodes from a parse tree.")
|
||||||
|
Reference,
|
||||||
|
|
||||||
@doc("A Namespace node represents a namespace created by the '#namespace' reserved keyword.")
|
@doc("A Namespace node represents a namespace created by the '#namespace' reserved keyword.")
|
||||||
Namespace,
|
Namespace,
|
||||||
|
|
||||||
@@ -93,34 +100,51 @@
|
|||||||
MAX,
|
MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@doc("Flags put on nodes to indicate extra information about specific details about the strings that were parsed to create the node.")
|
||||||
|
@see(MD_Node)
|
||||||
|
@see(MD_TokenKind)
|
||||||
@prefix(MD_NodeFlag)
|
@prefix(MD_NodeFlag)
|
||||||
@base_type(MD_u32)
|
@base_type(MD_u32)
|
||||||
@flags MD_NodeFlags: {
|
@flags MD_NodeFlags: {
|
||||||
|
@doc("The node has children in an open/close symbol pair and '(' is the open symbol.")
|
||||||
ParenLeft,
|
ParenLeft,
|
||||||
|
@doc("The node has children in an open/close symbol pair and ')' is the close .")
|
||||||
ParenRight,
|
ParenRight,
|
||||||
|
@doc("The node has children in an open/close symbol pair and '[' is the open symbol.")
|
||||||
BracketLeft,
|
BracketLeft,
|
||||||
|
@doc("The node has children in an open/close symbol pair and ']' is the close symbol.")
|
||||||
BracketRight,
|
BracketRight,
|
||||||
|
@doc("The node has children in an open/close symbol pair and '{' is the close symbol.")
|
||||||
BraceLeft,
|
BraceLeft,
|
||||||
|
@doc("The node has children in an open/close symbol pair and '}' is the close symbol.")
|
||||||
BraceRight,
|
BraceRight,
|
||||||
|
|
||||||
|
@doc("The delimiter between this node and it's next sibling is a ';'")
|
||||||
BeforeSemicolon,
|
BeforeSemicolon,
|
||||||
|
@doc("The delimiter between this node and it's next sibling is a ','")
|
||||||
BeforeComma,
|
BeforeComma,
|
||||||
|
|
||||||
|
@doc("The delimiter between this node and it's previous sibling is a ';'")
|
||||||
AfterSemicolon,
|
AfterSemicolon,
|
||||||
|
@doc("The delimiter between this node and it's previous sibling is a ','")
|
||||||
AfterComma,
|
AfterComma,
|
||||||
|
|
||||||
|
@doc("The label on this node comes from a token with the MD_TokenKind_NumericLiteral kind.")
|
||||||
Numeric,
|
Numeric,
|
||||||
|
@doc("The label on this node comes from a token with the MD_TokenKind_Identifier kind.")
|
||||||
Identifier,
|
Identifier,
|
||||||
|
@doc("The label on this node comes from a token with the MD_TokenKind_StringLiteral kind.")
|
||||||
StringLiteral,
|
StringLiteral,
|
||||||
|
@doc("The label on this node comes from a token with the MD_TokenKind_CharLiteral kind.")
|
||||||
CharLiteral,
|
CharLiteral,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@doc("")
|
||||||
@prefix(MD_NodeMatchFlag)
|
@prefix(MD_NodeMatchFlag)
|
||||||
@base_type(MD_u32)
|
@base_type(MD_u32)
|
||||||
@flags MD_NodeMatchFlags: {
|
@flags MD_NodeMatchFlags: {
|
||||||
MD_NodeMatchFlag_Tags,
|
Tags,
|
||||||
|
TagArguments,
|
||||||
MD_NodeMatchFlag_TagArguments,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@struct MD_Node: {
|
@struct MD_Node: {
|
||||||
@@ -140,6 +164,7 @@
|
|||||||
string: MD_String8,
|
string: MD_String8,
|
||||||
whole_string: MD_String8,
|
whole_string: MD_String8,
|
||||||
string_hash: MD_u64,
|
string_hash: MD_u64,
|
||||||
|
ref_target: *MD_Node,
|
||||||
|
|
||||||
// Comments.
|
// Comments.
|
||||||
comment_before: MD_String8,
|
comment_before: MD_String8,
|
||||||
@@ -167,6 +192,7 @@
|
|||||||
None,
|
None,
|
||||||
Warning,
|
Warning,
|
||||||
Error,
|
Error,
|
||||||
|
CatastrophicError,
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
+13
-15
@@ -1644,38 +1644,36 @@ MD_PRIVATE_FUNCTION_IMPL MD_ParseResult _MD_ParseOneNode(MD_ParseCtx *ctx);
|
|||||||
MD_PRIVATE_FUNCTION_IMPL void _MD_ParseSet(MD_ParseCtx *ctx, MD_Node *parent, _MD_ParseSetFlags flags, MD_Node **first_out, MD_Node **last_out);
|
MD_PRIVATE_FUNCTION_IMPL void _MD_ParseSet(MD_ParseCtx *ctx, MD_Node *parent, _MD_ParseSetFlags flags, MD_Node **first_out, MD_Node **last_out);
|
||||||
MD_PRIVATE_FUNCTION_IMPL void _MD_ParseTagList(MD_ParseCtx *ctx, MD_Node **first_out, MD_Node **last_out);
|
MD_PRIVATE_FUNCTION_IMPL void _MD_ParseTagList(MD_ParseCtx *ctx, MD_Node **first_out, MD_Node **last_out);
|
||||||
|
|
||||||
MD_PRIVATE_FUNCTION_IMPL void
|
MD_PRIVATE_FUNCTION_IMPL MD_NodeFlags
|
||||||
_MD_SetNodeFlagsByToken(MD_Node *node, MD_Token token)
|
_MD_NodeFlagsFromTokenKind(MD_TokenKind kind)
|
||||||
{
|
{
|
||||||
#define Flag(_kind, _flag) if(token.kind == _kind) { node->flags |= _flag; }
|
MD_NodeFlags result = 0;
|
||||||
Flag(MD_TokenKind_Identifier, MD_NodeFlag_Identifier);
|
switch (kind){
|
||||||
Flag(MD_TokenKind_NumericLiteral, MD_NodeFlag_Numeric);
|
case MD_TokenKind_Identifier: result = MD_NodeFlag_Identifier; break;
|
||||||
Flag(MD_TokenKind_StringLiteral, MD_NodeFlag_StringLiteral);
|
case MD_TokenKind_NumericLiteral: result = MD_NodeFlag_Numeric; break;
|
||||||
Flag(MD_TokenKind_CharLiteral, MD_NodeFlag_CharLiteral);
|
case MD_TokenKind_StringLiteral: result = MD_NodeFlag_StringLiteral; break;
|
||||||
#undef Flag
|
case MD_TokenKind_CharLiteral: result = MD_NodeFlag_CharLiteral; break;
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
MD_PRIVATE_FUNCTION_IMPL MD_b32
|
MD_PRIVATE_FUNCTION_IMPL MD_b32
|
||||||
_MD_StringLiteralIsBalanced(MD_Token token)
|
_MD_StringLiteralIsBalanced(MD_Token token)
|
||||||
{
|
{
|
||||||
MD_b32 result = 0;
|
|
||||||
MD_u64 front_len = token.string.str - token.outer_string.str;
|
MD_u64 front_len = token.string.str - token.outer_string.str;
|
||||||
MD_u64 back_len = (token.outer_string.str + token.outer_string.size) - (token.string.str + token.string.size);
|
MD_u64 back_len = (token.outer_string.str + token.outer_string.size) - (token.string.str + token.string.size);
|
||||||
result = (front_len == back_len);
|
MD_b32 result = (front_len == back_len);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
MD_PRIVATE_FUNCTION_IMPL MD_b32
|
MD_PRIVATE_FUNCTION_IMPL MD_b32
|
||||||
_MD_CommentIsSyntacticallyCorrect(MD_Token comment_token)
|
_MD_CommentIsSyntacticallyCorrect(MD_Token comment_token)
|
||||||
{
|
{
|
||||||
|
|
||||||
MD_b32 result = 1;
|
|
||||||
|
|
||||||
MD_String8 inner = comment_token.string;
|
MD_String8 inner = comment_token.string;
|
||||||
MD_String8 outer = comment_token.outer_string;
|
MD_String8 outer = comment_token.outer_string;
|
||||||
MD_b32 incorrect = (MD_StringMatch(MD_StringPrefix(outer, 2), MD_S8Lit("/*"), 0) && // C-style comment
|
MD_b32 incorrect = (MD_StringMatch(MD_StringPrefix(outer, 2), MD_S8Lit("/*"), 0) && // C-style comment
|
||||||
(inner.str != outer.str + 2 || inner.str + inner.size != outer.str + outer.size - 2)); // Internally unbalanced
|
(inner.str != outer.str + 2 || inner.str + inner.size != outer.str + outer.size - 2)); // Internally unbalanced
|
||||||
result = !incorrect;
|
MD_b32 result = !incorrect;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1768,7 +1766,7 @@ _MD_ParseOneNode(MD_ParseCtx *ctx)
|
|||||||
{
|
{
|
||||||
result.node = MD_MakeNodeFromToken(MD_NodeKind_Label, ctx->filename, ctx->file_contents.str,
|
result.node = MD_MakeNodeFromToken(MD_NodeKind_Label, ctx->filename, ctx->file_contents.str,
|
||||||
token.outer_string.str, token);
|
token.outer_string.str, token);
|
||||||
_MD_SetNodeFlagsByToken(result.node, token);
|
result.node->flags |= _MD_NodeFlagsFromTokenKind(token.kind);
|
||||||
|
|
||||||
if(token.kind == MD_TokenKind_CharLiteral || token.kind == MD_TokenKind_StringLiteral)
|
if(token.kind == MD_TokenKind_CharLiteral || token.kind == MD_TokenKind_StringLiteral)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user