Last active
May 25, 2022 07:32
-
-
Save deemp/85d4bac3d14df2a8e135dda25fddd2e4 to your computer and use it in GitHub Desktop.
Revisions
-
deemp revised this gist
May 25, 2022 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,3 +30,16 @@ main = do customInt :: Parser Int customInt = read <$> many digitChar {- ghci> main (11111,333) 1:5: | 1 | 1111 | ^ unexpected end of input expecting Limited input: 5 characters -} -
deemp revised this gist
May 25, 2022 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,5 +30,3 @@ main = do customInt :: Parser Int customInt = read <$> many digitChar -
deemp created this gist
May 25, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ {-# LANGUAGE LambdaCase #-} module Lib where import Text.Megaparsec import Data.Void (Void) import Text.Megaparsec.Char (digitChar) import Data.Function ((&)) type Parser = Parsec Void String main :: IO () main = do let input = "11111333" parse p "p" input & \case Left e -> error $ show e Right r -> print r -- should print (11111, 333) return () where p :: Parser (Int, Int) p = do l <- takeP (Just "Limited input: 5 characters") 5 l' <- takeRest setInput l a <- customInt-- TODO limit input to 5 characters just for this `customInt` setInput l' b <- customInt -- take the remaining 3 (already limited) return (a, b) customInt :: Parser Int customInt = read <$> many digitChar -- customInt :: Parser Int -- NOTE: can't change this fn -- customInt = many digitChar