vn/code/vn_scene.cpp

63 lines
2.0 KiB
C++
Raw Normal View History

2023-07-19 15:09:41 +00:00
////////////////////////////////
//~ sixten: Scene Message Functions
static void S_PushMessage(memory_arena *Arena, scene_message_list *Messages, scene_node *Node, scene_message_type Type, string String)
{
scene_message *Message = PushStruct(Arena, scene_message);
Message->Type = Type;
Message->Node = Node;
Message->String = String;
QueuePush(Messages->First, Messages->Last, Message);
Messages->Count += 1;
}
////////////////////////////////
//~ sixten: Scene Node Functions
static scene_node *S_SceneFromText(memory_arena *Arena, string Filename, string Text)
{
tokenize_result TokenizeResult = T_TokenizeFromText(Arena, Filename, Text, TokenGroup_Comment|TokenGroup_Whitespace);
scene_parse_result ParseResult = S_ParseFromTokens(Arena, Filename, Text, TokenizeResult.Tokens);
scene_node *Result = ParseResult.Root;
return(Result);
}
////////////////////////////////
//~ sixten: Tokens -> Syntax Tree
static scene_parse_result S_ParseFromTokens(memory_arena *Arena, string Filename, string Text, token_array Tokens)
{
temporary_memory Scratch = GetScratch(&Arena, 1);
//scene_node *Root = {};
//- sixten: setup parse context
scene_parse_context Context = {};
{
Context.TokensStart = Tokens.Tokens;
Context.TokensEnd = Context.TokensStart + Tokens.Count;
Context.Token = Context.TokensStart;
}
//- sixten: parse top-level
for(;Context.Token < Context.TokensEnd;)
{
string TokenString = PushString(Scratch.Arena, T_StringFromToken(Text, *Context.Token));
if(T_TokenMatches(*Context.Token, TokenFlag_Identifier, Text, StrLit("proc")))
{
Context.Token += 1;
goto TokenConsumed;
}
//- sixten: token was not consumed, something has gone wrong
{
Context.Token += 1;
}
TokenConsumed:;
}
ReleaseScratch(Scratch);
scene_parse_result Result =
{
0
};
return(Result);
}