Permalink
Browse files

comments capture their text for the debugger

  • Loading branch information...
1 parent a091b0a commit 36892070d9a86884d3847e47fbd90704d3c4fbc1 @youngnh committed Mar 16, 2010
Showing with 5 additions and 4 deletions.
  1. +1 −1 Language/QuickPiet/Interpreter.hs
  2. +2 −2 Language/QuickPiet/Parser.hs
  3. +2 −1 Language/QuickPiet/StackOperations.hs
@@ -43,7 +43,7 @@ execute (Interpreter done (p@Not:rest) instr outstr stack) =
execute (Interpreter done (p@Greater:rest) instr outstr stack) = Interpreter (done ++ [p]) rest instr outstr (greater stack)
execute (Interpreter done (p@End:rest) instr outstr stack) = Finished (done ++ [p]) rest instr outstr stack
execute (Interpreter done (p@(Label _):rest) instr outstr stack) = Interpreter (done ++ [p]) rest instr outstr stack
-execute (Interpreter done (p@Comment:rest) instr outstr stack) = Interpreter (done ++ [p]) rest instr outstr stack
+execute (Interpreter done (p@(Comment _):rest) instr outstr stack) = Interpreter (done ++ [p]) rest instr outstr stack
execute (Interpreter done (p@(Goto label other):rest) instr outstr (Stack (x:stack))) = Interpreter done' rest' instr outstr (Stack stack)
where (done', rest') = goto x (done ++ [p] ++ rest)
goto 1 prog = break (== (Label label)) prog
@@ -28,8 +28,8 @@ command = comment <|> label <|> action
-- a comment is a # followed by zero or more chars
comment :: GenParser Char st Command
comment = do char '#'
- many (noneOf "\n")
- return Comment
+ text <- many (noneOf "\n")
+ return (Comment text)
-- a label is a : followed by zero or more alpha-numeric chars
label :: GenParser Char st Command
@@ -42,7 +42,7 @@ data Command = Push Int
| Not
| Greater
| End
- | Comment
+ | Comment String
| Label String
| Goto String String
deriving (Eq)
@@ -62,6 +62,7 @@ instance Show Command where
show Not = "not"
show Greater = "greater"
show End = "end"
+ show (Comment s) = "#" ++ s
show (Label s) = ":" ++ s
show (Goto label other) = "goto " ++ label ++ " " ++ other

0 comments on commit 3689207

Please sign in to comment.