[hs] Move parsing stuff to Aoc.Parse
This commit is contained in:
parent
b87c8e4555
commit
320fc25e06
2 changed files with 23 additions and 4 deletions
|
|
@ -4,17 +4,17 @@ module Aoc.Day
|
||||||
, dayFile
|
, dayFile
|
||||||
, dayString
|
, dayString
|
||||||
, dayText
|
, dayText
|
||||||
, Parser
|
|
||||||
, dayParser
|
, dayParser
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Data.Void
|
|
||||||
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.IO as T
|
import qualified Data.Text.IO as T
|
||||||
import Text.Megaparsec
|
import Text.Megaparsec
|
||||||
|
|
||||||
|
import Aoc.Parse
|
||||||
|
|
||||||
data Day
|
data Day
|
||||||
= DayPure String (IO ())
|
= DayPure String (IO ())
|
||||||
| DayFile String (FilePath -> IO ())
|
| DayFile String (FilePath -> IO ())
|
||||||
|
|
@ -31,8 +31,6 @@ dayString name f = dayFile name $ f <=< readFile
|
||||||
dayText :: String -> (T.Text -> IO ()) -> Day
|
dayText :: String -> (T.Text -> IO ()) -> Day
|
||||||
dayText name f = dayFile name $ f <=< T.readFile
|
dayText name f = dayFile name $ f <=< T.readFile
|
||||||
|
|
||||||
type Parser = Parsec Void T.Text
|
|
||||||
|
|
||||||
dayParser :: String -> Parser a -> (a -> IO ()) -> Day
|
dayParser :: String -> Parser a -> (a -> IO ()) -> Day
|
||||||
dayParser name p f = dayFile name $ \path -> do
|
dayParser name p f = dayFile name $ \path -> do
|
||||||
text <- T.readFile path
|
text <- T.readFile path
|
||||||
|
|
|
||||||
21
hs/src/Aoc/Parse.hs
Normal file
21
hs/src/Aoc/Parse.hs
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
module Aoc.Parse
|
||||||
|
( module Text.Megaparsec
|
||||||
|
, module Text.Megaparsec.Char
|
||||||
|
, module Text.Megaparsec.Char.Lexer
|
||||||
|
, Parser
|
||||||
|
, manyLines
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Data.Void
|
||||||
|
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import Text.Megaparsec
|
||||||
|
import Text.Megaparsec.Char
|
||||||
|
import Text.Megaparsec.Char.Lexer (binary, decimal, float,
|
||||||
|
hexadecimal, octal, scientific,
|
||||||
|
signed)
|
||||||
|
|
||||||
|
type Parser = Parsec Void T.Text
|
||||||
|
|
||||||
|
manyLines :: Parser a -> Parser [a]
|
||||||
|
manyLines p = sepBy p newline <* optional newline <* eof
|
||||||
Loading…
Add table
Add a link
Reference in a new issue