parsing updates for 2022-22 in haskell
This commit is contained in:
parent
d00f52da65
commit
2d31ebe29e
2 changed files with 8 additions and 14 deletions
|
@ -20,12 +20,12 @@ type Parser = Parsec Void String
|
||||||
|
|
||||||
parseMapLine :: Parser Line
|
parseMapLine :: Parser Line
|
||||||
parseMapLine = do
|
parseMapLine = do
|
||||||
line <- some (char '.' <|> char ' ' <|> char '#') <* char '\n'
|
line <- some (char '.' <|> char ' ' <|> char '#') <* eol
|
||||||
return $ V.generate (length line) (line !!)
|
return $ V.generate (length line) (line !!)
|
||||||
|
|
||||||
parseMap :: Parser Map
|
parseMap :: Parser Map
|
||||||
parseMap = do
|
parseMap = do
|
||||||
lines <- some parseMapLine <* char '\n'
|
lines <- some parseMapLine <* eol
|
||||||
return $ V.generate (length lines) (lines !!)
|
return $ V.generate (length lines) (lines !!)
|
||||||
|
|
||||||
parseInstruction :: Parser Instruction
|
parseInstruction :: Parser Instruction
|
||||||
|
@ -34,11 +34,8 @@ parseInstruction = (Move . read <$> some digitChar)
|
||||||
<|> (char 'R' $> R)
|
<|> (char 'R' $> R)
|
||||||
|
|
||||||
parseInput' :: Parser Input
|
parseInput' :: Parser Input
|
||||||
parseInput' = do
|
parseInput' = Input <$> parseMap
|
||||||
m <- parseMap
|
<*> some parseInstruction <* eol <* eof
|
||||||
i <- some parseInstruction
|
|
||||||
void $ optional (char '\n') <* eof
|
|
||||||
return $ Input m i
|
|
||||||
|
|
||||||
parseInput :: String -> IO Input
|
parseInput :: String -> IO Input
|
||||||
parseInput filename = do
|
parseInput filename = do
|
||||||
|
|
|
@ -21,12 +21,12 @@ type Parser = Parsec Void String
|
||||||
|
|
||||||
parseMapLine :: Parser Line
|
parseMapLine :: Parser Line
|
||||||
parseMapLine = do
|
parseMapLine = do
|
||||||
line <- some (char '.' <|> char ' ' <|> char '#') <* char '\n'
|
line <- some (char '.' <|> char ' ' <|> char '#') <* eol
|
||||||
return $ V.generate (length line) (line !!)
|
return $ V.generate (length line) (line !!)
|
||||||
|
|
||||||
parseMap :: Parser Map
|
parseMap :: Parser Map
|
||||||
parseMap = do
|
parseMap = do
|
||||||
lines <- some parseMapLine <* char '\n'
|
lines <- some parseMapLine <* eol
|
||||||
return $ V.generate (length lines) (lines !!)
|
return $ V.generate (length lines) (lines !!)
|
||||||
|
|
||||||
parseInstruction :: Parser Instruction
|
parseInstruction :: Parser Instruction
|
||||||
|
@ -35,11 +35,8 @@ parseInstruction = (Move . read <$> some digitChar)
|
||||||
<|> (char 'R' $> R)
|
<|> (char 'R' $> R)
|
||||||
|
|
||||||
parseInput' :: Parser Input
|
parseInput' :: Parser Input
|
||||||
parseInput' = do
|
parseInput' = Input <$> parseMap
|
||||||
m <- parseMap
|
<*> some parseInstruction <* eol <* eof
|
||||||
i <- some parseInstruction
|
|
||||||
void $ optional (char '\n') <* eof
|
|
||||||
return $ Input m i
|
|
||||||
|
|
||||||
parseInput :: String -> IO Input
|
parseInput :: String -> IO Input
|
||||||
parseInput filename = do
|
parseInput filename = do
|
||||||
|
|
Loading…
Add table
Reference in a new issue