SPY / haskell-wasm

Haskell WebAssembly Toolkit
Other
149 stars 24 forks source link

Unable to parse `elem` segment #24

Open Abhiroop opened 1 year ago

Abhiroop commented 1 year ago

When parsing valid wast files, the parser currently is unable to parse wast files containing this variant of the elem segment string:

(elem (;0;) (i32.const 1) func 0)

Currently, this throws the following error:

"Error occuried during parsing phase. Line 48, Column 29, Token TKeyword \"func\". Token lookahed: [Lexeme {pos = Just (AlexPn 1187 48 34), tok = TIntLit 0},Lexeme {pos = Just (AlexPn 1188 48 35), tok = TCloseBracket},Lexeme {pos = Just (AlexPn 1189 48 36), tok = TCloseBracket}]"

I presume the error lies somewhere in Parser.y. The reference interpreter is able to parse this file fine.

Abhiroop commented 1 year ago

The current production rule for elem segments is here - https://github.com/SPY/haskell-wasm/blob/master/src/Language/Wasm/Parser.y#L911 It definitely won't parse the example that I gave. I am not at all familiar with Happy but a production rule that parses this is something like this:

'elem' opt(ident) '(' offsetexpr 'func' index  ')' { ElemSegment (Index 0) $4 [$6] }

Someone who understands the wast grammar well should comment if this looks reasonable. The parser seems happy with this but I might have changed the meaning of the grammar.