Rough draft of single-expr function syntax

This commit is contained in:
John David Pressman 2019-10-17 20:50:41 -07:00
parent 60600a90fd
commit 8997155a57
3 changed files with 25 additions and 0 deletions

View File

@ -80,6 +80,7 @@ type t =
| Down of Region.t (* "down" *)
| Else of Region.t (* "else" *)
| End of Region.t (* "end" *)
| Expr of Region.t (* "expr" *)
| Fail of Region.t (* "fail" *)
| For of Region.t (* "for" *)
| From of Region.t (* "from" *)

View File

@ -78,6 +78,7 @@ type t =
| Down of Region.t (* "down" *)
| Else of Region.t (* "else" *)
| End of Region.t (* "end" *)
| Expr of Region.t (* "expr" *)
| Fail of Region.t (* "fail" *)
| For of Region.t (* "for" *)
| From of Region.t (* "from" *)
@ -210,6 +211,7 @@ let proj_token = function
| Down region -> region, "Down"
| Else region -> region, "Else"
| End region -> region, "End"
| Expr region -> region, "Expr"
| Fail region -> region, "Fail"
| For region -> region, "For"
| From region -> region, "From"
@ -303,6 +305,7 @@ let to_lexeme = function
| Down _ -> "down"
| Else _ -> "else"
| End _ -> "end"
| Expr _ -> "expr"
| Fail _ -> "fail"
| For _ -> "for"
| From _ -> "from"
@ -364,6 +367,7 @@ let keywords = [
(fun reg -> Down reg);
(fun reg -> Else reg);
(fun reg -> End reg);
(fun reg -> Expr reg);
(fun reg -> For reg);
(fun reg -> From reg);
(fun reg -> Function reg);
@ -588,6 +592,7 @@ let is_kwd = function
| Down _
| Else _
| End _
| Expr _
| Fail _
| For _
| From _

View File

@ -264,6 +264,25 @@ fun_decl:
return = $10;
terminator = $11}
in {region; value}}
| Function fun_name parameters COLON type_expr Is
Expr expr option(SEMI) {
let stop =
match $9 with
Some region -> region
| None -> expr_to_region $8 in
let region = cover $1 stop
and value = {
kwd_function = $1;
name = $2;
param = $3;
colon = $4;
ret_type = $5;
kwd_is = $6;
kwd_expr = $7;
expr = $8;
terminator = $9;
}
in {region; value}}
parameters:
par(nsepseq(param_decl,SEMI)) { $1 }