aboutsummaryrefslogtreecommitdiff
path: root/2022
diff options
context:
space:
mode:
authorJulien Dessaux2023-12-25 23:47:01 +0100
committerJulien Dessaux2023-12-25 23:47:01 +0100
commit2d31ebe29e936f894ce3ce1f92999aec80c20389 (patch)
tree34eefbae4e21c910b8d6d7f432ee5b112cec6e66 /2022
parent2023-13 part 2 in haskell (diff)
downloadadvent-of-code-2d31ebe29e936f894ce3ce1f92999aec80c20389.tar.gz
advent-of-code-2d31ebe29e936f894ce3ce1f92999aec80c20389.tar.bz2
advent-of-code-2d31ebe29e936f894ce3ce1f92999aec80c20389.zip
parsing updates for 2022-22 in haskell
Diffstat (limited to '')
-rw-r--r--2022/22-Monkey-Map/first.hs11
-rw-r--r--2022/22-Monkey-Map/second.hs11
2 files changed, 8 insertions, 14 deletions
diff --git a/2022/22-Monkey-Map/first.hs b/2022/22-Monkey-Map/first.hs
index a7f9385..913ba30 100644
--- a/2022/22-Monkey-Map/first.hs
+++ b/2022/22-Monkey-Map/first.hs
@@ -20,12 +20,12 @@ type Parser = Parsec Void String
parseMapLine :: Parser Line
parseMapLine = do
- line <- some (char '.' <|> char ' ' <|> char '#') <* char '\n'
+ line <- some (char '.' <|> char ' ' <|> char '#') <* eol
return $ V.generate (length line) (line !!)
parseMap :: Parser Map
parseMap = do
- lines <- some parseMapLine <* char '\n'
+ lines <- some parseMapLine <* eol
return $ V.generate (length lines) (lines !!)
parseInstruction :: Parser Instruction
@@ -34,11 +34,8 @@ parseInstruction = (Move . read <$> some digitChar)
<|> (char 'R' $> R)
parseInput' :: Parser Input
-parseInput' = do
- m <- parseMap
- i <- some parseInstruction
- void $ optional (char '\n') <* eof
- return $ Input m i
+parseInput' = Input <$> parseMap
+ <*> some parseInstruction <* eol <* eof
parseInput :: String -> IO Input
parseInput filename = do
diff --git a/2022/22-Monkey-Map/second.hs b/2022/22-Monkey-Map/second.hs
index 82752cd..33385dc 100644
--- a/2022/22-Monkey-Map/second.hs
+++ b/2022/22-Monkey-Map/second.hs
@@ -21,12 +21,12 @@ type Parser = Parsec Void String
parseMapLine :: Parser Line
parseMapLine = do
- line <- some (char '.' <|> char ' ' <|> char '#') <* char '\n'
+ line <- some (char '.' <|> char ' ' <|> char '#') <* eol
return $ V.generate (length line) (line !!)
parseMap :: Parser Map
parseMap = do
- lines <- some parseMapLine <* char '\n'
+ lines <- some parseMapLine <* eol
return $ V.generate (length lines) (lines !!)
parseInstruction :: Parser Instruction
@@ -35,11 +35,8 @@ parseInstruction = (Move . read <$> some digitChar)
<|> (char 'R' $> R)
parseInput' :: Parser Input
-parseInput' = do
- m <- parseMap
- i <- some parseInstruction
- void $ optional (char '\n') <* eof
- return $ Input m i
+parseInput' = Input <$> parseMap
+ <*> some parseInstruction <* eol <* eof
parseInput :: String -> IO Input
parseInput filename = do