Skip to content

Commit 9165a56

Browse files
committed
Add tracking of rule prefixes
This adds tracking of rule prefixes (like `asm.ts-args` is an interior prefix of `asm.ts-args.syntax`). This will be used for test linking, to check for tests that link to these. I'm not sure what we'll want to do with these long-term, whether we want to allow linking these "uber" rules, or remove them, or just warn about them.
1 parent 160bb6a commit 9165a56

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

mdbook-spec/src/rules.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use mdbook::book::Book;
55
use mdbook::BookItem;
66
use once_cell::sync::Lazy;
77
use regex::{Captures, Regex};
8-
use std::collections::BTreeMap;
8+
use std::collections::{BTreeMap, HashSet};
99
use std::path::PathBuf;
1010

1111
/// The Regex for rules like `r[foo]`.
@@ -24,6 +24,10 @@ pub struct Rules {
2424
/// trying to access the source files (`source_path`), or creating links
2525
/// in the output (`path`).
2626
pub def_paths: BTreeMap<String, (PathBuf, PathBuf)>,
27+
/// Set of rule name prefixes that have more specific rules within.
28+
///
29+
/// For example, `asm.ts-args` is an interior prefix of `asm.ts-args.syntax`.
30+
pub interior_prefixes: HashSet<String>,
2731
}
2832

2933
impl Spec {
@@ -58,6 +62,12 @@ impl Spec {
5862
eprintln!("warning: {message}");
5963
}
6064
}
65+
let mut parts: Vec<_> = rule_id.split('.').collect();
66+
while !parts.is_empty() {
67+
parts.pop();
68+
let prefix = parts.join(".");
69+
rules.interior_prefixes.insert(prefix);
70+
}
6171
});
6272
}
6373

0 commit comments

Comments
 (0)