Skip to content

Commit 489f162

Browse files
In Main.lean:
- Removed the parseNatWithUnderscores function and its doc comments with issue references - Simplified getMaxHeartbeats to use flag.as! Nat directly for the CLI flag and s.toNat? for the environment variable - Changed the max-heartbeats flag type from String to Nat in both singleCmd and genCoreCmd - Removed the "Supports underscores as separators" mention from flag descriptions In README.md: - Removed the "Underscores can be used as separators for readability" sentence (the examples still show underscores since they will work in a version of Lean4 that includes this merged PR: leanprover/lean4#11541
1 parent 130caf7 commit 489f162

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

Main.lean

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,13 @@ open DocGen4 Lean Cli
66

77
def defaultMaxHeartbeats : Nat := 100_000_000
88

9-
/-- Parse a natural number, allowing underscores as separators (e.g., "100_000_000").
10-
11-
See discussion: https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/String.2EtoNat.3F.20and.20String.2EtoInt.3F.20handling.20underscores/with/562357458
12-
See this related issue: https://github.com/leanprover/lean4/issues/11538
13-
-/
14-
def parseNatWithUnderscores (s : String) : Option Nat :=
15-
(s.replace "_" "").toNat?
16-
179
/-- Get maxHeartbeats from CLI flag, falling back to environment variable, then default. -/
1810
def getMaxHeartbeats (p : Parsed) : IO Nat := do
1911
match p.flag? "max-heartbeats" with
20-
| some flag => pure <| (parseNatWithUnderscores (flag.as! String)).getD defaultMaxHeartbeats
12+
| some flag => pure <| flag.as! Nat
2113
| none => do
2214
match ← IO.getEnv "DOCGEN_MAX_HEARTBEATS" with
23-
| some s => pure <| (parseNatWithUnderscores s).getD defaultMaxHeartbeats
15+
| some s => pure <| s.toNat?.getD defaultMaxHeartbeats
2416
| none => pure defaultMaxHeartbeats
2517

2618
def getTopLevelModules (p : Parsed) : IO (List String) := do
@@ -95,18 +87,13 @@ def runBibPrepassCmd (p : Parsed) : IO UInt32 := do
9587
| _ => throw <| IO.userError "there should be exactly one source file"
9688
return 0
9789

98-
/--
99-
See discussion: https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/String.2EtoNat.3F.20and.20String.2EtoInt.3F.20handling.20underscores/with/562357458
100-
If https://github.com/leanprover/lean4/issues/11538 is resolved, change "max-heartbeats" to be of type Nat directly.
101-
See: https://github.com/leanprover/lean4/pull/11541
102-
-/
10390
def singleCmd := `[Cli|
10491
single VIA runSingleCmd;
10592
"Only generate the documentation for the module it was given, might contain broken links unless all documentation is generated."
10693

10794
FLAGS:
10895
b, build : String; "Build directory."
109-
"max-heartbeats" : String; "Maximum heartbeats for elaboration (default: 100_000_000). Supports underscores as separators. Can also be set via DOCGEN_MAX_HEARTBEATS env var."
96+
"max-heartbeats" : Nat; "Maximum heartbeats for elaboration (default: 100_000_000). Can also be set via DOCGEN_MAX_HEARTBEATS env var."
11097

11198
ARGS:
11299
module : String; "The module to generate the HTML for. Does not have to be part of topLevelModules."
@@ -128,7 +115,7 @@ def genCoreCmd := `[Cli|
128115
FLAGS:
129116
b, build : String; "Build directory."
130117
m, manifest : String; "Manifest output, to list all the files generated."
131-
"max-heartbeats" : String; "Maximum heartbeats for elaboration (default: 100_000_000). Supports underscores as separators. Can also be set via DOCGEN_MAX_HEARTBEATS env var."
118+
"max-heartbeats" : Nat; "Maximum heartbeats for elaboration (default: 100_000_000). Can also be set via DOCGEN_MAX_HEARTBEATS env var."
132119

133120
ARGS:
134121
module : String; "The module to generate the HTML for."

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ The different options are:
9292
Generation of equations for definitions is enabled by default, but can be disabled by setting the `DISABLE_EQUATIONS` environment variable to `1`.
9393

9494
## Max heartbeats
95-
The maximum number of heartbeats for elaboration can be configured by setting the `DOCGEN_MAX_HEARTBEATS` environment variable. The default is `100_000_000`. Underscores can be used as separators for readability. For example:
95+
The maximum number of heartbeats for elaboration can be configured by setting the `DOCGEN_MAX_HEARTBEATS` environment variable. The default is `100_000_000`. For example:
9696
```
9797
DOCGEN_MAX_HEARTBEATS=200_000_000 lake build YourLibraryName:docs
9898
```

0 commit comments

Comments
 (0)