feat: add isCharLit

This commit is contained in:
Leonardo de Moura 2020-08-13 12:49:37 -07:00
parent 145a3dddca
commit 5b1b11ffe0
2 changed files with 23 additions and 9 deletions

View file

@ -427,14 +427,6 @@ def isLit : Expr → Bool
| lit _ _ => true
| _ => false
def isNatLit : Expr → Bool
| lit (Literal.natVal _) _ => true
| _ => false
def isStringLit : Expr → Bool
| lit (Literal.strVal _) _ => true
| _ => false
def getAppFn : Expr → Expr
| app f a _ => getAppFn f
| e => e
@ -512,6 +504,21 @@ def appArg! : Expr → Expr
| app _ a _ => a
| _ => panic! "application expected"
def isNatLit : Expr → Bool
| lit (Literal.natVal _) _ => true
| _ => false
def natLit? : Expr → Option Nat
| lit (Literal.natVal v) _ => v
| _ => none
def isStringLit : Expr → Bool
| lit (Literal.strVal _) _ => true
| _ => false
def isCharLit (e : Expr) : Bool :=
e.isAppOfArity `Char.ofNat 1 && e.appArg!.isNatLit
def constName! : Expr → Name
| const n _ _ => n
| _ => panic! "constant expected"

View file

@ -734,6 +734,13 @@ check t;
t ← mkArrayLit nat [mkNatLit 1, mkNatLit 2];
print t;
check t;
pure ()
match t.isArrayLit? with
| some (_, xs) => do
check $ pure $ xs.size == 2;
match (xs.get! 0).isNatLit?, (xs.get! 1).isNatLit? with
| some 1, some 2 => pure ()
| _, _ => throwOther "nat lits expected"
| none => throwOther "array lit expected"
#eval tst42