From b8211cda90f8a9cb14657d3328cfa9ec78722c5c Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 30 Mar 2023 21:13:47 +0300 Subject: change to left-to-right resolver --- src/parser.y | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/parser.y') diff --git a/src/parser.y b/src/parser.y index 50edf13..329e072 100644 --- a/src/parser.y +++ b/src/parser.y @@ -80,7 +80,7 @@ %token PUB "pub" %token STRUCT "struct" %token UNION "union" -%token TYPEDEF "type" +%token TYPEDEF "typedef" %token IMPORT "import" %token DEFER "defer" %token GOTO "goto" @@ -111,6 +111,7 @@ %token SCOPE "::" %token FATARROW "=>" +%right "[" "]" /* precedence */ %left "," %right "=" "+=" "-=" "*=" "/=" "%=" "<<=" ">>=" "&=" "^=" "|=" "^^=" @@ -464,6 +465,9 @@ type: id { $$ = gen_type(AST_TYPE_ID, $1, NULL, NULL); } | "typeof" expr { $$ = gen_type(AST_TYPE_TYPEOF, NULL, $2, NULL); } + | id "::" type { + $$ = gen_type(AST_TYPE_MEMBER, $1, $3, NULL); + } ; var_decl: id "mut" type { @@ -542,15 +546,15 @@ type_list: type "," type_list { $$ = $1; $1->next = $3; } | type { $$ = $1; } ; -type_alias: "type" id type { $$ = gen_alias($2, $3); } +type_alias: "typedef" id type { $$ = gen_alias($2, $3); } ; /* we'll parse the arg list later in the AST and check that each node is of some * specific type */ -type_template: "type" id "{" template_list "}" { +type_template: "typedef" id "{" template_list "}" { $$ = gen_template($2, $4); } - | "type" id "{" "}" { + | "typedef" id "{" "}" { /* should match anything, but doesn't implement anything */ $$ = gen_template($2, NULL); } -- cgit v1.3