Skip to content

Commit

Permalink
Merge pull request #249 from edwinb/refl-names
Browse files Browse the repository at this point in the history
Reflect 'display names' and record field names
  • Loading branch information
edwinb authored Jun 7, 2020
2 parents a0d9ce2 + d5e4dec commit 6898965
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions libs/base/Language/Reflection/TT.idr
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ data Constant
| WorldType

public export
data Name = UN String
| MN String Int
| NS (List String) Name
data Name = UN String -- user defined name
| MN String Int -- machine generated name
| NS (List String) Name -- name in a namespace
| DN String Name -- a name and how to display it
| RF String -- record field name

export
Show Name where
Expand All @@ -61,6 +63,8 @@ Show Name where
showSep sep (x :: xs) = x ++ sep ++ showSep sep xs
show (UN x) = x
show (MN x y) = "{" ++ x ++ ":" ++ show y ++ "}"
show (DN str y) = str
show (RF n) = "." ++ n

public export
data Count = M0 | M1 | MW
Expand Down
14 changes: 14 additions & 0 deletions src/Core/Reflect.idr
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ Reify Name where
=> do ns' <- reify defs !(evalClosure defs ns)
n' <- reify defs !(evalClosure defs n)
pure (NS ns' n')
(NS _ (UN "DN"), [str, n])
=> do str' <- reify defs !(evalClosure defs str)
n' <- reify defs !(evalClosure defs n)
pure (DN str' n')
(NS _ (UN "RF"), [str])
=> do str' <- reify defs !(evalClosure defs str)
pure (RF str')
_ => cantReify val "Name"
reify defs val = cantReify val "Name"

Expand All @@ -244,6 +251,13 @@ Reflect Name where
= do ns' <- reflect fc defs lhs env ns
n' <- reflect fc defs lhs env n
appCon fc defs (reflectiontt "NS") [ns', n']
reflect fc defs lhs env (DN str n)
= do str' <- reflect fc defs lhs env str
n' <- reflect fc defs lhs env n
appCon fc defs (reflectiontt "DN") [str', n']
reflect fc defs lhs env (RF x)
= do x' <- reflect fc defs lhs env x
appCon fc defs (reflectiontt "RF") [x']
reflect fc defs lhs env (Resolved i)
= case !(full (gamma defs) (Resolved i)) of
Resolved _ => cantReflect fc "Name"
Expand Down

0 comments on commit 6898965

Please sign in to comment.