diff options
-rw-r--r-- | out.c | 7 | ||||
-rw-r--r-- | parse.c | 44 | ||||
-rw-r--r-- | test.toc | 5 |
3 files changed, 38 insertions, 18 deletions
@@ -2,10 +2,3 @@ /* toc */ void main__(void) { - int64_t salkdfj = 0; float something = 0; int64_t baz = 0; int64_t bar = 0; int64_t foo = 0; -} - -int main(void) { - main__(); - return 0; -} @@ -414,7 +414,7 @@ static bool parse_type(Parser *p, Type *type) { type->builtin = kw_to_builtin_type(t->token->kw); if (type->builtin != BUILTIN_TYPE_COUNT) { t->token++; - return true; + break; } /* Not a builtin */ switch (t->token->kw) { @@ -444,17 +444,18 @@ static bool parse_type(Parser *p, Type *type) { } t->token++; /* move past ) */ Type *ret_type = type->fn.types.data; - /* if there's a symbol that isn't [, that can't be the start of a type */ + /* if there's a symbol that isn't [ or (, that can't be the start of a type */ if (t->token->kind == TOKEN_KW && t->token->kw <= KW_LAST_SYMBOL - && t->token->kw != KW_LSQUARE) { + && t->token->kw != KW_LSQUARE + && t->token->kw != KW_LPAREN) { ret_type->kind = TYPE_VOID; ret_type->flags = 0; } else { if (!parse_type(p, ret_type)) return false; } - return true; + break; } case KW_LSQUARE: { /* array type */ @@ -469,15 +470,40 @@ static bool parse_type(Parser *p, Type *type) { if (!parse_type(p, type->arr.of)) return false; type->flags = 0; type->where = start->where; - return true; + break; } - default: break; + case KW_LPAREN: + /* tuple! */ + type->kind = TYPE_TUPLE; + arr_create(&type->tuple, sizeof(Type)); + t->token++; /* move past ( */ + while (1) { + Type *child = arr_add(&type->tuple); + parse_type(p, child); + if (token_is_kw(t->token, KW_RPAREN)) { /* we're done with the tuple */ + t->token++; /* move past ) */ + break; + } + if (token_is_kw(t->token, KW_COMMA)) { + t->token++; /* move past , */ + continue; + } else { + tokr_err(t, "Expected , to list next tuple type or ) to end tuple type."); + return false; + } + } + break; + default: + tokr_err(t, "Unrecognized type."); + return false; } break; - default: break; + default: + tokr_err(t, "Unrecognized type."); + return false; } - tokr_err(t, "Unrecognized type."); - return false; + return true; + } static bool parse_param(Parser *parser, Param *p) { @@ -1,3 +1,4 @@ -main @= fn() { - foo, bar, baz : int, something : float, salkdfj : int; +main @ fn() = fn() { + asdkofhj : fn() (int, int); + foo, bar, baz : int, something : float, salkdfj : int= 2, 2, 2, 2, 2; }; |