src/paths.bend
bolt@1.18.0.0 · 42 lines · 0 definitions
1# src/paths: what a path names, read by its segments, never by a suffix or a
2# substring. A law file is one whose last segment is exactly LAWS.bend or
3# PROOF.bend, so OUTLAWS.bend is not one; a test is one with a directory
4# segment exactly `tests`, so contests/ is not one. Pure.
5import Base
6import bolt@1.18.0.0/src/lazy/lazy.bend as Lazy
7
8# the last of the segments, or the one before when there are none
9def base.go(segs: List<&2, String>, last: String) -> String:
10 match segs:
11 case Nil{}:
12 last
13 case Con{s, rest}:
14 base.go(rest, s)
15
16# a path's last segment
17def base(path: String) -> String:
18 base.go(String.split(path, '/'), "")
19
20# is some segment but the last exactly `tests`?
21def tested(segs: List<&2, String>) -> Bool:
22 match segs:
23 case Nil{}:
24 False{}
25 case Con{+s, +rest}:
26 Lazy.or_else(Bool.and(String.eq(s, "tests"), Bool.not(List.is_empty(&2, String, rest))), _u => tested(rest))
27
28# is the file under a `tests` directory?
29def is_test(path: String) -> Bool:
30 tested(String.split(path, '/'))
31
32# is it a LAWS.bend?
33def is_laws(path: String) -> Bool:
34 String.eq(base(path), "LAWS.bend")
35
36# is it a PROOF.bend?
37def is_proof(path: String) -> Bool:
38 String.eq(base(path), "PROOF.bend")
39
40# is it a LAWS.bend or a PROOF.bend?
41def is_law_file(+path: String) -> Bool:
42 Bool.or(is_laws(path), is_proof(path))