else if into elif

This commit is contained in:
Krzosa Karol
2022-06-14 21:25:02 +02:00
parent 44ee0f4351
commit 58e919ef69
3 changed files with 13 additions and 7 deletions

View File

@@ -163,6 +163,7 @@ Intern_String keyword_true;
Intern_String keyword_false; Intern_String keyword_false;
Intern_String keyword_for; Intern_String keyword_for;
Intern_String keyword_pass; Intern_String keyword_pass;
Intern_String keyword_elif;
Intern_String keyword_sizeof; Intern_String keyword_sizeof;
Intern_String keyword_alignof; Intern_String keyword_alignof;
Intern_String keyword_lengthof; Intern_String keyword_lengthof;
@@ -211,6 +212,7 @@ lex_init(Allocator *token_string_arena, Allocator *map_allocator, Lexer *l){
keyword_false = l->intern("false"_s); keyword_false = l->intern("false"_s);
keyword_return = l->intern("return"_s); keyword_return = l->intern("return"_s);
keyword_if = l->intern("if"_s); keyword_if = l->intern("if"_s);
keyword_elif = l->intern("elif"_s);
keyword_pass = l->intern("pass"_s); keyword_pass = l->intern("pass"_s);
keyword_else = l->intern("else"_s); keyword_else = l->intern("else"_s);
keyword_for = l->intern("for"_s); keyword_for = l->intern("for"_s);

View File

@@ -42,15 +42,12 @@ want to export all the symbols, we can namespace them optionally.
@todo @todo
[ ] - Fix field access, cant cast, cant index [ ] - Fix field access, cant cast, cant index
[ ] - Fix codegen renames
[ ] - Add parent_scope to Ast_Type [ ] - Add parent_scope to Ast_Type
[ ] - Should compound resolution use an algorithm to reorder compounds to initialize all fields in order [ ] - Should compound resolution use an algorithm to reorder compounds to initialize all fields in order
[ ] - Switch [ ] - Switch
[ ] - Add c string
[ ] - Some way to take slice of data [ ] - Some way to take slice of data
[ ] - slices should be properly displayed in debugger
[ ] - elif [ ] - elif
[ ] - Imports inside of import shouldn't spill outside [ ] - Optional function renaming
[ ] - #assert that handles constants at compile time and vars at runtime [ ] - #assert that handles constants at compile time and vars at runtime
[ ] - Comma notation when declaring variables thing1, thing2: S32 [ ] - Comma notation when declaring variables thing1, thing2: S32
@@ -75,11 +72,15 @@ want to export all the symbols, we can namespace them optionally.
[ ] - Conditional compilation #if [ ] - Conditional compilation #if
@donzo @donzo
[x] - Add c string
[x] - slices should be properly displayed in debugger
[x] - Imports inside of import shouldn't spill outside
[x] - Scope [x] - Scope
[x] - Hex 0x42 [x] - Hex 0x42
[x] - Rewrite where # happen, [x] - Rewrite where # happen,
[x] - cast -> [x] - cast ->
[x] - Remodel compound from call to {} [x] - Remodel compound from call to {}
[x] - Fix codegen renames
[x] - Field access rewrite [x] - Field access rewrite
[-] - Constants embeded in structs should be able to refer to other constants in that namespace without prefix [-] - Constants embeded in structs should be able to refer to other constants in that namespace without prefix
[-] - Order independent constants in structs [-] - Order independent constants in structs

View File

@@ -264,16 +264,19 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
Ast_If_Node *if_node = ast_if_node(token, init_val, expr, if_block); Ast_If_Node *if_node = ast_if_node(token, init_val, expr, if_block);
if_nodes.add(if_node); if_nodes.add(if_node);
while(token_is(SAME_SCOPE) && token_is_keyword(keyword_else, 1)){ while(token_is(SAME_SCOPE) && (token_is_keyword(keyword_elif, 1) || (token_is_keyword(keyword_else, 1)))){
token_next(); token_next();
token = token_next(); token = token_get();
if(token_match_keyword(keyword_if)){ if(token_match_keyword(keyword_elif)){
assert(token->intern_val == keyword_elif);
Ast_Expr *expr = parse_expr(); Ast_Expr *expr = parse_expr();
Ast_Scope *else_if_block = parse_stmt_scope(); Ast_Scope *else_if_block = parse_stmt_scope();
Ast_If_Node *if_node = ast_if_node(token, 0, expr, else_if_block); Ast_If_Node *if_node = ast_if_node(token, 0, expr, else_if_block);
if_nodes.add(if_node); if_nodes.add(if_node);
} }
else{ else{
token_match_keyword(keyword_else);
assert(token->intern_val == keyword_else);
Ast_Scope *else_block = parse_stmt_scope(); Ast_Scope *else_block = parse_stmt_scope();
Ast_If_Node *if_node = ast_if_node(token, 0, 0, else_block); Ast_If_Node *if_node = ast_if_node(token, 0, 0, else_block);
if_nodes.add(if_node); if_nodes.add(if_node);