diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-07-26 12:22:07 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-07-26 12:22:07 +0200 |
| commit | ce7652c6189b289ffbc749dc3d1ffb465c758c01 (patch) | |
| tree | e3f059ceb8fdaf3153d49d894d695fc5825021c5 /lib/Language/Elna/Location.hs | |
| parent | bf774475cc21cf7190144a5a9e16c2a72318f0bb (diff) | |
| download | elna-ce7652c6189b289ffbc749dc3d1ffb465c758c01.tar.gz | |
Add types for name analysis
Diffstat (limited to 'lib/Language/Elna/Location.hs')
| -rw-r--r-- | lib/Language/Elna/Location.hs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/Language/Elna/Location.hs b/lib/Language/Elna/Location.hs new file mode 100644 index 0000000..918ef46 --- /dev/null +++ b/lib/Language/Elna/Location.hs @@ -0,0 +1,58 @@ +module Language.Elna.Location + ( Identifier(..) + , Location(..) + , Node(..) + , showArrayType + ) where + +import Data.Hashable (Hashable(..)) +import Data.String (IsString(..)) +import Data.Text (Text) +import qualified Data.Text as Text +import Data.Word (Word32) + +data Location = Location + { line :: Word32 + , column :: Word32 + } deriving (Eq, Show) + +instance Semigroup Location + where + (Location thisLine thisColumn) <> (Location thatLine thatColumn) = Location + { line = thisLine + thatLine + , column = thisColumn + thatColumn + } + +instance Monoid Location + where + mempty = Location{ line = 1, column = 1 } + +data Node a = Node a Location + deriving (Eq, Show) + +instance Functor Node + where + fmap f (Node node location) = Node (f node) location + +newtype Identifier = Identifier { unIdentifier :: Text } + deriving Eq + +instance Show Identifier + where + show (Identifier identifier) = Text.unpack identifier + +instance IsString Identifier + where + fromString = Identifier . Text.pack + +instance Ord Identifier + where + compare (Identifier lhs) (Identifier rhs) = compare lhs rhs + +instance Hashable Identifier + where + hashWithSalt salt (Identifier identifier) = hashWithSalt salt identifier + +showArrayType :: Show a => Word32 -> a -> String +showArrayType elementCount typeName = concat + ["array[", show elementCount, "] of ", show typeName] |
