diff --git a/src/Lean/Elab/Binders.lean b/src/Lean/Elab/Binders.lean index 0262558998..d1f08fc7e4 100644 --- a/src/Lean/Elab/Binders.lean +++ b/src/Lean/Elab/Binders.lean @@ -373,7 +373,7 @@ else /- Helper function for `expandEqnsIntoMatch` -/ private def getMatchAltNumPatterns (matchAlts : Syntax) : Nat := -let alt0 := matchAlts.getArg 0; +let alt0 := (matchAlts.getArg 1).getArg 0; let pats := (alt0.getArg 0).getArgs.getSepElems; pats.size @@ -381,7 +381,7 @@ pats.size private def expandMatchAltsIntoMatchAux (ref : Syntax) (matchAlts : Syntax) (matchTactic : Bool) : Nat → Array Syntax → MacroM Syntax | 0, discrs => pure $ Syntax.node (if matchTactic then `Lean.Parser.Tactic.match else `Lean.Parser.Term.match) - #[mkAtomFrom ref "match ", mkNullNode discrs, mkNullNode, mkAtomFrom ref " with ", mkNullNode, matchAlts] + #[mkAtomFrom ref "match ", mkNullNode discrs, mkNullNode, mkAtomFrom ref " with ", matchAlts] | n+1, discrs => withFreshMacroScope do x ← `(x); let discrs := if discrs.isEmpty then discrs else discrs.push $ mkAtomFrom ref ", "; @@ -425,7 +425,7 @@ fun stx expectedType? => -- "fun " >> ((many1 funBinder >> darrow >> termParser) <|> funMatchAlts) -- funMatchAlts := parser! matchAlts false if (stx.getArg 1).isOfKind `Lean.Parser.Term.funMatchAlts then do - stxNew ← liftMacroM $ expandMatchAltsIntoMatch stx ((stx.getArg 1).getArg 1); + stxNew ← liftMacroM $ expandMatchAltsIntoMatch stx ((stx.getArg 1).getArg 0); withMacroExpansion stx stxNew $ elabTerm stxNew expectedType? else do let binders := (stx.getArg 1).getArgs; diff --git a/src/Lean/Elab/Match.lean b/src/Lean/Elab/Match.lean index 4724846ce8..83fe79e5a2 100644 --- a/src/Lean/Elab/Match.lean +++ b/src/Lean/Elab/Match.lean @@ -21,7 +21,7 @@ nodeWithAntiquot "matchAlt" `Lean.Parser.Term.matchAlt $ sepBy1 termParser ", " >> darrow >> termParser def matchAlts (optionalFirstBar := true) : Parser := -withPosition $ fun pos => +group $ withPosition $ fun pos => (if optionalFirstBar then optional "| " else "| ") >> sepBy1 matchAlt (checkColGe pos.column "alternatives must be indented" >> "|") @@ -92,7 +92,7 @@ matchAlts.mapM fun matchAlt => do /- Given `stx` a match-expression, return its alternatives. -/ private def getMatchAlts (stx : Syntax) : Array MatchAltView := -let alts : Array Syntax := (stx.getArg 5).getArgs.filter fun alt => alt.getKind == `Lean.Parser.Term.matchAlt; +let alts : Array Syntax := ((stx.getArg 4).getArg 1).getArgs.filter fun alt => alt.getKind == `Lean.Parser.Term.matchAlt; alts.map mkMatchAltView /-- diff --git a/src/Lean/Elab/Tactic/Basic.lean b/src/Lean/Elab/Tactic/Basic.lean index 81ea86f3d2..f8642b8771 100644 --- a/src/Lean/Elab/Tactic/Basic.lean +++ b/src/Lean/Elab/Tactic/Basic.lean @@ -304,7 +304,7 @@ fun stx => match_syntax stx with @[builtinTactic Lean.Parser.Tactic.introMatch] def evalIntroMatch : Tactic := fun stx => do - let matchAlts := stx.getArg 2; + let matchAlts := stx.getArg 1; stxNew ← liftMacroM $ Term.expandMatchAltsIntoMatchTactic stx matchAlts; withMacroExpansion stx stxNew $ evalTactic stxNew diff --git a/src/Lean/Elab/Tactic/Match.lean b/src/Lean/Elab/Tactic/Match.lean index 10842b2563..15ae4e6266 100644 --- a/src/Lean/Elab/Tactic/Match.lean +++ b/src/Lean/Elab/Tactic/Match.lean @@ -16,7 +16,8 @@ structure AuxMatchTermState := (cases : Array Syntax := #[]) private def mkAuxiliaryMatchTermAux (parentTag : Name) (matchTac : Syntax) : StateT AuxMatchTermState MacroM Syntax := do -let alts := (matchTac.getArg 5).getArgs; +let matchAlts := matchTac.getArg 4; +let alts := (matchAlts.getArg 1).getArgs; newAlts ← alts.mapSepElemsM fun alt => do { let alt := alt.updateKind `Lean.Parser.Term.matchAlt; let holeOrTactic := alt.getArg 2; @@ -36,7 +37,7 @@ newAlts ← alts.mapSepElemsM fun alt => do { pure $ alt.setArg 2 newHole }; let result := matchTac.updateKind `Lean.Parser.Term.match; -let result := result.setArg 5 (mkNullNode newAlts); +let result := result.setArg 4 (matchAlts.setArg 1 (mkNullNode newAlts)); pure result private def mkAuxiliaryMatchTerm (parentTag : Name) (matchTac : Syntax) : MacroM (Syntax × Array Syntax) := do diff --git a/src/Lean/Parser/Tactic.lean b/src/Lean/Parser/Tactic.lean index 96ee9cc6bd..23e865ded1 100644 --- a/src/Lean/Parser/Tactic.lean +++ b/src/Lean/Parser/Tactic.lean @@ -57,7 +57,7 @@ def generalizingVars := optional (" generalizing " >> many1 ident) def withIds : Parser := optional (" with " >> many1 ident') def matchAlt : Parser := parser! sepBy1 termParser ", " >> darrow >> holeOrTactic -def matchAlts : Parser := withPosition $ fun pos => (optional "| ") >> sepBy1 matchAlt (checkColGe pos.column "alternatives must be indented" >> "|") +def matchAlts : Parser := group $ withPosition $ fun pos => (optional "| ") >> sepBy1 matchAlt (checkColGe pos.column "alternatives must be indented" >> "|") @[builtinTacticParser] def «match» := parser! nonReservedSymbol "match " >> sepBy1 Term.matchDiscr ", " >> Term.optType >> " with " >> matchAlts @[builtinTacticParser] def «introMatch» := parser! nonReservedSymbol "intro " >> matchAlts diff --git a/src/Lean/Parser/Term.lean b/src/Lean/Parser/Term.lean index 4bf54b4526..5adce61ef5 100644 --- a/src/Lean/Parser/Term.lean +++ b/src/Lean/Parser/Term.lean @@ -99,7 +99,7 @@ nodeWithAntiquot "matchAlt" `Lean.Parser.Term.matchAlt $ sepBy1 termParser ", " >> darrow >> termParser def matchAlts (optionalFirstBar := true) : Parser := -withPosition $ fun pos => +parser! withPosition $ fun pos => (if optionalFirstBar then optional "| " else "| ") >> sepBy1 matchAlt (checkColGe pos.column "alternatives must be indented" >> "|") @@ -110,8 +110,7 @@ def matchDiscr := parser! optional (try (ident >> checkNoWsBefore "no space befo def funImplicitBinder := try (lookahead ("{" >> many1 binderIdent >> (" : " <|> "}"))) >> implicitBinder def funBinder : Parser := funImplicitBinder <|> instBinder <|> termParser maxPrec -def funMatchAlts := parser! matchAlts false -@[builtinTermParser] def «fun» := parser!:maxPrec unicodeSymbol "λ " "fun " >> ((many1 funBinder >> darrow >> termParser) <|> funMatchAlts) +@[builtinTermParser] def «fun» := parser!:maxPrec unicodeSymbol "λ " "fun " >> ((many1 funBinder >> darrow >> termParser) <|> matchAlts false) def optExprPrecedence := optional (try ":" >> termParser maxPrec) @[builtinTermParser] def «parser!» := parser!:leadPrec "parser! " >> optExprPrecedence >> termParser