diff --git a/Pantograph/Expr.lean b/Pantograph/Expr.lean index 9d8f70c..cbee9a5 100644 --- a/Pantograph/Expr.lean +++ b/Pantograph/Expr.lean @@ -4,6 +4,26 @@ open Lean namespace Pantograph +structure ProjectionApplication where + projector: Name + numParams: Nat + inner: Expr + +@[export pantograph_expr_proj_to_app] +def exprProjToApp (env: Environment) (e: Expr): ProjectionApplication := + let (typeName, idx, inner) := match e with + | .proj typeName idx inner => (typeName, idx, inner) + | _ => panic! "Argument must be proj" + let ctor := getStructureCtor env typeName + let fieldName := getStructureFields env typeName |>.get! idx + let projector := getProjFnForField? env typeName fieldName |>.get! + { + projector, + numParams := ctor.numParams, + inner, + } + + def _root_.Lean.Name.isAuxLemma (n : Lean.Name) : Bool := n matches .num (.str _ "_auxLemma") _ /-- Unfold all lemmas created by `Lean.Meta.mkAuxLemma`. These end in `_auxLemma.nn` where `nn` is a number. -/ diff --git a/Pantograph/Serial.lean b/Pantograph/Serial.lean index 87353e2..21bffce 100644 --- a/Pantograph/Serial.lean +++ b/Pantograph/Serial.lean @@ -168,15 +168,12 @@ partial def serializeExpressionSexp (expr: Expr) (sanitize: Bool := true): MetaM -- NOTE: Equivalent to expr itself, but mdata influences the prettyprinter -- It may become necessary to incorporate the metadata. self inner - | .proj typeName idx inner => do + | .proj _ _ _ => do let env ← getEnv - let ctor := getStructureCtor env typeName - let fieldName := getStructureFields env typeName |>.get! idx - let projectorName := getProjFnForField? env typeName fieldName |>.get! - - let autos := String.intercalate " " (List.replicate ctor.numParams "_") - let inner ← self inner - pure s!"((:c {projectorName}) {autos} {inner})" + let projApp := exprProjToApp env e + let autos := String.intercalate " " (List.replicate projApp.numParams "_") + let inner ← self projApp.inner + pure s!"((:c {projApp.projector}) {autos} {inner})" -- Elides all unhygenic names binderInfoSexp : Lean.BinderInfo → String | .default => ""