-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: @[builtin_doc] attribute (part 1)
- Loading branch information
Showing
3 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/- | ||
Copyright (c) 2021 Microsoft Corporation. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Leonardo de Moura | ||
-/ | ||
import Lean.Compiler.InitAttr | ||
import Lean.DocString | ||
|
||
namespace Lean | ||
|
||
def declareBuiltinDocStringAndRanges (declName : Name) : AttrM Unit := do | ||
if let some doc ← findDocString? (← getEnv) declName (includeBuiltin := false) then | ||
declareBuiltin (declName ++ `docString) (mkAppN (mkConst ``addBuiltinDocString) #[toExpr declName, toExpr doc]) | ||
if let some declRanges ← findDeclarationRanges? declName then | ||
declareBuiltin (declName ++ `declRange) (mkAppN (mkConst ``addBuiltinDeclarationRanges) #[toExpr declName, toExpr declRanges]) | ||
|
||
builtin_initialize | ||
registerBuiltinAttribute { | ||
name := `builtin_doc | ||
descr := "make the docs and location of this declaration available as a builtin" | ||
add := fun decl stx _ => do | ||
Attribute.Builtin.ensureNoArgs stx | ||
declareBuiltinDocStringAndRanges decl | ||
} | ||
|
||
end Lean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters