Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-
- Program's grammar: (1^+)(#^*)
- The above is actually a little lie. For #, I only want allow #, ##, ###, ####, and #####.
- Once I can understand why the parser below doesn't work, I can focus on that.
- -}
- -- | Given a 1# program, converts it to a list of parsed instructions
- -- | Currently, it doesn't parse comments.
- -- | TODO: Throw error if we get more than 5 hashes
- collectInstrs :: Parsec Void T.Text [ParsedInstr]
- collectInstrs = space >> many takeInstr
- where
- takeInstr :: Parsec Void T.Text ParsedInstr
- takeInstr = do
- ones <-
- some
- $ (do
- c <- char '1'
- space
- return c
- )
- hashes <-
- some
- $ (do
- c <- char '#'
- space
- return c
- )
- return . parseInstr $ T.pack ones <> T.pack hashes
- {-
- Seems to work fine when all expected 1 and # are there, but doesn't fail on the following:
- "#"
- " # "
- There are probably more problems but can't figure out why it doesn't fail for the above two cases.
- -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement