@@ -1227,32 +1227,67 @@ table_fields :
12271227/* Imports & Exports */
12281228
12291229externtype :
1230- | LPAR FUNC bindidx_opt typeuse RPAR
1231- { fun c -> ignore ($ 3 c anon_func bind_func);
1232- fun () -> ExternFuncT (Idx ($ 4 c).it) }
1233- | LPAR TAG bindidx_opt typeuse RPAR
1234- { fun c -> ignore ($ 3 c anon_tag bind_tag);
1235- fun () -> ExternTagT (TagT (Idx ($ 4 c).it)) }
1236- | LPAR TAG bindidx_opt functype RPAR /* Sugar */
1237- { fun c -> ignore ($ 3 c anon_tag bind_tag);
1238- fun () -> ExternTagT (TagT (Idx (inline_functype c ($ 4 c) $ loc($ 4 )).it)) }
1239- | LPAR GLOBAL bindidx_opt globaltype RPAR
1240- { fun c -> ignore ($ 3 c anon_global bind_global);
1241- fun () -> ExternGlobalT ($ 4 c) }
1242- | LPAR MEMORY bindidx_opt memorytype RPAR
1243- { fun c -> ignore ($ 3 c anon_memory bind_memory);
1244- fun () -> ExternMemoryT ($ 4 c) }
1245- | LPAR TABLE bindidx_opt tabletype RPAR
1246- { fun c -> ignore ($ 3 c anon_table bind_table);
1247- fun () -> ExternTableT ($ 4 c) }
1248- | LPAR FUNC bindidx_opt functype RPAR /* Sugar */
1249- { fun c -> ignore ($ 3 c anon_func bind_func);
1250- fun () -> ExternFuncT (Idx (inline_functype c ($ 4 c) $ loc($ 4 )).it) }
1230+ | LPAR FUNC option(bindidx) typeuse RPAR
1231+ { fun c -> ($3, anon_func, bind_func,
1232+ fun () -> ExternFuncT (Idx ($4 c).it)) }
1233+ | LPAR TAG option(bindidx) typeuse RPAR
1234+ { fun c -> ($3, anon_tag, bind_tag,
1235+ fun () -> ExternTagT (TagT (Idx ($4 c).it))) }
1236+ | LPAR TAG option(bindidx) functype RPAR /* Sugar */
1237+ { fun c -> ($3, anon_tag, bind_tag,
1238+ fun () -> ExternTagT (TagT (Idx (inline_functype c ($4 c) $loc($4)).it))) }
1239+ | LPAR GLOBAL option(bindidx) globaltype RPAR
1240+ { fun c -> ($3, anon_global, bind_global,
1241+ fun () -> ExternGlobalT ($4 c)) }
1242+ | LPAR MEMORY option(bindidx) memorytype RPAR
1243+ { fun c -> ($3, anon_memory, bind_memory,
1244+ fun () -> ExternMemoryT ($4 c)) }
1245+ | LPAR TABLE option(bindidx) tabletype RPAR
1246+ { fun c -> ($3, anon_table, bind_table,
1247+ fun () -> ExternTableT ($4 c)) }
1248+ | LPAR FUNC option(bindidx) functype RPAR /* Sugar */
1249+ { fun c -> ($3, anon_func, bind_func,
1250+ fun () -> ExternFuncT (Idx (inline_functype c ($4 c) $loc($4)).it)) }
1251+
1252+ compact_item1 :
1253+ | LPAR ITEM name externtype RPAR
1254+ { fun c -> let (id, anon, bind, df) = $4 c in
1255+ ignore (match id with None -> anon c $loc($4) | Some x -> bind c x);
1256+ fun () -> ($3, df ()) }
1257+
1258+ compact_item1_list :
1259+ | compact_item1
1260+ { fun c -> let f = $1 c in
1261+ fun () -> [f ()] }
1262+ | compact_item1 compact_item1_list
1263+ { fun c -> let f = $1 c in let fs = $2 c in
1264+ fun () -> f () :: fs () }
1265+
1266+ compact_item2_list :
1267+ | LPAR ITEM name RPAR compact_item2_list
1268+ { let (items, xt_fn) = $5 in ($3 :: items, xt_fn) }
1269+ | externtype
1270+ { ([], $1) }
12511271
12521272import :
12531273 | LPAR IMPORT name name externtype RPAR
1254- { fun c -> let df = $ 5 c in
1255- fun () -> Import ($ 3 , $ 4 , df () ) @@ $ sloc }
1274+ { fun c -> let (id, anon, bind, df) = $5 c in
1275+ ignore (match id with None -> anon c $loc($5) | Some x -> bind c x);
1276+ fun () -> [Import ($3, $4, df ()) @@ $sloc] }
1277+ | LPAR IMPORT name compact_item1_list RPAR
1278+ { fun c -> let items = $4 c in
1279+ fun () ->
1280+ List.map (fun (item_name, xt) -> Import ($3, item_name, xt) @@ $sloc)
1281+ (items ()) }
1282+ | LPAR IMPORT name compact_item2_list RPAR
1283+ { fun c ->
1284+ let (items, xt_fn) = $4 in
1285+ let (id, anon, _bind, df) = xt_fn c in
1286+ (match id with Some x -> error x.at "identifier not allowed" | None -> ());
1287+ List.iter (fun _ -> ignore (anon c $sloc)) items;
1288+ fun () ->
1289+ let xt = df () in
1290+ List.map (fun item_name -> Import ($3, item_name, xt) @@ $sloc) items }
12561291
12571292inline_import :
12581293 | LPAR IMPORT name name RPAR { $3, $4 }
@@ -1377,8 +1412,8 @@ module_fields1 :
13771412 | import module_fields
13781413 { fun c -> let imf = $1 c in let mff = $2 c in
13791414 fun () -> let mf = mff () in
1380- fun () -> let im = imf () in let m = mf () in
1381- {m with imports = im :: m .imports} }
1415+ fun () -> let ims = imf () in let m = mf () in
1416+ {m with imports = ims @ m.imports} }
13821417 | export module_fields
13831418 { fun c -> let mff = $2 c in
13841419 fun () -> let mf = mff () in
0 commit comments