More work, I guess
This commit is contained in:
26
app/Main.hs
26
app/Main.hs
@@ -5,6 +5,7 @@ import Control.Monad
|
||||
import Control.Applicative
|
||||
import Text.Printf
|
||||
import Debug.Trace
|
||||
import Data.List
|
||||
|
||||
type HeaderLevel = Int
|
||||
|
||||
@@ -55,6 +56,11 @@ instance Show MdToken where
|
||||
mustBeHash :: ReadP Char
|
||||
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 = do
|
||||
firstChar <- get -- Must parse at least one character here
|
||||
text <- munch (\x -> not (elem x "#*_["))
|
||||
return (Unit (firstChar:text))
|
||||
--return (Unit text)
|
||||
-- firstChar <- get -- Must parse at least one character here
|
||||
text <- munch1 (\x -> not (elem x "#*_["))
|
||||
--return (Unit (firstChar:text))
|
||||
return (Unit text)
|
||||
|
||||
parseLine :: ReadP MdToken
|
||||
parseLine = choice [parseHeader, parseBold, parseItalic, parseString]
|
||||
|
||||
parsePara :: ReadP MdToken
|
||||
parsePara =
|
||||
------ parsePara :: ReadP MdToken
|
||||
------ parsePara = do
|
||||
------ parsed <- parseMany parseLine
|
||||
------ -- traceM $ show parsed
|
||||
------ return (Para parsed)
|
||||
parsePara = do
|
||||
parsed <- parseMany parseLine
|
||||
-- traceM $ show parsed
|
||||
return (Para parsed)
|
||||
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let res = readP_to_S parsePara "## Hello __world_*"
|
||||
let res = readP_to_S parsePara "## Hello __world__"
|
||||
putStrLn (show res)
|
||||
|
Reference in New Issue
Block a user