-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from HEPLean/Docs
refactor: Docs and note
- Loading branch information
Showing
20 changed files
with
615 additions
and
171 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/- | ||
Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved. | ||
Released under Apache 2.0 license. | ||
Authors: Joseph Tooby-Smith | ||
-/ | ||
import Batteries.Lean.HashSet | ||
import Mathlib.Lean.Expr.Basic | ||
import Mathlib.Lean.CoreM | ||
import ImportGraph.RequiredModules | ||
/-! | ||
## Underlying structure for remarks | ||
-/ | ||
|
||
namespace HepLean | ||
open Lean System Meta | ||
|
||
/-- The information from a `remark ...` command. To be used in a note file-/ | ||
structure RemarkInfo where | ||
/-- The content of the remark. -/ | ||
content : String | ||
/-- The file name where the remark came from. -/ | ||
fileName : Name | ||
/-- The line from where the remark came from. -/ | ||
line : Nat | ||
/-- The name of the remark. -/ | ||
name : Name | ||
/-- The namespace of the remark. -/ | ||
nameSpace : Name | ||
|
||
/-- Environment extension to store `remark ...`. -/ | ||
initialize remarkExtension : SimplePersistentEnvExtension RemarkInfo (Array RemarkInfo) ← | ||
registerSimplePersistentEnvExtension { | ||
name := `remarkExtension | ||
addEntryFn := fun arr remarkInfoT => arr.push remarkInfoT | ||
addImportedFn := fun es => es.foldl (· ++ ·) #[] | ||
} | ||
|
||
/-- A remark is a string used for important information. -/ | ||
syntax (name := remark_syntax) "remark " ident ":=" str : command | ||
|
||
/-- Elaborator for the `note ...` command -/ | ||
@[command_elab remark_syntax] | ||
def elabRemark : Lean.Elab.Command.CommandElab := fun stx => | ||
match stx with | ||
| `(remark $n := $s) => do | ||
let str : String := s.getString | ||
let pos := stx.getPos? | ||
match pos with | ||
| some pos => do | ||
let env ← getEnv | ||
let fileMap ← getFileMap | ||
let filePos := fileMap.toPosition pos | ||
let line := filePos.line | ||
let modName := env.mainModule | ||
let nameSpace := (← getCurrNamespace) | ||
|
||
let noteInfo : RemarkInfo := { | ||
content := str, | ||
fileName := modName, | ||
line := line, | ||
name := n.getId, | ||
nameSpace := nameSpace} | ||
modifyEnv fun env => remarkExtension.addEntry env noteInfo | ||
| none => throwError "Invalid syntax for `note` command" | ||
| _ => throwError "Invalid syntax for `note` command" | ||
|
||
end HepLean |
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,44 @@ | ||
/- | ||
Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved. | ||
Released under Apache 2.0 license. | ||
Authors: Joseph Tooby-Smith | ||
-/ | ||
import HepLean.Meta.Remark.Basic | ||
/-! | ||
## Underlying structure for remarks | ||
-/ | ||
|
||
namespace HepLean | ||
open Lean System Meta | ||
|
||
/-- All remarks in the enviroment. -/ | ||
def Name.allRemarkInfo : MetaM (List RemarkInfo) := do | ||
let env ← getEnv | ||
let allRemarks := (remarkExtension.getState env) | ||
pure allRemarks.toList | ||
|
||
/-- The full name of a remark (name and namespace). -/ | ||
def RemarkInfo.toFullName (r : RemarkInfo) : Name := | ||
if r.nameSpace != .anonymous then | ||
(r.nameSpace.toString ++ "." ++ r.name.toString).toName | ||
else | ||
r.name | ||
|
||
/-- A Bool which is true if a name correponds to a remark. -/ | ||
def RemarkInfo.IsRemark (n : Name) : MetaM Bool := do | ||
let allRemarks ← Name.allRemarkInfo | ||
let r := allRemarks.find? (fun r => r.toFullName = n) | ||
match r with | ||
| some _ => pure true | ||
| none => pure false | ||
|
||
/-- Gets the remarkInfo from a name corresponding to a remark.. -/ | ||
def RemarkInfo.getRemarkInfo (n : Name) : MetaM RemarkInfo := do | ||
let allRemarks ← Name.allRemarkInfo | ||
let r := allRemarks.find? (fun r => r.toFullName = n) | ||
match r with | ||
| some r => pure r | ||
| none => throwError s!"No remark named {n}" | ||
|
||
end HepLean |
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
Oops, something went wrong.