I'm building a JavaScript parser in Haskell using Happy and I'm running into an error message that, no matter how hard I try, I can't debug.
I can't really post all the code here as it is thousands of lines long. I'll try to post the relevant bits and if anyone can help me I'd be immensely grateful!
This error message is very long so please bear with me. I've left out most of the HappyAbsSyn
part. I can provide the full error message if it will help.
Parser.hs:800:28:
Couldn't match expected type `Expression'
with actual type `PrimaryExpr'
Expected type: Int
-> Int
-> Token
-> HappyState
Token
(HappyStk
(HappyAbsSyn
FuncDecl
... etc etc ...
PostFix)
-> P a1)
-> [HappyState
Token
(HappyStk
(HappyAbsSyn
FuncDecl
... etc etc ...
PostFix)
-> P a1)]
-> HappyStk
(HappyAbsSyn
FuncDecl
... etc etc ...
Actual type: Int
-> Int
-> Token
-> HappyState
Token
(HappyStk
(HappyAbsSyn
FuncDecl
... etc etc ...
t630)
-> P a0)
-> [HappyState
Token
(HappyStk
(HappyAbsSyn
FuncDecl
... etc etc ...
t630)
-> P a0)]
-> HappyStk
(HappyAbsSyn
FuncDecl
... etc etc ...
t630)
-> P a0
In the first argument of `happyGoto', namely `action_90'
In the expression: happyGoto action_90
Got that? Ok, so the first thing I did was look at line 800 in Parser.hs (The file generated by Happy).
799: action_60 (7) = happyGoto action_71
800: action_60 (28) = happyGoto action_90
801: action_60 (33) = happyGoto action_15
action_90
is defined as:
action_90 (100) = happyShift action_224
action_90 _ = happyFail
This obviously doesn't make much sense unless we understand what the codes correspond to. I asked Happy to generate an info file when I compiled and this is (I think) the appropriate part:
-----------------------------------------------------------------------------
Grammar
-----------------------------------------------------------------------------
%start_parse -> program (0)
... etc etc ...
statement -> ID ':' statement (28)
... etc etc ...
primaryExpr -> THIS (100)
... etc etc ...
So it looks like it's something to do with an ID statement. I'm really quite confused by this point. Does anyone have any suggestions of where I should go from here? I'm guessing that to work through this, you'd need to see the Abstract Syntax. Here is a bit of it. Again, I'm happy to show more if it helps.
data Expression
= Assignment Assignment
deriving Show
data Assignment
= CondExpr CondExpr
| Assign LeftExpr AssignOp Assignment
| AssignFuncDecl FuncDecl
deriving Show
data FuncDecl
= FuncDecl (Maybe String) [String] [Source]
deriving Show
data Statement
= EmptyStmt
| IfStmt IfStmt
| IterativeStmt IterativeStmt
| ExprStmt Expression
| Block [Statement]
| VarStmt [VarDecl]
| TryStmt TryStmt
| ContinueStmt (Maybe String)
| BreakStmt (Maybe String)
| ReturnStmt (Maybe Expression)
| WithStmt Expression Statement
| LabelledStmt String Statement
| Switch Switch
| ThrowExpr Expression
deriving Show
data PrimaryExpr
= ExpLitInt Integer
| ExpLitStr String
| ExpId String
| ExpBrackExp PrimaryExpr
| ExpThis
| ExpRegex String
| ExpArray ArrayLit
| ExpObject [(Property, Assignment)]
deriving Show
I'm sorry this is so long. I'm at my wits end here. Any help or pointers would be amazing.