chore: update stage0

This commit is contained in:
Leonardo de Moura 2021-09-30 20:31:18 -07:00
parent a5502e652c
commit ef4becfedb
3 changed files with 1337 additions and 556 deletions

View file

@ -137,12 +137,12 @@ infixr:100 " <$> " => Functor.map
macro_rules | `($x <|> $y) => `(binop_lazy% HOrElse.hOrElse $x $y)
macro_rules | `($x >> $y) => `(binop_lazy% HAndThen.hAndThen $x $y)
syntax (name := termDepIfThenElse) ppGroup(ppDedent("if " ident " : " term " then" ppSpace term ppDedent(ppSpace "else") ppSpace term)) : term
syntax (name := termDepIfThenElse) (priority := high) ppGroup(ppDedent("if " ident " : " term " then" ppSpace term ppDedent(ppSpace "else") ppSpace term)) : term
macro_rules
| `(if $h:ident : $c then $t:term else $e:term) => ``(dite $c (fun $h:ident => $t) (fun $h:ident => $e))
syntax (name := termIfThenElse) ppGroup(ppDedent("if " term " then" ppSpace term ppDedent(ppSpace "else") ppSpace term)) : term
syntax (name := termIfThenElse) (priority := high) ppGroup(ppDedent("if " term " then" ppSpace term ppDedent(ppSpace "else") ppSpace term)) : term
macro_rules
| `(if $c then $t:term else $e:term) => ``(ite $c $t $e)

View file

@ -50,13 +50,38 @@ open Meta
| none => throwError "invalid constructor ⟨...⟩, expected type must be known"
| _ => throwUnsupportedSyntax
/-
@[builtinMacro Lean.Parser.Term.if] def expandIf : Macro := fun stx =>
match_syntax stx with
| `(if $h : $cond then $t else $e) => `(dite $cond (fun $h:ident => $t) (fun $h:ident => $e))
| `(if $cond then $t else $e) => `(ite $cond $t $e)
| _ => Macro.throwUnsupported
-/
@[builtinTermElab Lean.Parser.Term.if] def elabIf : TermElab := fun stx expectedType? => do
/- "if " >> optIdent >> termParser >> " then " >> termParser >> " else " >> termParser -/
let c := stx[2]
let t := stx[4]
let e := stx[6]
let newStx ←
if stx[1].isNone then
`(ite $c $t $e)
else
let h := stx[1][0]
`(dite $c (fun $h:ident => $t) (fun $h:ident => $e))
withMacroExpansion stx newStx <| elabTerm newStx expectedType?
-- TODO: delete
@[builtinTermElab termDepIfThenElse] def elabIfOld1 : TermElab := fun stx expectedType? => do
/- "if " ident " : " term " then" term "else" term -/
let h := stx[1]
let c := stx[3]
let t := stx[5]
let e := stx[7]
let newStx ← `(dite $c (fun $h:ident => $t) (fun $h:ident => $e))
withMacroExpansion stx newStx <| elabTerm newStx expectedType?
-- TODO: delete
@[builtinTermElab termIfThenElse] def elabIfOld2 : TermElab := fun stx expectedType? => do
/- "if " term " then" term "else" term -/
let c := stx[1]
let t := stx[3]
let e := stx[5]
let newStx ← `(ite $c $t $e)
withMacroExpansion stx newStx <| elabTerm newStx expectedType?
@[builtinTermElab borrowed] def elabBorrowed : TermElab := fun stx expectedType? =>
match stx with

File diff suppressed because it is too large Load diff