From c0f058dd425fd306f21b7435501ebbfdc9d28b76 Mon Sep 17 00:00:00 2001 From: Pingu Date: Fri, 28 Oct 2022 12:55:46 +0200 Subject: [PATCH] Started thinking of using new datatypes --- README.org | 20 ++++++++------------ app/Main.hs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/README.org b/README.org index 29581d0..44e48b4 100644 --- a/README.org +++ b/README.org @@ -6,15 +6,11 @@ The name is pronounced like autumn. * Spec -| org | forum | Notes | -|-----+-----------------+---------------------------| -| * | [TITLE][/TITLE] | | -| ** | [SIZE=4][/SIZE] | | -| *** | [SIZE=2][/SIZE] | | -| - | [*] | Needs a [LIST] around all | -| | | | -| | | | -| | | | -| | | | -| | | | -| | | | +| org | forum | Notes | +|---------------+------------------------------------------------------+------------------------------------| +| * | [TITLE][/TITLE] | | +| ** | [SIZE=4][/SIZE] | | +| *** | [SIZE=2][/SIZE] | | +| - | [*] | Needs a [LIST] around all | +| [[]] | [IMG][/IMG] or [VIDEO][/VIDEO] or [URL="link"][/URL] | Figure out what type of link it is | +| #+BEGIN #+END | [SPOILER][/SPOILER] | | diff --git a/app/Main.hs b/app/Main.hs index 496e10d..dad8def 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -4,6 +4,8 @@ import Control.Applicative hiding (some) import Control.Monad import Data.Functor import Data.Void +import GHC.Stack.CCS (whereFrom) +import GHC.StaticPtr (StaticPtrInfo) import System.Environment import System.Exit import Text.Megaparsec hiding (satisfy) @@ -11,6 +13,34 @@ import Text.Megaparsec.Char type Parser = Parsec Void String +newtype URL = URL String + +data Info = + Bread String | + List [Info] | + Header String | + Subheader String | + Subsubheader String | + Image URL | + Video URL | + Link URL Info | + Spoiler Info + +instance Show Info where + show :: Info -> String + show info = case info of + Bread text -> text + List texts -> "[LIST]" ++ concatMap show texts ++ "[/LIST]" + Header text -> "[TITLE]" ++ text ++ "[/TITLE]" + Subheader text -> "[SIZE=4]" ++ text ++ "[/SIZE]" + Subsubheader text -> "[SIZE=2]" ++ text ++ "[/SIZE]" + Image (URL url) -> "[IMG]" ++ url ++ "[/IMG]" + Video (URL url) -> "[VIDEO]" ++ url ++ "[/VIDEO]" + Link (URL url) inf -> "[URL=\"" ++ url ++ "\"]" ++ show inf ++ "[/IMG]" + Spoiler inf -> "[SPOILER]" ++ show inf ++ "[/SPOILER]" + +newtype Post = Post [Info] + parseHelper :: Parser String -> String -> String parseHelper parser x = case parse parser "" x of Left bundle -> error $ errorBundlePretty bundle