Adjust grammar to allow for broader range of type inputs.

This commit is contained in:
Danila Fedorin 2020-04-13 23:17:34 -07:00
parent 98c1b5a3b2
commit b4c91d2dd4

View File

@ -41,7 +41,7 @@ extern yy::parser::symbol_type yylex();
%type <std::vector<branch_ptr>> branches
%type <std::vector<constructor_ptr>> constructors
%type <std::vector<parsed_type_ptr>> typeList
%type <parsed_type_ptr> type nullaryType
%type <parsed_type_ptr> type nullaryType typeListElement
%type <ast_ptr> aAdd aMul case app appBase
%type <definition_data_ptr> data
%type <definition_defn_ptr> defn
@ -146,12 +146,18 @@ type
;
nullaryType
: OPAREN UID typeList CPAREN { $$ = parsed_type_ptr(new parsed_type_app(std::move($2), std::move($3))); }
| UID { $$ = parsed_type_ptr(new parsed_type_app(std::move($1), { })); }
: UID typeList { $$ = parsed_type_ptr(new parsed_type_app(std::move($1), std::move($2))); }
| LID { $$ = parsed_type_ptr(new parsed_type_var(std::move($1))); }
| OPAREN type CPAREN { $$ = std::move($2); }
;
typeListElement
: OPAREN type CPAREN { $$ = std::move($2); }
| UID { $$ = parsed_type_ptr(new parsed_type_app(std::move($1), {})); }
| LID { $$ = parsed_type_ptr(new parsed_type_var(std::move($1))); }
;
typeList
: %empty { $$ = std::vector<parsed_type_ptr>(); }
| typeList type { $$ = std::move($1); $$.push_back(std::move($2)); }
| typeList typeListElement { $$ = std::move($1); $$.push_back(std::move($2)); }
;