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
{- |
    Module      :  Check.TypeExpr
    Description :  Check and validation for TypeExpr

    This module contains the check function
    and validation functions for TypeExpr.
    The messages are only saved if the check
    is switched ON in the config (`shallCheck Check`)
-}








module Check.TypeExpr (typeExprCheck) where

import AST.PositionUtils
import AST.Span          (Pos, start)
import AST.SpanAST
import Check.Types       (CheckF, Message (..))
import Config.Types      (Check (..))
import Config.ReadConfig (shallCheck)
import Utils             (condMsg)

--- ----------------------------------------------------------------------------
--- Check Function
--- ----------------------------------------------------------------------------

-- |Check TypeExpr
typeExprCheck :: CheckF TypeExpr
typeExprCheck te = case te of
  ArrowType _ s te2
    | shallCheck CTypeArrow && not (validArrowType (start s) te2)
      -> [Message (start s) "ArrowType: There is no blank behind the arrow."]
  _   -> []


--------------------------------------------------------------------------------
--- Validation Functions
--- ----------------------------------------------------------------------------

-- |ArrowType is valid if there's a blank behind the arrow
validArrowType :: Pos -> TypeExpr -> Bool
validArrowType p te2 = col p == ((col $ typeExprPos te2) - 3)
-- todo: recognize whether there is a blank before the arrow