Skip to content

Commit fff5eb1

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 fff5eb1

31 files changed

+556
-128
lines changed

flake.lock

+24-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ast.rs

+4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ 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

13+
pub use tokens::PathContent;
14+
1115
use crate::{NixLanguage, SyntaxKind, SyntaxToken};
1216

1317
pub use expr_ext::LiteralKind;

src/ast/nodes.rs

+18-2
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)