55 lines
920 B
Idris
55 lines
920 B
Idris
module Quox.Name
|
|
|
|
import public Data.SnocList
|
|
import Data.List
|
|
import Generics.Derive
|
|
|
|
%hide TT.Name
|
|
|
|
%default total
|
|
%language ElabReflection
|
|
|
|
|
|
public export
|
|
data BaseName
|
|
= UN String -- user-given name
|
|
%runElab derive "BaseName" [Generic, Meta, Eq, Ord, DecEq]
|
|
|
|
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" [Generic, Meta, 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
|