Add parser tokens, guru meditation on why the AST types don't work

This commit is contained in:
John David Pressman 2019-10-17 21:33:45 -07:00
parent 8997155a57
commit 35a59a0867
4 changed files with 52 additions and 29 deletions

View File

@ -49,6 +49,7 @@ type kwd_contains = Region.t
type kwd_down = Region.t type kwd_down = Region.t
type kwd_else = Region.t type kwd_else = Region.t
type kwd_end = Region.t type kwd_end = Region.t
type kwd_expr = Region.t
type kwd_for = Region.t type kwd_for = Region.t
type kwd_from = Region.t type kwd_from = Region.t
type kwd_function = Region.t type kwd_function = Region.t
@ -210,7 +211,8 @@ and type_tuple = (type_expr, comma) nsepseq par reg
(* Function and procedure declarations *) (* Function and procedure declarations *)
and fun_decl = { and fun_decl =
BlockFun of {
kwd_function : kwd_function; kwd_function : kwd_function;
name : variable; name : variable;
param : parameters; param : parameters;
@ -221,8 +223,17 @@ and fun_decl = {
block : block reg; block : block reg;
kwd_with : kwd_with; kwd_with : kwd_with;
return : expr; return : expr;
terminator : semi option terminator : semi option }
} | BlocklessFun of
{ kwd_function : kwd_function;
name : variable;
param : parameters;
colon : colon;
ret_type : type_expr;
kwd_is : kwd_is;
kwd_expr : kwd_expr;
return : expr;
terminator : semi option }
and parameters = (param_decl, semi) nsepseq par reg and parameters = (param_decl, semi) nsepseq par reg

View File

@ -33,6 +33,7 @@ type kwd_contains = Region.t
type kwd_down = Region.t type kwd_down = Region.t
type kwd_else = Region.t type kwd_else = Region.t
type kwd_end = Region.t type kwd_end = Region.t
type kwd_expr = Region.t
type kwd_for = Region.t type kwd_for = Region.t
type kwd_from = Region.t type kwd_from = Region.t
type kwd_function = Region.t type kwd_function = Region.t
@ -201,7 +202,8 @@ and type_tuple = (type_expr, comma) nsepseq par reg
(* Function declarations *) (* Function declarations *)
and fun_decl = { and fun_decl =
BlockFun of {
kwd_function : kwd_function; kwd_function : kwd_function;
name : variable; name : variable;
param : parameters; param : parameters;
@ -212,8 +214,17 @@ and fun_decl = {
block : block reg; block : block reg;
kwd_with : kwd_with; kwd_with : kwd_with;
return : expr; return : expr;
terminator : semi option terminator : semi option }
} | BlocklessFun of
{ kwd_function : kwd_function;
name : variable;
param : parameters;
colon : colon;
ret_type : type_expr;
kwd_is : kwd_is;
kwd_expr : kwd_expr;
return : expr;
terminator : semi option }
and parameters = (param_decl, semi) nsepseq par reg and parameters = (param_decl, semi) nsepseq par reg

View File

@ -53,6 +53,7 @@
%token <Region.t> Contains (* "contains" *) %token <Region.t> Contains (* "contains" *)
%token <Region.t> Else (* "else" *) %token <Region.t> Else (* "else" *)
%token <Region.t> End (* "end" *) %token <Region.t> End (* "end" *)
%token <Region.t> Expr (* "expr" *)
%token <Region.t> For (* "for" *) %token <Region.t> For (* "for" *)
%token <Region.t> Function (* "function" *) %token <Region.t> Function (* "function" *)
%token <Region.t> From (* "from" *) %token <Region.t> From (* "from" *)

View File

@ -263,7 +263,7 @@ fun_decl:
kwd_with = $9; kwd_with = $9;
return = $10; return = $10;
terminator = $11} terminator = $11}
in {region; value}} in BlockFun {region; value}}
| Function fun_name parameters COLON type_expr Is | Function fun_name parameters COLON type_expr Is
Expr expr option(SEMI) { Expr expr option(SEMI) {
let stop = let stop =
@ -279,10 +279,10 @@ fun_decl:
ret_type = $5; ret_type = $5;
kwd_is = $6; kwd_is = $6;
kwd_expr = $7; kwd_expr = $7;
expr = $8; return = $8;
terminator = $9; terminator = $9;
} }
in {region; value}} in BlocklessFun {region; value}}
parameters: parameters:
par(nsepseq(param_decl,SEMI)) { $1 } par(nsepseq(param_decl,SEMI)) { $1 }