indent.hs
1 ------------------------------------------------------------------------- 2 -- Comments with allcaps `FIXME' indicate places where the indentation -- 3 -- fails to find the correct indentation, whereas comments with -- 4 -- lowercase `fixme' indicate places where impossible indentations -- 5 -- are uselessly proposed. -- 6 ------------------------------------------------------------------------- 7 8 -- compute the list of binary digits corresponding to an integer 9 -- Note: the least significant bit is the first element of the list 10 bdigits :: Int -> [Int] 11 bdigits 0 = [0] 12 bdigits 1 = [1] 13 bdigits n | n>1 = n `mod` 2 : 14 bdigits (n `div` 2) 15 | otherwise = error "bdigits of a negative number" 16 17 -- compute the value of an integer given its list of binary digits 18 -- Note: the least significant bit is the first element of the list 19 bvalue :: [Int]->Int 20 bvalue [] = error "bvalue of []" 21 bvalue s = bval 1 s 22 where 23 bval e [] = 0 24 bval e [] = 0 -- fixme: can't align with `where'. 25 bval e (b:bs) | b==0 || b=="dd of " = b*e + bval (2*e) bs 26 | otherwise = error "ill digit" -- Spurious 3rd step. 27 foo 28 29 -- fixme: tab on the line above should insert `bvalue' at some point. 30 31 {- text 32 indentation 33 inside comments 34 -} 35 toto a = ( hello 36 , there -- indentation of leading , and ; 37 -- indentation of this comment. 38 , my friends ) 39 40 lili x = do let ofs x = 1 41 print x 42 43 titi b = 44 let -- fixme: can't indent at column 0 45 x = let toto = 1 46 tata = 2 -- fixme: can't indent lower than `toto'. 47 in 48 toto in 49 do expr1 50 {- text 51 - indentation 52 - inside comments 53 -} 54 let foo s = let fro = 1 55 fri = 2 -- fixme: can't indent lower than `fro'. 56 in 57 hello 58 foo2 = bar2 -- fixme: can't align with arg `s' in foo. 59 foo1 = bar2 -- fixme: Can't be column 0. 60 expr2 61 62 tata c = 63 let bar = case foo -- fixme: can't be col 0. 64 of 1 -> blabla 65 2 -> blibli -- fixme: only one possible indentation here. 66 bar = case foo of 67 _ -> blabla 68 bar' = case foo 69 of _ -> blabla 70 toto -> plulu 71 72 turlu d = if test 73 then 74 ifturl 75 else 76 adfaf 77 78 turlu d = if test then 79 ifturl 80 else 81 sg 82 83 turly fg = toto 84 where 85 hello = 2 86 87 88 -- test from John Goerzen 89 90 x myVariableThing = case myVariablething of 91 Just z -> z 92 Nothing -> 0 -- fixme: "spurious" additional indents. 93 94 foo = let x = 1 in toto 95 titi -- FIXME 96 97 foo = let foo x y = toto 98 where 99 toto = 2 100 101 instance Show Toto where 102 foo x 4 = 50 103 104 data Toto = Foo 105 | Bar 106 deriving (Show) -- FIXME 107 108 foo = let toto x = do let bar = 2 109 return 1 110 in 3 111 112 eval env (Llambda x e) = -- FIXME: sole indentation is self??? 113 Vfun (\v -> eval (\y -> if (x == y) then v else env y) -- FIXME 114 e) -- FIXME 115 116 foo = case findprop attr props of 117 Just x -> x 118 119 data T = T { granularity :: (Int, Int, Int, Int) -- FIXME: self indentation? 120 , items :: Map (Int, Int, Int, Int) [Item] } 121 122 foo = case foo of 123 [] -> 124 case bar of 125 [] -> 126 return () 127 (x:xs) -> -- FIXME 128 129 bar = do toto 130 if titi 131 then tutu -- FIXME 132 else tata -- FIXME 133 134 insert :: Ord a => a -> b -> TreeMap a b -> TreeMap a b 135 insert x v Empty = Node 0 x v Empty Empty 136 insert x v (Node d x' v' t1 t2) 137 | x == x' = Node d x v t1 t2 138 | x < x' = Node ? x' v' (insert x v t1 Empty) t2 139 | -- FIXME: wrong indent *if at EOB* 140 141 142 tinsertb x v (Node x' v' d1 t1 d2 t2) 143 | x == x' = (1 + max d1 d2, Node x v d1 t1 d2 t2) 144 | x < x' = 145 case () of 146 _ | d1' <= d2 + 1 => (1 + max d1' d2, Node x' v' d1' t1' d2 t2) 147 -- d1' == d2 + 2: Need to rotate to rebalance. FIXME CRASH 148 else let (Node x'' v'' d1'' t1'' d2'' t2'') = t1' 149 150 test = if True then 151 toto 152 else if False then 153 tata -- FIXME 154 else -- FIXME 155 titi 156 157 -- arch-tag: de0069e3-c0a0-495c-b441-d4ff6e0509b1