Equations
-
Lean.Elab.Command.expandMutualNamespace stx = let ns? := none;
let elemsNew := #[];
do
let r ←
let col := Lean.Syntax.getArgs (Lean.Syntax.getOp stx 1);
forIn col { fst := elemsNew, snd := ns? } fun elem r =>
let elemsNew := r.fst;
let ns? := r.snd;
do
let a ← Lean.Elab.Command.expandDeclNamespace? elem
match ns?, a with
| x, none =>
let elemsNew := Array.push elemsNew elem;
do
pure PUnit.unit
pure (ForInStep.yield { fst := elemsNew, snd := ns? })
| none, some (ns, elem) =>
let ns? := some ns;
let elemsNew := Array.push elemsNew elem;
do
pure PUnit.unit
pure (ForInStep.yield { fst := elemsNew, snd := ns? })
| some nsCurr, some (nsNew, elem) =>
if (nsCurr == nsNew) = true then
let elemsNew := Array.push elemsNew elem;
do
pure PUnit.unit
pure (ForInStep.yield { fst := elemsNew, snd := ns? })
else do
Lean.Macro.throwErrorAt elem
(toString "conflicting namespaces in mutual declaration, using namespace '" ++ toString nsNew ++ toString "', but used '" ++ toString nsCurr ++ toString "' in previous declaration")
pure (ForInStep.yield { fst := elemsNew, snd := ns? })
let x : MProd (Array Lean.Syntax) (Option Lean.Name) := r
match x with
| { fst := elemsNew, snd := ns? } =>
match ns? with
| some ns =>
let ns := Lean.mkIdentFrom stx ns;
let stxNew := Lean.Syntax.setArg stx 1 (Lean.mkNullNode elemsNew);
do
let info ← Lean.MonadRef.mkInfoFromRefPos
let _ ← Lean.getCurrMacroScope
let _ ← Lean.getMainModule
pure
(Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.namespace
#[Lean.Syntax.atom info "namespace", ns],
stxNew,
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.end
#[Lean.Syntax.atom info "end", Lean.Syntax.node Lean.SourceInfo.none `null #[ns]]])
| none => Lean.Macro.throwUnsupported
Equations
-
Lean.Elab.Command.expandInitCmd builtin stx = let optVisibility := Lean.Syntax.getOp stx 0;
let optHeader := Lean.Syntax.getOp stx 2;
let doSeq := Lean.Syntax.getOp stx 3;
let attrId := Lean.mkIdentFrom stx (if builtin = true then `builtinInit else `init);
if Lean.Syntax.isNone optHeader = true then
let _do_jp := fun y => do
let info ← Lean.MonadRef.mkInfoFromRefPos
let scp ← Lean.getCurrMacroScope
let mainModule ← Lean.getMainModule
pure
(Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declaration
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declModifiers
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attributes
#[Lean.Syntax.atom info "@[",
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attrInstance
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attrKind
#[Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Attr.simple
#[attrId, Lean.Syntax.node Lean.SourceInfo.none `null #[]]]],
Lean.Syntax.atom info "]"]],
Lean.Syntax.node Lean.SourceInfo.none `null #[], Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[], Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.def
#[Lean.Syntax.atom info "def",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declId
#[Lean.Syntax.ident info (String.toSubstring "initFn") (Lean.addMacroScope mainModule `initFn scp)
[],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.optDeclSig
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.typeSpec
#[Lean.Syntax.atom info ":",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.app
#[Lean.Syntax.ident info (String.toSubstring "IO")
(Lean.addMacroScope mainModule `IO scp) [(`IO, [])],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.ident info (String.toSubstring "Unit")
(Lean.addMacroScope mainModule `Unit scp) [(`Unit, [])]]]]]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declValSimple
#[Lean.Syntax.atom info ":=",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.do #[Lean.Syntax.atom info "do", doSeq],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `null #[], Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[]]]);
if Lean.Syntax.isNone optVisibility = true then do
let y ← pure PUnit.unit
_do_jp y
else do
let y ← Lean.Macro.throwError "invalid initialization command, 'visibility' modifer is not allowed"
_do_jp y
else
let id := Lean.Syntax.getOp optHeader 0;
let type := Lean.Syntax.getOp (Lean.Syntax.getOp optHeader 1) 1;
if Lean.Syntax.isNone optVisibility = true then do
let info ← Lean.MonadRef.mkInfoFromRefPos
let scp ← Lean.getCurrMacroScope
let mainModule ← Lean.getMainModule
pure
(Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declaration
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declModifiers
#[Lean.Syntax.node Lean.SourceInfo.none `null #[], Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[], Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[], Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.def
#[Lean.Syntax.atom info "def",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declId
#[Lean.Syntax.ident info (String.toSubstring "initFn")
(Lean.addMacroScope mainModule `initFn scp) [],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.optDeclSig
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.typeSpec
#[Lean.Syntax.atom info ":",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.app
#[Lean.Syntax.ident info (String.toSubstring "IO")
(Lean.addMacroScope mainModule `IO scp) [(`IO, [])],
Lean.Syntax.node Lean.SourceInfo.none `null #[type]]]]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declValSimple
#[Lean.Syntax.atom info ":=",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.do
#[Lean.Syntax.atom info "do", doSeq],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `null #[], Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[]]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declaration
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declModifiers
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attributes
#[Lean.Syntax.atom info "@[",
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attrInstance
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attrKind
#[Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Attr.simple
#[attrId,
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.ident info (String.toSubstring "initFn")
(Lean.addMacroScope mainModule `initFn scp) []]]]],
Lean.Syntax.atom info "]"]],
Lean.Syntax.node Lean.SourceInfo.none `null #[], Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[], Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.constant
#[Lean.Syntax.atom info "constant", id,
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declSig
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.typeSpec
#[Lean.Syntax.atom info ":", type]],
Lean.Syntax.node Lean.SourceInfo.none `null #[]]]])
else
if (Lean.Syntax.getKind (Lean.Syntax.getOp optVisibility 0) == `Lean.Parser.Command.private) = true then do
let info ← Lean.MonadRef.mkInfoFromRefPos
let scp ← Lean.getCurrMacroScope
let mainModule ← Lean.getMainModule
pure
(Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declaration
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declModifiers
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.def
#[Lean.Syntax.atom info "def",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declId
#[Lean.Syntax.ident info (String.toSubstring "initFn")
(Lean.addMacroScope mainModule `initFn scp) [],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.optDeclSig
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.typeSpec
#[Lean.Syntax.atom info ":",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.app
#[Lean.Syntax.ident info (String.toSubstring "IO")
(Lean.addMacroScope mainModule `IO scp) [(`IO, [])],
Lean.Syntax.node Lean.SourceInfo.none `null #[type]]]]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declValSimple
#[Lean.Syntax.atom info ":=",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.do
#[Lean.Syntax.atom info "do", doSeq],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[]]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declaration
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declModifiers
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attributes
#[Lean.Syntax.atom info "@[",
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attrInstance
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attrKind
#[Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Attr.simple
#[attrId,
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.ident info (String.toSubstring "initFn")
(Lean.addMacroScope mainModule `initFn scp) []]]]],
Lean.Syntax.atom info "]"]],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.private
#[Lean.Syntax.atom info "private"]],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.constant
#[Lean.Syntax.atom info "constant", id,
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declSig
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.typeSpec
#[Lean.Syntax.atom info ":", type]],
Lean.Syntax.node Lean.SourceInfo.none `null #[]]]])
else
if (Lean.Syntax.getKind (Lean.Syntax.getOp optVisibility 0) == `Lean.Parser.Command.protected) = true then do
let info ← Lean.MonadRef.mkInfoFromRefPos
let scp ← Lean.getCurrMacroScope
let mainModule ← Lean.getMainModule
pure
(Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declaration
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declModifiers
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.def
#[Lean.Syntax.atom info "def",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declId
#[Lean.Syntax.ident info (String.toSubstring "initFn")
(Lean.addMacroScope mainModule `initFn scp) [],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.optDeclSig
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.typeSpec
#[Lean.Syntax.atom info ":",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.app
#[Lean.Syntax.ident info (String.toSubstring "IO")
(Lean.addMacroScope mainModule `IO scp) [(`IO, [])],
Lean.Syntax.node Lean.SourceInfo.none `null #[type]]]]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declValSimple
#[Lean.Syntax.atom info ":=",
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.do
#[Lean.Syntax.atom info "do", doSeq],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[]]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declaration
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declModifiers
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attributes
#[Lean.Syntax.atom info "@[",
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attrInstance
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.attrKind
#[Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Attr.simple
#[attrId,
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.ident info (String.toSubstring "initFn")
(Lean.addMacroScope mainModule `initFn scp) []]]]],
Lean.Syntax.atom info "]"]],
Lean.Syntax.node Lean.SourceInfo.none `null
#[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.protected
#[Lean.Syntax.atom info "protected"]],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `null #[]],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.constant
#[Lean.Syntax.atom info "constant", id,
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Command.declSig
#[Lean.Syntax.node Lean.SourceInfo.none `null #[],
Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.typeSpec
#[Lean.Syntax.atom info ":", type]],
Lean.Syntax.node Lean.SourceInfo.none `null #[]]]])
else Lean.Macro.throwError "unexpected visibility annotation"