Closed IanMarsh1 closed 1 year ago
Still have issues with the Parser.hs file and trying to get the stack. Error below:
src\Adder\Lang\Parser.hs:48:19: error:
* Couldn't match type Statement with [Statement] Expected: ParsecT String () (IndentT Identity) [Statement] Actual: IParser Statement * In the second argument of (<$>), namely statement In the expression: Pgm <$> statement In an equation for `program': program = Pgm <$> statement |
48 | program = Pgm <$> statement |__^^^^^^^^^
It's useful to note here that ParsecT String () (IndentT Identity)
means the same thing as IParser
in this context. So, what it's telling you is that Pgm <$> statement
gives you an IParser Statement
, but what it needs is an IParser [Statement]
. That's because the statement
function is an IParser Statement
.
This is where the block
function that I mentioned earlier in the Zoom would be useful. The type of the block function is block :: IParser a -> IParser [a]
. In other words, if you give is a function that parses an a
value, then it creates a function that parses an sequence of a
s on separate lines, as long as they're all indented the same amount (which is what we want).
As an example, if we write block identifier
that will have type IParser [String]
and will parse an indented block of identifiers, each identifier on its own line and all lines indented the same amount. Of course, we don't want a block of identifiers... we want a block of statements.
The pass statement looks to be implemented correctly. I don't know if you need to add "return PassStmt" when you define it in the parser. I could be wrong, but I don't think you need it.
Still have issues with the Parser.hs file and trying to get the stack. Error below:
48 | program = Pgm <$> statement |__^^^^^^^^^