]> Git — Sourcephile - comptalang.git/blob - lcc/Hcompta/LCC/Source.hs
Commit old WIP.
[comptalang.git] / lcc / Hcompta / LCC / Source.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 module Hcompta.LCC.Source where
3
4 import Data.Data (Data(..))
5 import Data.Eq (Eq)
6 import Data.Int (Int)
7 import Data.List.NonEmpty (NonEmpty)
8 import Data.Ord (Ord(..))
9 import Data.Typeable (Typeable)
10 import System.IO (FilePath)
11 import Text.Show (Show)
12
13 import Language.Symantic hiding (Source(..))
14 import qualified Language.Symantic as Sym
15
16 -- import Hcompta.LCC.Compta (Compta)
17
18 -- * Type 'Source'
19 -- | A 'Source' usable when using 'readCompta'.
20 data SourceRead
21 = SourceRead_Less
22 | SourceRead_Span (Span SourcePath)
23 {-
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))
28 | Source_Term
29 -}
30 deriving (Eq, Show)
31
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
37
38
39
40 {-
41 type instance Source_Input (Source inp ss) = inp
42
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
55 -}
56
57 -- * Type 'SourcePos'
58 data SourcePos
59 = SourcePos FilePath {-# UNPACK #-} !PosFile {-# UNPACK #-} !PosFile
60 deriving (Data, Eq, Ord, Show, Typeable)
61
62 initialPos :: FilePath -> SourcePos
63 initialPos p = SourcePos p (PosFile 0) (PosFile 0)
64
65 -- * Type 'SourcePath'
66 type SourcePath = NonEmpty SourcePos
67
68 -- ** Type 'PosFile'
69 newtype PosFile = PosFile Int
70 deriving (Data, Eq, Ord, Show, Typeable)
71
72 -- ** Type 'SourceRange'
73 data SourceRange
74 = SourceRange SourcePos SourcePos
75 deriving (Data, Eq, Ord, Show, Typeable)
76