128 | 128 |
Alias a -> pfx <> goAlias c a (cont rest)
|
129 | 129 |
|
130 | 130 |
_ -> error ("putNode: expected node-start event instead of " ++ show t)
|
131 | |
where
|
|
131 |
where -- TODO flow
|
132 | 132 |
pfx | sol = mempty
|
133 | 133 |
| BlockKey <- c = mempty
|
134 | 134 |
| otherwise = T.B.singleton ' '
|
|
191 | 191 |
|
192 | 192 |
Plain -- empty scalars
|
193 | 193 |
| t == "", Nothing <- anc, Tag Nothing <- tag -> contEol -- not even node properties
|
194 | |
| sol, t == "" -> anchorTag0 anc tag (if c == BlockKey then ws <> cont else contEol)
|
195 | |
| t == "", BlockKey <- c -> anchorTag0 anc tag (if c == BlockKey then ws <> cont else contEol)
|
|
194 |
| sol, t == "" -> anchorTag0 anc tag (if c == BlockKey then ws <> cont else contEol)
|
|
195 |
| t == "", BlockKey <- c -> anchorTag0 anc tag (if c == BlockKey then ws <> cont else contEol) -- unnecessary if
|
196 | 196 |
| t == "" -> anchorTag'' (Left ws) anc tag contEol
|
197 | 197 |
|
198 | 198 |
Plain -> pfx $
|
|
207 | 207 |
|
208 | 208 |
DoubleQuoted -> pfx $ T.B.singleton '"' <> T.B.fromText (escapeDQ t) <> T.B.singleton '"' <> contEol
|
209 | 209 |
|
210 | |
-- block-style
|
211 | |
Folded --- FIXME/TODO: T.lines eats trailing whitespace; check this works out properly!
|
212 | |
| T.null t -> pfx $ ">" <> eol <> cont
|
213 | |
| hasLeadSpace t -> pfx $ (if T.last t == '\n' then ">2" else ">2-") <> g (insFoldNls' $ T.lines t) cont
|
214 | |
| T.last t == '\n' -> pfx $ T.B.singleton '>' <> g (insFoldNls' $ T.lines t) cont
|
215 | |
| otherwise -> pfx $ ">-" <> g (insFoldNls' $ T.lines t) cont
|
216 | |
|
217 | |
Literal -- TODO: indent-indicator for leading space payloads
|
218 | |
| T.null t -> pfx $ "|" <> eol <> cont
|
219 | |
| "\n" == t -> pfx $ "|+" <> g (T.lines t) cont
|
220 | |
| hasLeadSpace t -> pfx $ "|2" <> g (T.lines t) cont
|
221 | |
| "\n\n" `T.isSuffixOf` t -> pfx $ "|+" <> g (T.lines t) cont
|
222 | |
| "\n" `T.isSuffixOf` t -> pfx $ T.B.singleton '|' <> g (T.lines t) cont
|
223 | |
| otherwise -> pfx $ "|-" <> g (T.lines t) cont
|
224 | |
|
225 | |
where
|
226 | |
hasLeadSpace t' = T.isPrefixOf " " . T.dropWhile (== '\n') $ t'
|
|
210 |
-- block style
|
|
211 |
Folded chm iden -> pfx $ ">" <> goChomp chm <> goDigit iden <> g (insFoldNls' $ T.lines t) (fromEnum iden) cont
|
|
212 |
|
|
213 |
Literal chm iden -> pfx $ "|" <> goChomp chm <> goDigit iden <> g (T.lines t) (fromEnum iden) cont
|
|
214 |
|
|
215 |
where
|
|
216 |
goDigit iden = let ch = C.intToDigit.fromEnum $ iden
|
|
217 |
in if(ch == '0') then mempty else T.B.singleton ch
|
|
218 |
|
|
219 |
goChomp chm = case chm of
|
|
220 |
Strip -> T.B.singleton '-'
|
|
221 |
Clip -> mempty
|
|
222 |
Keep -> T.B.singleton '+'
|
227 | 223 |
|
228 | 224 |
pfx cont' = (if sol || c == BlockKey then mempty else ws) <> anchorTag'' (Right ws) anc tag cont'
|
229 | 225 |
|
|
235 | 231 |
| doEol = eol <> cont
|
236 | 232 |
| otherwise = cont
|
237 | 233 |
|
238 | |
g [] cont' = eol <> cont'
|
239 | |
g (x:xs) cont'
|
240 | |
| T.null x = eol <> g xs cont'
|
241 | |
| otherwise = eol <> mkInd n <> T.B.fromText x <> g xs cont'
|
|
234 |
g [] _ cont' = eol <> cont'
|
|
235 |
g (x:xs) dig cont'
|
|
236 |
| T.null x = eol <> g xs dig cont'
|
|
237 |
| dig == 0 = eol <> mkInd (n) <> T.B.fromText x <> g xs dig cont'
|
|
238 |
| otherwise = eol <> mkInd (n-1) <> mkInd' dig <> T.B.fromText x <> g xs dig cont'
|
242 | 239 |
|
243 | 240 |
g' [] cont' = cont'
|
244 | 241 |
g' (x:xs) cont' = eol <> mkInd (n+1) <> T.B.fromText x <> g' xs cont'
|
|
250 | 247 |
|
251 | 248 |
|
252 | 249 |
isSmallKey (Alias _ : _) = True
|
253 | |
isSmallKey (Scalar _ _ Folded _ : _) = False
|
254 | |
isSmallKey (Scalar _ _ Literal _ : _) = False
|
|
250 |
isSmallKey (Scalar _ _ (Folded _ _) _: _) = False
|
|
251 |
isSmallKey (Scalar _ _ (Literal _ _) _: _) = False
|
255 | 252 |
isSmallKey (Scalar _ _ _ _ : _) = True
|
256 | 253 |
isSmallKey (SequenceStart _ _ _ : _) = False
|
257 | 254 |
isSmallKey (MappingStart _ _ _ : _) = False
|
|
289 | 286 |
| l < 0 = error (show l)
|
290 | 287 |
| otherwise = T.B.fromText (T.replicate l " ")
|
291 | 288 |
|
|
289 |
mkInd' 0 = mempty
|
|
290 |
mkInd' 1 = " "
|
|
291 |
mkInd' 2 = " "
|
|
292 |
mkInd' 3 = " "
|
|
293 |
mkInd' 4 = " "
|
|
294 |
mkInd' 5 = " "
|
|
295 |
mkInd' 6 = " "
|
|
296 |
mkInd' 7 = " "
|
|
297 |
mkInd' 8 = " "
|
|
298 |
mkInd' 9 = " "
|
|
299 |
mkInd' l = error ("Impossible Indentation-level" ++ show l)
|
292 | 300 |
|
293 | 301 |
eol = T.B.singleton '\n'
|
294 | 302 |
ws = T.B.singleton ' '
|
|
341 | 349 |
-- FIXME: check single-quoted strings with leading '\n' or trailing '\n's
|
342 | 350 |
insFoldNls :: [Text] -> [Text]
|
343 | 351 |
insFoldNls [] = []
|
344 | |
insFoldNls (z:zs)
|
345 | |
| all T.null (z:zs) = "" : z : zs -- HACK
|
|
352 |
insFoldNls z0@(z:zs)
|
|
353 |
| all T.null z0 = "" : z0 -- HACK
|
346 | 354 |
| otherwise = z : go zs
|
347 | 355 |
where
|
348 | 356 |
go [] = []
|