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
{- |
     Author  : Kai-Oliver Prott
     Version : August 2018

     Datatype and operations to handle SpanInfos.
-}





module Curry.SpanInfo where

import Curry.Span

data SpanInfo = SpanInfo Span [Span] -- ^ Span for the whole entity
                                     -- and a list of minor sub-spans,
                                     -- e.g. keywords.
              | NoSpanInfo
  deriving (Eq, Show, Read)

-- | A class for easy access to SpanInfos
class HasSpanInfo a where
  getSpanInfo :: a -> SpanInfo
  setSpanInfo :: SpanInfo -> a -> a

instance HasSpanInfo SpanInfo where
  getSpanInfo = id
  setSpanInfo = const

-- | Get the span of the whole entity
getSrcSpan :: HasSpanInfo a
           => a    -- ^ The entity with SpanInfos
           -> Span -- ^ Whole span of that entity
getSrcSpan a = case getSpanInfo a of
  NoSpanInfo   -> NoSpan
  SpanInfo s _ -> s

-- | Get the src info points of the entity
getSrcInfoPoints :: HasSpanInfo a
                 => a     -- ^ The entity with SpanInfos
                 -> [Span] -- ^ SrcInfoPoints
getSrcInfoPoints a = case getSpanInfo a of
  NoSpanInfo    -> []
  SpanInfo _ ss -> ss