lean4-htt/tests/lean/run/elabCmd.lean
Leonardo de Moura 8e81db0d2b chore: add temporary workaround to tests
We will remove it after we implement `doMatch`
2020-09-27 06:58:10 -07:00

30 lines
716 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Lean
new_frontend
open Lean
open Lean.Elab
open Lean.Elab.Term
def getCtors (c : Name) : TermElabM (List Name) := do
let env ← getEnv;
(match env.find? c with
| some (ConstantInfo.inductInfo val) =>
pure val.ctors
| _ => pure [])
def elabAnonCtor (args : Syntax) (τ : Expr) : TermElabM Expr :=
match τ.getAppFn with
| Expr.const C _ _ => do
let ctors ← getCtors C;
(match ctors with
| [c] => do
let stx ← `($(Lean.mkIdent c) $(Array.getSepElems args.getArgs)*);
elabTerm stx τ
-- error handling
| _ => unreachable!)
| _ => unreachable!
elab "foo⟨" args:(sepBy term ", ") "⟩" : term <= τ => do
elabAnonCtor args τ
example : Nat × Nat := foo⟨1, 2⟩