summaryrefslogtreecommitdiff
path: root/src/parser.mly
diff options
context:
space:
mode:
authorJon French2018-05-16 15:44:19 +0100
committerJon French2018-05-16 15:44:19 +0100
commita7563156f1ea9ca71c2d4cd0de4bad67f0f99b30 (patch)
tree882c978f6e50369e8ddb0f4871755e9f33b4a715 /src/parser.mly
parente2d8fe4d847b6e8f71eecd7aa6d15799bd2a2e11 (diff)
Add support for inline val-spec declaration for mappings
This means that a mapping which formerly had to be pre-declared like val name : a <-> b ... mapping name { x <-> y, ... } can now be shortened to mapping name : a <-> b { x <-> y, ... }
Diffstat (limited to 'src/parser.mly')
-rw-r--r--src/parser.mly22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/parser.mly b/src/parser.mly
index a46defd6..5c513e5b 100644
--- a/src/parser.mly
+++ b/src/parser.mly
@@ -93,6 +93,16 @@ let mk_exp e n m = E_aux (e, loc n m)
let mk_lit l n m = L_aux (l, loc n m)
let mk_lit_exp l n m = mk_exp (E_lit (mk_lit l n m)) n m
let mk_typschm tq t n m = TypSchm_aux (TypSchm_ts (tq, t), loc n m)
+
+let mk_typschm_opt ts n m = TypSchm_opt_aux (
+ TypSchm_opt_some (
+ ts
+ ),
+ loc n m
+ )
+
+let mk_typschm_opt_none = TypSchm_opt_aux (TypSchm_opt_none, Unknown)
+
let mk_nc nc n m = NC_aux (nc, loc n m)
let mk_sd s n m = SD_aux (s, loc n m)
let mk_sd_doc s str n m = SD_aux (s, Documented (str, loc n m))
@@ -108,7 +118,7 @@ let mk_default d n m = DT_aux (d, loc n m)
let mk_mpexp mpexp n m = MPat_aux (mpexp, loc n m)
let mk_mpat mpat n m = MP_aux (mpat, loc n m)
let mk_mapcl mpexp1 mpexp2 n m = MCL_aux (MCL_mapcl (mpexp1, mpexp2), loc n m)
-let mk_map id mapcls n m = MD_aux (MD_mapping (id, mapcls), loc n m)
+let mk_map id tannot mapcls n m = MD_aux (MD_mapping (id, tannot, mapcls), loc n m)
let doc_vs doc (VS_aux (v, l)) = VS_aux (v, Documented (doc, l))
@@ -1280,9 +1290,9 @@ mapcl_list:
map_def:
| Mapping id Eq Lcurly mapcl_list Rcurly
- { mk_map $2 $5 $startpos $endpos }
- (* | Mapping id Colon typschm Eq Lcurly mapcl_list Rcurly
- * { mk_map $2 $4 $7 $startpos $endpos } *)
+ { mk_map $2 mk_typschm_opt_none $5 $startpos $endpos }
+ | Mapping id Colon typschm Eq Lcurly mapcl_list Rcurly
+ { mk_map $2 (mk_typschm_opt $4 $startpos($4) $endpos($4)) $7 $startpos $endpos }
let_def:
| Let_ letbind
@@ -1334,7 +1344,9 @@ scattered_def:
| Function_ id
{ mk_sd (SD_scattered_function(mk_recn, mk_tannotn, mk_eannotn, $2)) $startpos $endpos }
| Mapping id
- { mk_sd (SD_scattered_mapping $2) $startpos $endpos }
+ { mk_sd (SD_scattered_mapping ($2, mk_tannotn)) $startpos $endpos }
+ | Mapping id Colon funcl_typ
+ { mk_sd (SD_scattered_mapping ($2, $4)) $startpos $endpos }
scattered_clause:
| Doc Function_ Clause funcl