From aad99796e43d7f551a0b3035c09ec496321f53f1 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 6 Dec 2022 10:26:15 +0200 Subject: Implement record! and generate create fn --- src/Utils.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/Utils.hs') diff --git a/src/Utils.hs b/src/Utils.hs index b68de18..bcac58e 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -6,6 +6,7 @@ import Control.Monad.State import qualified Data.Map as M import qualified Data.List as L import qualified Data.Char as C +import qualified Data.Text as T -- TYPES @@ -130,6 +131,8 @@ instance (Show Token) where type Purity = Bool type LFunction = AST -> LContext AST +type LRecord = M.Map String AST + data ASTNode = ASTInteger Int | ASTDouble Double @@ -140,6 +143,7 @@ data ASTNode | ASTFunctionCall [AST] | ASTHashMap (M.Map AST AST) | ASTFunction Purity LFunction + | ASTRecord String LRecord | ASTUnit | ASTHole @@ -167,6 +171,9 @@ instance (Show ASTNode) where show (ASTFunction isPure _) = case isPure of True -> "" False -> "" + show (ASTRecord identifier record) = + let assocsStrList = map (\(k, v) -> k ++ ":" ++ show v) (M.assocs record) + in "(" ++ identifier ++ " " ++ L.intercalate " " assocsStrList ++ ")" show ASTUnit = "" show ASTHole = "" @@ -286,3 +293,11 @@ astPos AST { astRow = r, astColumn = c, astFileName = f } = f ++ ":" ++ show r + tokenPos :: Token -> String tokenPos Token { tokenRow = r, tokenColumn = c, tokenFileName = f } = f ++ ":" ++ show r ++ ":" ++ show c + +separateNsIdPart :: String -> (String, String) +separateNsIdPart identifier = + let t = T.pack identifier + parts = T.splitOn (T.pack "/") t + nsPartText = T.concat $ L.init parts + idPartText = L.last parts + in (T.unpack nsPartText, T.unpack idPartText) -- cgit v1.3