Move QuoteLinkParser to Common
This commit is contained in:
parent
705beb10ac
commit
71a4a5829e
|
@ -82,7 +82,7 @@ executable chandlr
|
|||
Common.FrontEnd.Routes
|
||||
Common.AttachmentType
|
||||
Parsing.BodyParser
|
||||
Parsing.QuoteLinkParser
|
||||
Common.Parsing.QuoteLinkParser
|
||||
Parsing.EmbedParser
|
||||
Common.Parsing.PostPartType
|
||||
Common.Component.TimeControl
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 3abd4f9f772e864b5e9e1b44a07909bb7d74423b
|
||||
Subproject commit c8b6cfa8d17dab26db31f72a0b1b6bcbcd3d03f0
|
|
@ -33,7 +33,7 @@ import qualified Common.Network.PostType as Post
|
|||
import Common.Component.Thread.Model (PostWithBody)
|
||||
|
||||
import Common.Parsing.PostPartType
|
||||
import Parsing.QuoteLinkParser
|
||||
import Common.Parsing.QuoteLinkParser
|
||||
|
||||
|
||||
nodeListToList :: NodeList -> IO [ Node ]
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
module Parsing.QuoteLinkParser
|
||||
( parseURL
|
||||
, ParsedURL (..)
|
||||
)
|
||||
where
|
||||
|
||||
import Text.Parsec
|
||||
import Text.Parsec.String (Parser)
|
||||
|
||||
-- Define a data type to hold the extracted components
|
||||
data ParsedURL = ParsedURL
|
||||
{ boardName :: String
|
||||
, threadId :: Maybe Integer
|
||||
, postId :: Maybe Integer
|
||||
} deriving (Show, Eq)
|
||||
|
||||
-- Parser for a segment of the path
|
||||
segment :: Parser String
|
||||
segment = many (noneOf "/#")
|
||||
|
||||
-- Parser for an integer
|
||||
integer :: Parser Integer
|
||||
integer = read <$> many1 digit
|
||||
|
||||
-- Parser for the board name
|
||||
boardNameParser :: Parser String
|
||||
boardNameParser = char '/' >> segment
|
||||
|
||||
-- Optional parser for the thread number
|
||||
threadNumberParser :: Parser (Maybe Integer)
|
||||
threadNumberParser = optionMaybe $ try $ do
|
||||
_ <- char '/' >> string "res/"
|
||||
tId <- integer
|
||||
_ <- string ".html"
|
||||
return tId
|
||||
|
||||
-- Parser for index.html, returning Nothing for threadId and postId
|
||||
indexParser :: Parser (Maybe Integer, Maybe Integer)
|
||||
indexParser = try $ do
|
||||
_ <- string "/index.html"
|
||||
return (Nothing, Nothing)
|
||||
|
||||
-- Combined URL parser
|
||||
urlParser :: Parser ParsedURL
|
||||
urlParser = do
|
||||
bName <- boardNameParser
|
||||
|
||||
(tId, pId) <- try threadNumberParser >>= \mTid ->
|
||||
case mTid of
|
||||
Just tId -> do
|
||||
pId <- postIdParser
|
||||
return (Just tId, pId)
|
||||
Nothing -> indexParser
|
||||
eof -- Expect the end of input
|
||||
return $ ParsedURL bName tId pId
|
||||
|
||||
-- Optional parser for the post ID
|
||||
postIdParser :: Parser (Maybe Integer)
|
||||
postIdParser = optionMaybe $ char '#' >> integer
|
||||
|
||||
-- Function to run the parser
|
||||
parseURL :: String -> Either ParseError ParsedURL
|
||||
parseURL = parse urlParser ""
|
Loading…
Reference in New Issue