From 1fcce32ef6bc59dcea633e218fa2d218b8c9b9bd Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Fri, 23 May 2025 19:03:23 -0400 Subject: [PATCH] Updated to read from stdin/file --- app/Main.hs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 1dddb85..83ff5b8 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,8 +1,27 @@ module Main where import MdToHTML +import System.Environment +import System.IO + +readLinesHelper :: [String] -> IO [String] +readLinesHelper xs = do + done <- isEOF + if done + then return xs + else do + line <- getLine + let xs' = line : xs + readLinesHelper xs' + +readLines :: IO [String] +readLines = fmap reverse $ readLinesHelper [] main :: IO () main = do - let res = fst $ leftmostLongestParse parseDocument "# _Hello_\n" - putStrLn (show res) + args <- getArgs + fileContents <- case args of + [] -> getContents + x : _ -> readFile x + let res = fst $ leftmostLongestParse parseDocument fileContents + print res