feat: support simpleBinder at letDecl

This commit is contained in:
Leonardo de Moura 2020-11-12 13:25:38 -08:00
parent 5c33440050
commit cae6aa95dc
4 changed files with 25 additions and 9 deletions

View file

@ -32,7 +32,11 @@ def doIdDecl := parser! «try» (ident >> optType >> leftArrow) >> doElemParse
def doPatDecl := parser! «try» (termParser >> leftArrow) >> doElemParser >> optional (" | " >> doElemParser)
@[builtinDoElemParser] def doLetArrow := parser! "let " >> optional "mut " >> (doIdDecl <|> doPatDecl)
@[builtinDoElemParser] def doReassign := parser! notFollowedByRedefinedTermToken >> (letIdDecl <|> letPatDecl)
-- We use `letIdDeclNoBinders` to define `doReassign`.
-- Motivation: we do not reassign functions, and avoid parser conflict
def letIdDeclNoBinders := node `Lean.Parser.Term.letIdDecl $ «try» (ident >> pushNone >> optType >> " := ") >> termParser
@[builtinDoElemParser] def doReassign := parser! notFollowedByRedefinedTermToken >> (letIdDeclNoBinders <|> letPatDecl)
@[builtinDoElemParser] def doReassignArrow := parser! notFollowedByRedefinedTermToken >> (doIdDecl <|> doPatDecl)
@[builtinDoElemParser] def doHave := parser! "have " >> Term.haveDecl
/-

View file

@ -150,7 +150,7 @@ def optExprPrecedence := optional («try» ":" >> termParser maxPrec)
@[builtinTermParser] def «match_syntax» := parser!:leadPrec "match_syntax" >> termParser >> " with " >> matchAlts
/- Remark: we use `checkWsBefore` to ensure `let x[i] := e; b` is not parsed as `let x [i] := e; b` where `[i]` is an `instBinder`. -/
def letIdLhs : Parser := ident >> checkWsBefore "expected space before binders" >> many (ppSpace >> bracketedBinder) >> optType
def letIdLhs : Parser := ident >> checkWsBefore "expected space before binders" >> many (ppSpace >> (simpleBinder <|> bracketedBinder)) >> optType
def letIdDecl := node `Lean.Parser.Term.letIdDecl $ «try» (letIdLhs >> " := ") >> termParser
def letPatDecl := node `Lean.Parser.Term.letPatDecl $ «try» (termParser >> pushNone >> optType >> " := ") >> termParser
def letEqnsDecl := node `Lean.Parser.Term.letEqnsDecl $ letIdLhs >> matchAlts false

View file

@ -243,11 +243,11 @@ def ex6 (α : Type u) (n : Nat) (xs : Vec α n) :
× LHS (forall (N : Nat) (XS : Vec α N), Pat (inaccessible N) × Pat XS) :=
arbitrary _
set_option trace.Meta.Match.match true
set_option trace.Meta.Match.debug true
-- set_option trace.Meta.Match.match true
-- set_option trace.Meta.Match.debug true
#eval test `ex6 2 `elimTest6
#print elimTest6
-- #print elimTest6
def ex7 (α : Type u) (n : Nat) (xs : Vec α n) :
LHS (forall (a : α), Pat (inaccessible 1) × Pat (Vec.cons a Vec.nil))
@ -255,7 +255,7 @@ def ex7 (α : Type u) (n : Nat) (xs : Vec α n) :
arbitrary _
#eval test `ex7 2 `elimTest7
#check elimTest7
-- #check elimTest7
def isSizeOne {n : Nat} (xs : Vec Nat n) : Bool :=
elimTest7 _ (fun _ _ => Bool) n xs (fun _ => true) (fun _ _ => false)
@ -351,7 +351,7 @@ def ex14 (x y : Nat) :
× LHS (forall (x y : Nat), Pat x × Pat y) :=
arbitrary _
set_option trace.Meta.Match true
-- set_option trace.Meta.Match true
#eval test `ex14 2 `elimTest14
#print elimTest14
@ -372,7 +372,7 @@ def ex15 (xs : Array (List Nat)) :
arbitrary _
#eval test `ex15 1 `elimTest15
#check elimTest15
-- #check elimTest15
def h3 (xs : Array (List Nat)) : Nat :=
elimTest15 (fun _ => Nat) xs
@ -393,9 +393,11 @@ arbitrary _
#eval test `ex16 1 `elimTest16
#check elimTest16
-- #check elimTest16
#print elimTest16
def h4 (xs : List Nat) : List Nat :=
elimTest16 (fun _ => List Nat) xs
(fun a xs b ys => xs)

View file

@ -361,3 +361,13 @@ theorem simple24 (x y z : Nat) : y = z → x = x → y = x → x = z :=
fun h1 _ h3 =>
have h : x = y by apply Eq.symm; assumption
Eq.trans h (by assumption)
def f1 (x : Nat) : Nat :=
let double x := x + x
let rec loop x :=
match x with
| 0 => 0
| x+1 => loop x + double x
loop x
#eval f1 5