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_else = Region.t
type kwd_end = Region.t
type kwd_expr = Region.t
type kwd_for = Region.t
type kwd_from = Region.t
type kwd_function = Region.t
@ -210,19 +211,29 @@ and type_tuple = (type_expr, comma) nsepseq par reg
(* Function and procedure declarations *)
and fun_decl = {
kwd_function : kwd_function;
name : variable;
param : parameters;
colon : colon;
ret_type : type_expr;
kwd_is : kwd_is;
local_decls : local_decl list;
block : block reg;
kwd_with : kwd_with;
return : expr;
terminator : semi option
}
and fun_decl =
BlockFun of {
kwd_function : kwd_function;
name : variable;
param : parameters;
colon : colon;
ret_type : type_expr;
kwd_is : kwd_is;
local_decls : local_decl list;
block : block reg;
kwd_with : kwd_with;
return : expr;
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

View File

@ -33,6 +33,7 @@ type kwd_contains = Region.t
type kwd_down = Region.t
type kwd_else = Region.t
type kwd_end = Region.t
type kwd_expr = Region.t
type kwd_for = Region.t
type kwd_from = Region.t
type kwd_function = Region.t
@ -201,19 +202,29 @@ and type_tuple = (type_expr, comma) nsepseq par reg
(* Function declarations *)
and fun_decl = {
kwd_function : kwd_function;
name : variable;
param : parameters;
colon : colon;
ret_type : type_expr;
kwd_is : kwd_is;
local_decls : local_decl list;
block : block reg;
kwd_with : kwd_with;
return : expr;
terminator : semi option
}
and fun_decl =
BlockFun of {
kwd_function : kwd_function;
name : variable;
param : parameters;
colon : colon;
ret_type : type_expr;
kwd_is : kwd_is;
local_decls : local_decl list;
block : block reg;
kwd_with : kwd_with;
return : expr;
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

View File

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

View File

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