Allocator logging
This commit is contained in:
@@ -5,8 +5,11 @@ token_get(S64 i = 0){ Get_Ctx(Parse_Ctx);
|
||||
if(i >= ctx->tokens.len){
|
||||
return &ctx->empty_token;
|
||||
}
|
||||
|
||||
Token *result = &ctx->tokens[i];
|
||||
if(result->kind == TK_NewLine){
|
||||
ctx->indent = result->indent;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -207,25 +210,38 @@ test_parse_expr(){
|
||||
// Parsing declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
function Ast_Decl *
|
||||
parse_decl(){
|
||||
parse_decl(){Get_Ctx(Parse_Ctx);
|
||||
Ast_Decl *result = 0;
|
||||
Token *token = token_match(TK_Identifier);
|
||||
if(token){
|
||||
if(token_match(TK_DoubleColon)){
|
||||
if(token_match_keyword(keyword_const)){
|
||||
Ast_Expr *expr = parse_expr();
|
||||
result = ast_decl_const(token, token->intern_val, expr);
|
||||
}
|
||||
if(token_match(TK_ColonAssign)){
|
||||
if(ctx->indent != 0)
|
||||
parsing_error(token, "Top level declarations shouldn't be indented");
|
||||
|
||||
Ast_Expr *expr = parse_expr();
|
||||
result = ast_decl_var(token, 0, token->intern_val, expr);
|
||||
}
|
||||
else parsing_error(token, "Encountered unexpected token while parsing a top level declarations");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Package *
|
||||
parse_file(){
|
||||
Ast_Package *result = ast_package(token_get(), token_get()->file);
|
||||
while(!token_is(TK_End)){
|
||||
while(token_match(TK_NewLine));
|
||||
Ast_Decl *decl = parse_decl();
|
||||
if(!decl) break;
|
||||
result->decls.add(decl);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function void
|
||||
test_parse_decl(){
|
||||
TEST_PARSER();
|
||||
lex_restream(&ctx, "thing :: const 24252\n"_s, "test_parse_decl"_s);
|
||||
Ast_Decl *result = parse_decl();
|
||||
lex_restream(&ctx, "thing := 24252\nanother_thing := \"string\"\n\nref := thing"_s, "test_parse_decl"_s);
|
||||
Ast_Package *result = parse_file();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user