module Quox.Name import public Data.SnocList import Data.List import Derive.Prelude %hide TT.Name %default total %language ElabReflection public export data BaseName = UN String -- user-given name %runElab derive "BaseName" [Eq, Ord] export Show BaseName where show (UN x) = x export baseStr : BaseName -> String baseStr (UN x) = x export FromString BaseName where fromString = UN public export record Name where constructor MakeName mods : SnocList String base : BaseName %runElab derive "Name" [Eq, Ord] export Show Name where show (MakeName mods base) = concat $ intersperse "." $ toList $ mods :< show base export FromString Name where fromString x = MakeName [<] (fromString x) public export %inline unq : BaseName -> Name unq = MakeName [<] export toDots : Name -> String toDots x = fastConcat $ cast $ map (<+> ".") x.mods :< baseStr x.base export fromList : List1 String -> Name fromList (x ::: xs) = go [<] x xs where go : SnocList String -> String -> List String -> Name go mods x [] = MakeName mods (UN x) go mods x (y :: ys) = go (mods :< x) y ys