git @ Cat's Eye Technologies Falderal / 71b146c
Get closer to proper identity formatting of a Falderal file. catseye 10 years ago
3 changed file(s) with 24 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
5353 outputText <- return $ formatLines (formatLine) lines
5454 putStr outputText
5555
56 dumpLine x = (show x) ++ "\n"
57
5658 formatLines formatter lines = foldl (++) "" (map (formatter) lines)
57
58 -- TODO: find out what's stripping out empty lines and stop it!
5959
6060 formatLine (TestInput text) =
6161 (prefixEachLine "| " text)
7070 formatLine (SectionHeading text) =
7171 text ++ "\n" ++ (take (length text) (repeat '-')) ++ "\n"
7272
73 -- Fix lines so that it acts on "" appropriately
74
75 allLines x =
76 case (lines x) of
77 [] -> [""]
78 other -> other
79
7380 prefixEachLine prefix text =
74 foldl (++) "" (map (\x -> prefix ++ x ++ "\n") (lines text))
81 foldl (++) "" (map (\x -> prefix ++ x ++ "\n") (allLines text))
4545 | LiteralText String
4646 | QuotedCode String
4747 | SectionHeading String
48 | Placeholder
4849 deriving (Show, Eq, Ord)
4950
5051 -- TODO: move these datatypes to a common module?
7576 transformLines lines =
7677 let
7778 lines' = map classifyLine lines
78 lines'' = findSectionHeadings lines' (LiteralText "0")
79 lines'' = findSectionHeadings lines' Placeholder
80 lines''' = coalesceLines lines'' Placeholder
7981 in
80 coalesceLines lines'' (LiteralText "0")
82 stripPlaceholders lines'''
83
84 stripPlaceholders [] = []
85 stripPlaceholders (Placeholder:rest) = stripPlaceholders rest
86 stripPlaceholders (other:rest) = other:(stripPlaceholders rest)
8187
8288 classifyLine line
8389 | prefix == "| " = TestInput suffix
5757 diff -u expected.txt actual.txt
5858 E=$?
5959 rm -f expected.txt actual.txt
60
61 ghc Test/Falderal/Formatter.hs -e 'formatFile "Test/Falderal/Demo.lhs"' >formatted.txt
62 diff -u Test/Falderal/Demo.lhs formatted.txt
63 E=$?
64 rm -f formatted.txt
65
6066 exit $E