From f547898e1f351e62fac1a9d8ea3b20fc0c7e8ae0 Mon Sep 17 00:00:00 2001 From: Ilya Rezvov Date: Tue, 23 Jan 2018 18:28:24 -0800 Subject: [PATCH] parse inline exports and imports in memory definition --- src/Language/Wasm/Parser.y | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Language/Wasm/Parser.y b/src/Language/Wasm/Parser.y index 5d2ae5b..864edd0 100644 --- a/src/Language/Wasm/Parser.y +++ b/src/Language/Wasm/Parser.y @@ -676,9 +676,23 @@ global_mut_export_import :: { Maybe Ident -> [ModuleField] } \ident -> [MFImport $ Import $2 $3 $ ImportGlobal ident $5] } --- TODO: inline exports and imports -memory :: { Memory } - : 'memory' opt(ident) limits ')' { Memory $2 $3 } +memory :: { [ModuleField] } + : 'memory' opt(ident) memory_limits_export_import { $3 $2 } + +memory_limits_export_import :: { Maybe Ident -> [ModuleField] } + : memory_limits { $1 } + | '(' memory_limits_export_import1 { $2 } + +memory_limits_export_import1 :: { Maybe Ident -> [ModuleField] } + : 'export' name ')' memory_limits_export_import { + \ident -> (MFExport $ Export $2 $ ExportMemory $ Named `fmap` ident) : $4 ident + } + | 'import' name name ')' limits ')' { + \ident -> [MFImport $ Import $2 $3 $ ImportMemory ident $5] + } + +memory_limits :: { Maybe Ident -> [ModuleField] } + : limits ')' { \ident -> [MFMem $ Memory ident $1] } -- TABLE -- limits :: { Limit } @@ -737,7 +751,6 @@ datasegment :: { DataSegment } modulefield1_single :: { ModuleField } : typedef { MFType $1 } | import { MFImport $1 } - | memory { MFMem $1 } | export { MFExport $1 } | start { MFStart $1 } | elemsegment { MFElem $1 } @@ -746,6 +759,7 @@ modulefield1_single :: { ModuleField } modulefield1_multi :: { [ModuleField] } : function { $1 } | table { $1 } + | memory { $1 } | global { $1 } modulefield1 :: { [ModuleField] }