MakeName ⇒ MkName for consistency
This commit is contained in:
parent
11b0ab6a25
commit
fca75377a0
7 changed files with 28 additions and 28 deletions
|
@ -43,14 +43,14 @@ Mods = SnocList String
|
||||||
|
|
||||||
public export
|
public export
|
||||||
record Name where
|
record Name where
|
||||||
constructor MakeName
|
constructor MkName
|
||||||
mods : Mods
|
mods : Mods
|
||||||
base : BaseName
|
base : BaseName
|
||||||
%runElab derive "Name" [Eq, Ord]
|
%runElab derive "Name" [Eq, Ord]
|
||||||
|
|
||||||
public export %inline
|
public export %inline
|
||||||
unq : BaseName -> Name
|
unq : BaseName -> Name
|
||||||
unq = MakeName [<]
|
unq = MkName [<]
|
||||||
|
|
||||||
||| add some namespaces to the beginning of a name
|
||| add some namespaces to the beginning of a name
|
||||||
public export %inline
|
public export %inline
|
||||||
|
@ -64,31 +64,31 @@ PBaseName = String
|
||||||
|
|
||||||
public export
|
public export
|
||||||
record PName where
|
record PName where
|
||||||
constructor MakePName
|
constructor MkPName
|
||||||
mods : Mods
|
mods : Mods
|
||||||
base : PBaseName
|
base : PBaseName
|
||||||
%runElab derive "PName" [Eq, Ord, PrettyVal]
|
%runElab derive "PName" [Eq, Ord, PrettyVal]
|
||||||
|
|
||||||
export %inline
|
export %inline
|
||||||
fromPName : PName -> Name
|
fromPName : PName -> Name
|
||||||
fromPName p = MakeName p.mods $ UN p.base
|
fromPName p = MkName p.mods $ UN p.base
|
||||||
|
|
||||||
export %inline
|
export %inline
|
||||||
toPName : Name -> PName
|
toPName : Name -> PName
|
||||||
toPName p = MakePName p.mods $ baseStr p.base
|
toPName p = MkPName p.mods $ baseStr p.base
|
||||||
|
|
||||||
export %inline
|
export %inline
|
||||||
fromPBaseName : PBaseName -> Name
|
fromPBaseName : PBaseName -> Name
|
||||||
fromPBaseName = MakeName [<] . UN
|
fromPBaseName = MkName [<] . UN
|
||||||
|
|
||||||
export
|
export
|
||||||
Show PName where
|
Show PName where
|
||||||
show (MakePName mods base) =
|
show (MkPName mods base) =
|
||||||
show $ concat $ intersperse "." $ toList $ mods :< base
|
show $ concat $ intersperse "." $ toList $ mods :< base
|
||||||
|
|
||||||
export Show Name where show = show . toPName
|
export Show Name where show = show . toPName
|
||||||
|
|
||||||
export FromString PName where fromString = MakePName [<]
|
export FromString PName where fromString = MkPName [<]
|
||||||
|
|
||||||
export FromString Name where fromString = fromPBaseName
|
export FromString Name where fromString = fromPBaseName
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ export
|
||||||
fromListP : List1 String -> PName
|
fromListP : List1 String -> PName
|
||||||
fromListP (x ::: xs) = go [<] x xs where
|
fromListP (x ::: xs) = go [<] x xs where
|
||||||
go : SnocList String -> String -> List String -> PName
|
go : SnocList String -> String -> List String -> PName
|
||||||
go mods x [] = MakePName mods x
|
go mods x [] = MkPName mods x
|
||||||
go mods x (y :: ys) = go (mods :< x) y ys
|
go mods x (y :: ys) = go (mods :< x) y ys
|
||||||
|
|
||||||
export %inline
|
export %inline
|
||||||
|
|
|
@ -75,7 +75,7 @@ parameters {auto _ : Functor m} (b : Var n -> m a) (f : PName -> m a)
|
||||||
(xs : Context' PatVar n)
|
(xs : Context' PatVar n)
|
||||||
private
|
private
|
||||||
fromBaseName : PBaseName -> m a
|
fromBaseName : PBaseName -> m a
|
||||||
fromBaseName x = maybe (f $ MakePName [<] x) b $
|
fromBaseName x = maybe (f $ MkPName [<] x) b $
|
||||||
Context.find (\y => y.name == Just x) xs
|
Context.find (\y => y.name == Just x) xs
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -124,7 +124,7 @@ qname = terminalMatch "name" `(Name n) `(n)
|
||||||
||| unqualified name
|
||| unqualified name
|
||||||
export
|
export
|
||||||
baseName : Grammar True PBaseName
|
baseName : Grammar True PBaseName
|
||||||
baseName = terminalMatch "unqualified name" `(Name (MakePName [<] b)) `(b)
|
baseName = terminalMatch "unqualified name" `(Name (MkPName [<] b)) `(b)
|
||||||
|
|
||||||
||| dimension constant (0 or 1)
|
||| dimension constant (0 or 1)
|
||||||
export
|
export
|
||||||
|
@ -152,7 +152,7 @@ qty fname = withLoc fname [|PQ qtyVal|]
|
||||||
export
|
export
|
||||||
exactName : String -> Grammar True ()
|
exactName : String -> Grammar True ()
|
||||||
exactName name = terminal "expected '\{name}'" $ \case
|
exactName name = terminal "expected '\{name}'" $ \case
|
||||||
Name (MakePName [<] x) => guard $ x == name
|
Name (MkPName [<] x) => guard $ x == name
|
||||||
_ => Nothing
|
_ => Nothing
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -113,13 +113,13 @@ makeIdBase mods str = joinBy "." $ toList $ mods :< str
|
||||||
|
|
||||||
export
|
export
|
||||||
makeId : Name -> Id
|
makeId : Name -> Id
|
||||||
makeId (MakeName mods (UN str)) = I (makeIdBase mods str) 0
|
makeId (MkName mods (UN str)) = I (makeIdBase mods str) 0
|
||||||
makeId (MakeName mods (MN str k)) = I (makeIdBase mods str) 0
|
makeId (MkName mods (MN str k)) = I (makeIdBase mods str) 0
|
||||||
makeId (MakeName mods Unused) = I (makeIdBase mods "_") 0
|
makeId (MkName mods Unused) = I (makeIdBase mods "_") 0
|
||||||
|
|
||||||
export
|
export
|
||||||
makeIdB : BindName -> Id
|
makeIdB : BindName -> Id
|
||||||
makeIdB (BN name _) = makeId $ MakeName [<] name
|
makeIdB (BN name _) = makeId $ MkName [<] name
|
||||||
|
|
||||||
private
|
private
|
||||||
bump : Id -> Id
|
bump : Id -> Id
|
||||||
|
|
|
@ -71,7 +71,7 @@ tests = "lexer" :- [
|
||||||
lexes "δελτα" [Name "δελτα"],
|
lexes "δελτα" [Name "δελτα"],
|
||||||
lexes "★★" [Name "★★"],
|
lexes "★★" [Name "★★"],
|
||||||
lexes "Types" [Name "Types"],
|
lexes "Types" [Name "Types"],
|
||||||
lexes "a.b.c.d.e" [Name $ MakePName [< "a","b","c","d"] "e"],
|
lexes "a.b.c.d.e" [Name $ MkPName [< "a","b","c","d"] "e"],
|
||||||
lexes "normalïse" [Name "normalïse"],
|
lexes "normalïse" [Name "normalïse"],
|
||||||
-- ↑ replace i + combining ¨ with precomposed ï
|
-- ↑ replace i + combining ¨ with precomposed ï
|
||||||
lexes "map#" [Name "map#"],
|
lexes "map#" [Name "map#"],
|
||||||
|
@ -90,16 +90,16 @@ tests = "lexer" :- [
|
||||||
lexes "***" [Name "***"],
|
lexes "***" [Name "***"],
|
||||||
lexes "+**" [Name "+**"],
|
lexes "+**" [Name "+**"],
|
||||||
lexes "+#" [Name "+#"],
|
lexes "+#" [Name "+#"],
|
||||||
lexes "+.+.+" [Name $ MakePName [< "+", "+"] "+"],
|
lexes "+.+.+" [Name $ MkPName [< "+", "+"] "+"],
|
||||||
lexes "a.+" [Name $ MakePName [< "a"] "+"],
|
lexes "a.+" [Name $ MkPName [< "a"] "+"],
|
||||||
lexes "+.a" [Name $ MakePName [< "+"] "a"],
|
lexes "+.a" [Name $ MkPName [< "+"] "a"],
|
||||||
|
|
||||||
lexes "+a" [Name "+", Name "a"],
|
lexes "+a" [Name "+", Name "a"],
|
||||||
|
|
||||||
lexes "x." [Name "x", Reserved "."],
|
lexes "x." [Name "x", Reserved "."],
|
||||||
lexes "&." [Name "&", Reserved "."],
|
lexes "&." [Name "&", Reserved "."],
|
||||||
lexes ".x" [Reserved ".", Name "x"],
|
lexes ".x" [Reserved ".", Name "x"],
|
||||||
lexes "a.b.c." [Name $ MakePName [< "a", "b"] "c", Reserved "."],
|
lexes "a.b.c." [Name $ MkPName [< "a", "b"] "c", Reserved "."],
|
||||||
|
|
||||||
lexes "case" [Reserved "case"],
|
lexes "case" [Reserved "case"],
|
||||||
lexes "caseω" [Reserved "caseω"],
|
lexes "caseω" [Reserved "caseω"],
|
||||||
|
|
|
@ -63,9 +63,9 @@ tests = "parser" :- [
|
||||||
|
|
||||||
"names" :- [
|
"names" :- [
|
||||||
parsesAs (const qname) "x"
|
parsesAs (const qname) "x"
|
||||||
(MakePName [<] "x"),
|
(MkPName [<] "x"),
|
||||||
parsesAs (const qname) "Data.List.length"
|
parsesAs (const qname) "Data.List.length"
|
||||||
(MakePName [< "Data", "List"] "length"),
|
(MkPName [< "Data", "List"] "length"),
|
||||||
parseFails (const qname) "_"
|
parseFails (const qname) "_"
|
||||||
],
|
],
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ tests = "parser" :- [
|
||||||
parseMatch term "f"
|
parseMatch term "f"
|
||||||
`(V "f" {}),
|
`(V "f" {}),
|
||||||
parseMatch term "f.x.y"
|
parseMatch term "f.x.y"
|
||||||
`(V (MakePName [< "f", "x"] "y") {}),
|
`(V (MkPName [< "f", "x"] "y") {}),
|
||||||
parseMatch term "f x"
|
parseMatch term "f x"
|
||||||
`(App (V "f" {}) (V "x" {}) _),
|
`(App (V "f" {}) (V "x" {}) _),
|
||||||
parseMatch term "f x y"
|
parseMatch term "f x y"
|
||||||
|
@ -526,7 +526,7 @@ tests = "parser" :- [
|
||||||
PSucceed False Nothing _]
|
PSucceed False Nothing _]
|
||||||
PSucceed _),
|
PSucceed _),
|
||||||
PD (PDef $ MkPDef (PQ Any _) "y"
|
PD (PDef $ MkPDef (PQ Any _) "y"
|
||||||
(PConcrete Nothing (V (MakePName [< "a"] "x") Nothing _))
|
(PConcrete Nothing (V (MkPName [< "a"] "x") Nothing _))
|
||||||
PSucceed False Nothing _)]),
|
PSucceed False Nothing _)]),
|
||||||
parseMatch input #" load "a.quox"; def b = a.b "#
|
parseMatch input #" load "a.quox"; def b = a.b "#
|
||||||
`([PLoad "a.quox" _,
|
`([PLoad "a.quox" _,
|
||||||
|
|
|
@ -37,8 +37,8 @@ tests = "pretty printing terms" :- [
|
||||||
"free vars" :- [
|
"free vars" :- [
|
||||||
testPrettyE1 [<] [<] (^F "x" 0) "x",
|
testPrettyE1 [<] [<] (^F "x" 0) "x",
|
||||||
testPrettyE [<] [<] (^F "x" 1) "x¹" "x^1",
|
testPrettyE [<] [<] (^F "x" 1) "x¹" "x^1",
|
||||||
testPrettyE1 [<] [<] (^F (MakeName [< "A", "B", "C"] "x") 0) "A.B.C.x",
|
testPrettyE1 [<] [<] (^F (MkName [< "A", "B", "C"] "x") 0) "A.B.C.x",
|
||||||
testPrettyE [<] [<] (^F (MakeName [< "A", "B", "C"] "x") 2)
|
testPrettyE [<] [<] (^F (MkName [< "A", "B", "C"] "x") 2)
|
||||||
"A.B.C.x²"
|
"A.B.C.x²"
|
||||||
"A.B.C.x^2"
|
"A.B.C.x^2"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue