same parser clean up using next_tokens_are
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 3 Feb 2021 04:30:02 +0000 (22:30 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 3 Feb 2021 04:30:02 +0000 (22:30 -0600)
bin/onyx
onyx.exe
src/onyxparser.c

index 820da07d1b8a3aa3ece73cacf38c35c291d8a40b..dd26dece3b4043f70d2ac9a162a47005d9a25cc0 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 2493bbfd15ade518240630170fa367dbcbda4dec..c19b02d97a8a44e804c46c2d6c1e7dc3f4e256a7 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index bb8899c9bf97f7f745b7aa2443e42ea5b285ae60..7e834a3d446c1e0fee69ff6b69002bbd8c94a231 100644 (file)
@@ -217,7 +217,7 @@ static b32 parse_possible_directive(OnyxParser* parser, const char* dir) {
 }
 
 static b32 parse_possible_struct_literal(OnyxParser* parser, AstTyped* left, AstTyped** ret) {
-    if (parser->curr->type != '.' || peek_token(1)->type != '{') return 0;
+    if (!next_tokens_are(parser, 2, '.', '{')) return 0;
 
     AstStructLiteral* sl = make_node(AstStructLiteral, Ast_Kind_Struct_Literal);
     sl->token = parser->curr;
@@ -235,7 +235,7 @@ static b32 parse_possible_struct_literal(OnyxParser* parser, AstTyped* left, Ast
 }
 
 static b32 parse_possible_array_literal(OnyxParser* parser, AstTyped* left, AstTyped** ret) {
-    if (parser->curr->type != '.' || peek_token(1)->type != '[') return 0;
+    if (!next_tokens_are(parser, 2, '.', '[')) return 0;
     
     AstArrayLiteral* al = make_node(AstArrayLiteral, Ast_Kind_Array_Literal);
     al->token = parser->curr;
@@ -262,7 +262,7 @@ static void parse_arguments(OnyxParser* parser, TokenType end_token, Arguments*
     while (!consume_token_if_next(parser, end_token)) {
         if (parser->hit_unexpected_token) return;
 
-        if (peek_token(0)->type == Token_Type_Symbol && peek_token(1)->type == '=') {
+        if (next_tokens_are(parser, 2, Token_Type_Symbol, '=')) {
             OnyxToken* name = expect_token(parser, Token_Type_Symbol);
             expect_token(parser, '=');
 
@@ -1435,10 +1435,7 @@ static AstType* parse_function_type(OnyxParser* parser, OnyxToken* proc_token) {
         if (parser->hit_unexpected_token) return NULL;
 
         // NOTE: Allows for names to be put in the function types, just for readability.
-        if (peek_token(1)->type == ':') {
-            expect_token(parser, Token_Type_Symbol);
-            expect_token(parser, ':');
-        }
+        if (next_tokens_are(parser, 2, Token_Type_Symbol, ':')) consume_tokens(parser, 2);
 
         AstType* param_type = parse_type(parser);
         bh_arr_push(params, param_type);