1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
module Check.AST.Indent.ListTuple where

import Curry.SpanInfo
import Curry.Span
import Curry.Position
import Curry.Types
import Curry.Ident
import Text.Pretty

import Types

-- applies actual check on List constructs
checkListTuple :: Rhs a -> Int -> CSM ()
checkListTuple e i =
  case e of
    (SimpleRhs sI (List sC _ exps@(l:ls)) _) -> checkListTuple' sI sC exps i "list"
    (SimpleRhs sI (Tuple sC exps) _)  -> checkListTuple' sI sC exps i "tuple"
    _                    -> return ()

-- check indentation and alignment if declaration not in one line
checkListTuple' :: SpanInfo -> SpanInfo -> [Expression a] -> Int -> String -> CSM ()
checkListTuple' (SpanInfo rhsSp@(Span (Position eql1 eqc1) (Position eql2 eqc2)) _)
                (SpanInfo (Span (Position l1 c1) (Position l2 c2)) symbSpans)
                (exp:exps)
                i
                s
                = do
  unlessM (eql1 == l1)
    (unlessM ((i+2) == c1)
      (report (Message rhsSp
                       (colorizeKey (s ++ " declaration") <+> text "wrong formatting")
                       ( text "either write"
                       <+> colorizeKey "right-hand-side"
                       <+> text "right after the equation sign or start in new line and 2 indentation"
                       )
              )
      )
    )
  unlessM (l1 == l2)
    (if (spanAlign symbSpans)
       then
         (unlessM (checkAlign getCol (getCol (getSpanInfo exp)) exps)
           (report (Message rhsSp
                       (colorizeKey (s ++ " elements") <+> text "not aligned")
                       ( text "align"
                       <+> colorizeKey "list elements"
                       )
                   )
           )
           )
       else
         (report (Message rhsSp
                       (colorizeKey (s ++ " symbols") <+> text "not aligned")
                       ( text "align"
                       <+> colorizeKey "("
                       <+> text "or"
                       <+> colorizeKey "["
                       <> text ","
                       <+> colorizeKey ")"
                       <+> text "or"
                       <+> colorizeKey "]"
                       <+> text "and"
                       <+> colorizeKey ","
                       )
                 )
         )
    )