File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -232,6 +232,37 @@ section Configuration
232
232
| "" => none
233
233
| s => s.toInt?
234
234
235
+ open Lean
236
+
237
+ /-- We provide a type synonym here for `Name`, which will carry a `ParseableType ModuleName`
238
+ instance, supporting parsing either a module name (e.g. `Mathlib.Topology.Basic`)
239
+ or a relative path to a Lean file (e.g. `Mathlib/Topology/Basic.lean`). -/
240
+ def ModuleName := Name
241
+
242
+ /-- Check if a `ModuleName` has no `.num` components, and is not `.anonymous`. -/
243
+ def ModuleName.isValid : ModuleName → Bool
244
+ | .anonymous => false
245
+ | m => loop m
246
+ where
247
+ loop : ModuleName → Bool
248
+ | .anonymous => true
249
+ | .str pre _ => loop pre
250
+ | .num .. => false
251
+
252
+ open System in
253
+ /-- A custom command-line argument parser that allows either relative paths to Lean files,
254
+ (e.g. `Mathlib/Topology/Basic.lean`) or the module name (e.g. `Mathlib.Topology.Basic`). -/
255
+ instance : ParseableType ModuleName where
256
+ name := "ModuleName"
257
+ parse? s := do
258
+ if s.endsWith ".lean" then
259
+ let pathComponents := (s : FilePath).withExtension "" |>.components
260
+ return pathComponents.foldl Name.mkStr Name.anonymous
261
+ else
262
+ let name := String.toName s
263
+ guard <| ModuleName.isValid name
264
+ return name
265
+
235
266
instance [inst : ParseableType α] : ParseableType (Array α) where
236
267
name :=
237
268
if inst.name.contains ' ' then
Original file line number Diff line number Diff line change 1
- leanprover/lean4:nightly-2022-11-20
1
+ leanprover/lean4:nightly-2023-08-15
You can’t perform that action at this time.
0 commit comments