Haskell: syntax error when adding new line in pattern matching
compiler-construction, haskell, parsing
Solution
Have you indented the new line with the same space-delimiters as the previous ones? Or, has a tab character snuck in there?
Problem
Basically I'm modifying a parser to handle additional operators. Before my changes, one part of the parser looked like this: ``` parseExpRec e1 (op : ts) = let (e2, ts') = parsePrimExp ts in case op of T_Plus -> parseExpRec (BinOpApp Plus e1 e2) ts' T_Minus -> parseExpRec (BinOpApp Minus e1 e2) ts' T_Times -> parseExpRec (BinOpApp Times e1 e2) ts' T_Divide -> parseExpRec (BinOpApp Divide e1 e2) ts' _ -> (e1, op : ts) ``` T_Plus etc. are members of the Token datatype, and Plus, Minus etc. are part of BinOp which BinOpApp applies to two operands. I have updated the Token and BinOpApp datatypes to handle the Power (exponentiation) token. This is the resulting code: ``` parseExpRec e1 (op : ts) = let (e2, ts') = parsePrimExp ts in case op of T_Plus -> parseExpRec (BinOpApp Plus e1 e2) ts' T_Minus -> parseExpRec (BinOpApp Minus e1 e2) ts' T_Times -> parseExpRec (BinOpApp Times e1 e2) ts' T_Divide -> parseExpRec (BinOpApp Divide e1 e2) ts' T_Power -> parseExpRec (BinOpApp Power e1 e2) ts' _ -> (e1, op : ts) ``` This seems simple but it's now giving the following error: TXL.hs:182:13: parse error on input '->' Line 182 is the line where I added "T_Power -> parseExpRec..." - I don't see how it's any different from the other lines, which parse fine. I'm using GHCi as my environment.