Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. {-
  2. Program's grammar: (1^+)(#^*)
  3.  
  4. The above is actually a little lie. For #, I only want allow #, ##, ###, ####, and #####.
  5. Once I can understand why the parser below doesn't work, I can focus on that.
  6.  
  7. -}
  8.  
  9. -- | Given a 1# program, converts it to a list of parsed instructions
  10. -- | Currently, it doesn't parse comments.
  11. -- | TODO: Throw error if we get more than 5 hashes
  12. collectInstrs :: Parsec Void T.Text [ParsedInstr]
  13. collectInstrs = space >> many takeInstr
  14. where
  15. takeInstr :: Parsec Void T.Text ParsedInstr
  16. takeInstr = do
  17. ones <-
  18. some
  19. $ (do
  20. c <- char '1'
  21. space
  22. return c
  23. )
  24. hashes <-
  25. some
  26. $ (do
  27. c <- char '#'
  28. space
  29. return c
  30. )
  31. return . parseInstr $ T.pack ones <> T.pack hashes
  32.  
  33.  
  34. {-
  35. Seems to work fine when all expected 1 and # are there, but doesn't fail on the following:
  36.  
  37. "#"
  38.  
  39. " # "
  40.  
  41. There are probably more problems but can't figure out why it doesn't fail for the above two cases.
  42.  
  43. -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement