More work, I guess

master
Aadhavan Srinivasan 1 week ago
parent ade48bd64e
commit cbdcfcfea7

@ -5,6 +5,7 @@ import Control.Monad
import Control.Applicative import Control.Applicative
import Text.Printf import Text.Printf
import Debug.Trace import Debug.Trace
import Data.List
type HeaderLevel = Int type HeaderLevel = Int
@ -55,6 +56,11 @@ instance Show MdToken where
mustBeHash :: ReadP Char mustBeHash :: ReadP Char
mustBeHash = satisfy (\x -> x == '#') mustBeHash = satisfy (\x -> x == '#')
lengthCmp :: (a,[b]) -> (a, [b]) -> Ordering
lengthCmp (i,j) (k,l) = compare (length l) (length j)
leftmostLongest :: [(a, [b])] -> a
leftmostLongest tupleLst = (sortBy lengthCmp tupleLst)
@ -96,24 +102,22 @@ parseItalic = do
parseString :: ReadP MdToken parseString :: ReadP MdToken
parseString = do parseString = do
firstChar <- get -- Must parse at least one character here -- firstChar <- get -- Must parse at least one character here
text <- munch (\x -> not (elem x "#*_[")) text <- munch1 (\x -> not (elem x "#*_["))
return (Unit (firstChar:text)) --return (Unit (firstChar:text))
--return (Unit text) return (Unit text)
parseLine :: ReadP MdToken parseLine :: ReadP MdToken
parseLine = choice [parseHeader, parseBold, parseItalic, parseString] parseLine = choice [parseHeader, parseBold, parseItalic, parseString]
parsePara :: ReadP MdToken parsePara :: ReadP MdToken
parsePara = parsePara = do
------ parsePara :: ReadP MdToken parsed <- parseMany parseLine
------ parsePara = do -- traceM $ show parsed
------ parsed <- parseMany parseLine return (Para parsed)
------ -- traceM $ show parsed
------ return (Para parsed)
main :: IO () main :: IO ()
main = do main = do
let res = readP_to_S parsePara "## Hello __world_*" let res = readP_to_S parsePara "## Hello __world__"
putStrLn (show res) putStrLn (show res)

Loading…
Cancel
Save