Skip to content

Commit d84111e

Browse files
committed
Distinguish different types of Nix paths at the type level
- Added distinct token and node types for different path varieties: - PathAbs: Absolute paths starting with `/` (e.g., `/nix/store/...`) - PathRel: Relative paths (e.g., `./foo`, `foo/bar`) - PathHome: Home-relative paths starting with `~/` (e.g., `~/foo/bar`) - PathSearch: NIX_PATH expressions (e.g., `<nixpkgs>`) - Created `InterpolatablePath` trait for paths that support interpolation (all except search paths) - Added helper methods to path content for easier path type checking and access through `match_path`, `is_search`, `is_interpolatable`, etc. This allows code to determine what kind of path it's dealing with without having to re-parse the path string, improving type safety, correctness, and making path-specific operations more explicit.
1 parent e049bd2 commit d84111e

31 files changed

+546
-128
lines changed

flake.lock

Lines changed: 24 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ mod interpol;
55
mod nodes;
66
mod operators;
77
mod path_util;
8+
9+
pub use path_util::{InterpolatablePath, Path, PathNode, PathPart, SearchPath};
810
mod str_util;
911
mod tokens;
1012

src/ast/nodes.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ node! {
176176
IfElse,
177177
Select,
178178
Str,
179-
Path,
179+
PathAbs,
180+
PathRel,
181+
PathHome,
182+
PathSearch,
180183
Literal,
181184
Lambda,
182185
LegacyLet,
@@ -279,7 +282,20 @@ impl InheritFrom {
279282
tg! { r_paren_token, ')' }
280283
}
281284

282-
node! { #[from(NODE_PATH)] struct Path; }
285+
node! { #[from(NODE_PATH_ABS)] struct PathAbs; }
286+
node! { #[from(NODE_PATH_REL)] struct PathRel; }
287+
node! { #[from(NODE_PATH_HOME)] struct PathHome; }
288+
node! { #[from(NODE_PATH_SEARCH)] struct PathSearch; }
289+
290+
node! {
291+
#[from(
292+
PathAbs,
293+
PathRel,
294+
PathHome,
295+
PathSearch,
296+
)]
297+
enum Path;
298+
}
283299

284300
node! { #[from(NODE_STRING)] struct Str; }
285301

0 commit comments

Comments
 (0)