1
module WASHExpression where
6
import qualified WASHUtil
10
code :: FLAGS -> [CodeFrag] -> ShowS
12
code flags (x:xs) = code' flags x . code flags xs
14
code' :: FLAGS -> CodeFrag -> ShowS
15
code' flags (HFrag h) =
17
code' flags (EFrag e) =
18
runOut $ element flags e
19
code' flags (CFrag cnts) =
21
runOut (contents flags [] cnts) .
23
code' flags (AFrag attrs) =
25
WASHUtil.itemList (attribute flags) "CGI.empty" " >> " attrs .
27
code' flags (VFrag var) =
29
code' flags _ = error "Unknown type: code"
31
outMode :: Mode -> Out ()
32
outMode = outShowS . showMode
34
showMode :: Mode -> ShowS
36
showMode S = showString "_T"
37
showMode F = showString "_S"
39
element :: FLAGS -> Element -> Out [String]
40
element flags (Element mode nm ats cnt et) =
44
when (generateBT flags) $ outMode mode
46
outShowS $ attributes flags ats
47
rvs <- contents flags [] cnt
51
outRVS :: [String] -> Out ()
52
outRVS [] = outString "()"
58
where g x = do { outChar ','; outString x; }
60
outRVSpat :: [String] -> Out ()
61
outRVSpat [] = outString "(_)"
62
outRVSpat xs = outRVS xs
64
contents :: FLAGS -> [String] -> [Content] -> Out [String]
65
contents flags inRVS cts =
72
do rvs <- content flags ct
80
contents flags inRVS cts
86
do outString " >>= \\ "
89
contents flags (rvs ++ inRVS) cts
91
content :: FLAGS -> Content -> Out [String]
92
content flags (CElement elem) =
94
content flags (CText txt) =
97
content flags (CCode (VFrag var:c)) =
98
do outShowS $ (showChar '(' . code flags c . showChar ')')
100
content flags (CCode c) =
101
do outShowS $ (showChar '(' . code flags c . showChar ')')
103
content flags (CComment cc) =
104
do outShowS $ (showString "return (const () " . shows cc . showChar ')')
106
content flags (CReference txt) =
110
error $ "Unknown type: content -- " ++ (show c)
112
text :: FLAGS -> Text -> Out [String]
114
do outString "CGI.rawtext"
115
when (generateBT flags) $ outMode (textMode txt)
117
outs (textString txt)
120
attributes :: FLAGS -> [Attribute] -> ShowS
121
attributes flags atts =
126
attribute flags att .
130
attribute :: FLAGS -> Attribute -> ShowS
131
attribute flags (Attribute m n v) =
132
showString "(CGI.attr" .
133
(if generateBT flags then (attrvalueBT m v) else id) .
139
attribute flags (AttrPattern pat) =
143
attribute flags a = error $ "Unknown type: attribute -- " ++ (show a)
145
attrvalue :: AttrValue -> ShowS
146
attrvalue (AText t) =
148
attrvalue (ACode c) =
152
attrvalue a = error $ "Unknown type: attrvalue -- " ++ (show a)
154
attrvalueBT :: Mode -> AttrValue -> ShowS
156
attrvalueBT m (AText _) = showMode m . showChar 'S'
157
attrvalueBT m (ACode _) = showMode m . showChar 'D'
158
attrvalueBT m a = error $ "Unknown type: attrvalueBT -- " ++ (show a)