| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Symantic.Document.Plain
Synopsis
- newtype Plain d = Plain {
- unPlain :: PlainInh -> PlainState d -> ((d -> d, PlainState d) -> PlainFit d) -> PlainFit d
- runPlain :: Monoid d => Plain d -> d
- data PlainState d = PlainState {}
- defPlainState :: PlainState d
- data PlainInh = PlainInh {
- plainInh_width :: !(Maybe Column)
- plainInh_justify :: !Bool
- plainInh_indent :: !Width
- defPlainInh :: PlainInh
- type PlainFit d = (d -> d) -> (d -> d) -> d
- data PlainChunk d
- runPlainChunk :: Spaceable d => PlainChunk d -> d
- flushLine :: Spaceable d => Plain d
- collapseSpaces :: PlainChunk d -> PlainChunk d
- joinLine :: Spaceable d => PlainInh -> PlainState d -> d
- countWords :: [PlainChunk d] -> Natural
- justifyPadding :: Natural -> Natural -> [Natural]
- padPlainLineInits :: Spaceable d => Width -> (Natural, Natural, [PlainChunk d]) -> Line d
- joinPlainLine :: Monoid d => Spaceable d => [PlainChunk d] -> d
- padPlainLine :: Spaceable d => [PlainChunk d] -> [Width] -> d
Type Plain
Church encoded for performance concerns.
Kind like ParsecT in megaparsec but a little bit different
due to the use of PlainFit for implementing breakingSpace correctly
when in the left hand side of (<>).
Prepending is done using continuation, like in a difference list.
Constructors
| Plain | |
Fields
| |
Instances
Type PlainState
data PlainState d Source #
Constructors
| PlainState | |
Fields
| |
Instances
| Show d => Show (PlainState d) Source # | |
Defined in Symantic.Document.Plain Methods showsPrec :: Int -> PlainState d -> ShowS # show :: PlainState d -> String # showList :: [PlainState d] -> ShowS # | |
defPlainState :: PlainState d Source #
Type PlainInh
Constructors
| PlainInh | |
Fields
| |
Type PlainFit
type PlainFit d = (d -> d) -> (d -> d) -> d Source #
Double continuation to qualify the returned document
as fitting or overflowing the given plainInh_width.
It's like ( in a normal style
(a non continuation-passing-style).Bool,d)
Type PlainChunk
data PlainChunk d Source #
Constructors
| PlainChunk_Ignored d | Ignored by the justification but kept in place. Used for instance to put ANSI sequences. |
| PlainChunk_Word (Word d) | |
| PlainChunk_Spaces Width |
|
Instances
| Show d => Show (PlainChunk d) Source # | |
Defined in Symantic.Document.Plain Methods showsPrec :: Int -> PlainChunk d -> ShowS # show :: PlainChunk d -> String # showList :: [PlainChunk d] -> ShowS # | |
| Lengthable d => Lengthable (PlainChunk d) Source # | |
Defined in Symantic.Document.Plain | |
| From [SGR] d => From [SGR] (PlainChunk d) Source # | |
Defined in Symantic.Document.Plain Methods from :: [SGR] -> PlainChunk d Source # | |
runPlainChunk :: Spaceable d => PlainChunk d -> d Source #
flushLine :: Spaceable d => Plain d Source #
Commit plainState_buffer upto there, so that it won't be justified.
collapseSpaces :: PlainChunk d -> PlainChunk d Source #
countWords :: [PlainChunk d] -> Natural Source #
( returns the number of words in countWords ps)(ps)
clearly separated by spaces.
justifyPadding :: Natural -> Natural -> [Natural] Source #
( returns the padding lengths
to reach justifyPadding a b)(a) in (b) pads,
using the formula: (a
where == m*(q + q+1) + ('r'-'m)*(q+1) + (b'-'r'-'m)*q)(q+1) and (q) are the two padding lengths used and (m = min (b-r) r).
A simple implementation of justifyPadding could be:
justifyPadding a b =
join (replicate m [q,q+1])
<> (replicate (r-m) (q+1)
<> (replicate ((b-r)-m) q
where
(q,r) = adivModb
m = min (b-r) r
padPlainLineInits :: Spaceable d => Width -> (Natural, Natural, [PlainChunk d]) -> Line d Source #
joinPlainLine :: Monoid d => Spaceable d => [PlainChunk d] -> d Source #
Just concat PlainChunks with no justification.
padPlainLine :: Spaceable d => [PlainChunk d] -> [Width] -> d Source #
Interleave PlainChunks with Widths from justifyPadding.