Jump to content

ASCII art diagram converter: Difference between revisions

m
m (→‎Parsing: edited header)
Line 1,926:
process d = do
let l = length (head d)
unless (all ((l ==) . length) d) $ Left "Table is not aligned!"
Left "Table is not aligned!"
w <- readHLine (head d)
let rows = filter ((/= "+-") . nub) d
Line 1,934 ⟶ 1,933:
readHLine s = do
let cols = splitOn "--" s
unless (nub cols == ["+"]) $ Left ("Invalid header: " ++ s)
Left ("Invalid header: " ++ s)
return $ length cols - 1
 
readField s = do
let n = length s + 1
unless (n `mod` 3 == 0) $ Left ("Field is not aligned: " ++ s)
Left ("Field is not aligned: " ++ s)
return $ Field (filter (/= ' ') s) (n `div` 3) Nothing
 
Line 1,947 ⟶ 1,944:
let fields = filter (not.null) $ splitOn "|" s
row <- traverse readField fields
unless (sum (fieldSize <$> row) == n) $ Left $ "Fields are not aligned at row\n " ++ s
Left $ "Fields are not aligned at row\n " ++ s
return row</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.