1 {-# LANGUAGE DeriveDataTypeable #-}
2 module Hcompta.LCC.Source where
4 import Data.Data (Data(..))
6 import Data.List.NonEmpty (NonEmpty)
7 import Data.Ord (Ord(..))
8 import Data.Typeable (Typeable)
9 import Data.Word (Word)
10 import System.IO (FilePath)
11 import Text.Show (Show)
13 import Language.Symantic hiding (Source(..))
14 import qualified Language.Symantic as Sym
16 -- import Hcompta.LCC.Compta (Compta)
19 -- | A 'Source' usable when using 'readCompta'.
22 | SourceRead_Span (Span SourcePath)
24 | Source_AST_Term (AST_Term (Source inp ss) ({-Proxy (Compta (Source inp ss) ss) ':-} ss))
25 | Source_AST_Type (AST_Type (Source inp ss))
26 | Source_Kind (KindK (Source inp ss))
27 | Source_Type (TypeVT (Source inp ss))
32 type instance Source_Input SourceRead = SourcePath
33 instance Sym.Source SourceRead where
34 noSource = SourceRead_Less
35 instance SourceInj (Span SourcePath) SourceRead where
36 sourceInj = SourceRead_Span
41 type instance Source_Input (Source inp ss) = inp
43 instance SourceInj SourcePath (Source inp ss) where
44 sourceInj = Source_Path
45 instance SourceInj (Span inp) (Source inp ss) where
46 sourceInj = Source_Input
47 instance SourceInj (AST_Term (Source inp ss) ({-Proxy (Compta (Source inp ss) ss) ':-} ss)) (Source inp ss) where
48 sourceInj = Source_AST_Term
49 instance SourceInj (AST_Type (Source inp ss)) (Source inp ss) where
50 sourceInj = Source_AST_Type
51 instance SourceInj (KindK (Source inp ss)) (Source inp ss) where
52 sourceInj = Source_Kind
53 instance SourceInj (TypeVT (Source inp ss)) (Source inp ss) where
54 sourceInj = Source_Type
59 = SourcePos FilePath {-# UNPACK #-} !PosFile {-# UNPACK #-} !PosFile
60 deriving (Data, Eq, Ord, Show, Typeable)
62 initialPos :: FilePath -> SourcePos
63 initialPos p = SourcePos p (PosFile 0) (PosFile 0)
65 -- * Type 'SourcePath'
66 type SourcePath = NonEmpty SourcePos
69 newtype PosFile = PosFile (Word)
70 deriving (Data, Eq, Ord, Show, Typeable)
72 -- ** Type 'SourceRange'
74 = SourceRange SourcePos SourcePos
75 deriving (Data, Eq, Ord, Show, Typeable)