summaryrefslogtreecommitdiff
path: root/src/Codec/Pesto/Serialize.lhs
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2020-08-24 17:09:34 +0200
committerLars-Dominik Braun <lars@6xq.net>2020-08-24 17:09:34 +0200
commit295dd897297722d07ec2ce5fb82e323fe495c775 (patch)
tree8d9de652a030c34c6be775ca31c159620f52fbf1 /src/Codec/Pesto/Serialize.lhs
parent39f9263fa38c32ce2e3a4f4bedb8349da47a3200 (diff)
downloadpesto-295dd897297722d07ec2ce5fb82e323fe495c775.tar.gz
pesto-295dd897297722d07ec2ce5fb82e323fe495c775.tar.bz2
pesto-295dd897297722d07ec2ce5fb82e323fe495c775.zip
GHC 8.8, cabal 3, pandoc 2.10 compatibility
Move files around to separate Pesto (the library) and Pesto (the executables). Fixes for pandoc API changes.
Diffstat (limited to 'src/Codec/Pesto/Serialize.lhs')
-rw-r--r--src/Codec/Pesto/Serialize.lhs70
1 files changed, 0 insertions, 70 deletions
diff --git a/src/Codec/Pesto/Serialize.lhs b/src/Codec/Pesto/Serialize.lhs
deleted file mode 100644
index f07e871..0000000
--- a/src/Codec/Pesto/Serialize.lhs
+++ /dev/null
@@ -1,70 +0,0 @@
-Serializing
------------
-
-.. class:: nodoc
-
-> module Codec.Pesto.Serialize (serialize) where
-> import Data.Char (isSpace, isLetter)
-> import Data.Ratio (numerator, denominator)
->
-> import {-# SOURCE #-} Codec.Pesto.Parse
-
-> class Serializeable a where
-> serialize :: a -> String
-
-.. class:: todo
-
-- Add instance for graph
-- use :math:`\mathcal{O}(1)` string builder
-
-Finally transform linear stream of instructions into a string again:
-
-> instance Serializeable a => Serializeable [a] where
-> serialize ops = unlines $ map serialize ops
-
-> instance Serializeable Instruction where
-> serialize (Annotation s) = quote '(' ')' s
-> serialize (Ingredient q) = '+':serialize q
-> serialize (Tool q) = '&':serialize q
-> serialize (Action s) = quote '[' ']' s
-> serialize (Reference q) = '*':serialize q
-> serialize (Result q) = '>':serialize q
-> serialize (Alternative q) = '|':serialize q
-> serialize (Directive s) = '%':serializeQstr s
-> serialize (Unknown s) = s
-
-> instance Serializeable Quantity where
-> serialize (Quantity a b "") = serialize a ++ " " ++ serializeQstr b
-> serialize (Quantity (Exact (AmountStr "")) "" c) = serializeQstr c
-> serialize (Quantity a "" c) = serialize a ++ " _ " ++ serializeQstr c
-> serialize (Quantity a b c) = serialize a ++ " " ++ serializeQstr b ++ " " ++ serializeQstr c
-
-> instance Serializeable Approximately where
-> serialize (Range a b) = serialize a ++ "-" ++ serialize b
-> serialize (Approx a) = '~':serialize a
-> serialize (Exact a) = serialize a
-
-There are two special cases here, both for aesthetic reasons:
-
-1) If the denominator is one we can just skip printing it, because
- :math:`\frac{2}{1} = 2` and
-2) if the numerator is larger than the denominator use mixed fraction notation,
- because :math:`\frac{7}{2} = 3+\frac{1}{2}`
-
-> instance Serializeable Amount where
-> serialize (AmountRatio a) | denominator a == 1 = show (numerator a)
-> serialize (AmountRatio a) | numerator a > denominator a =
-> show full ++ "/" ++ show num ++ "/" ++ show denom
-> where
-> full = numerator a `div` denom
-> num = numerator a - full * denom
-> denom = denominator a
-> serialize (AmountRatio a) = show (numerator a) ++ "/" ++ show (denominator a)
-> serialize (AmountStr s) = serializeQstr s
-
-> serializeQstr "" = "_"
-> serializeQstr s | (not . isLetter . head) s || hasSpaces s = quote '"' '"' s
-> serializeQstr s = s
-> hasSpaces = any isSpace
-> quote start end s = [start] ++ concatMap (\c -> if c == end then ['\\', end] else [c]) s ++ [end]
-