Skip to content

Distinguish different types of Nix paths at the type level #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

domenkozar
Copy link

@domenkozar domenkozar commented Apr 20, 2025

#166

I'm not entirely sure about the special casing for UPDATE, there could be a better way?

cc @oberblastmeister

@domenkozar
Copy link
Author

Any chance for a review?

@oberblastmeister
Copy link
Contributor

Sorry for leaving this. I think it would be better to create a single NODE_PATH that is the parent of all TOKEN_PATH_* tokens, similar to how the NODE_LITERAL node is the parent of TOKEN_INTEGER, TOKEN_FLOAT, etc.

@oberblastmeister
Copy link
Contributor

Ah, but having the single NODE_PATH parent would make it more annoying to distinguish the kind of the entire path.

@domenkozar
Copy link
Author

Yeah :) Note that once this is merged I'll update https://cl.snix.dev/c/snix/+/30323

@domenkozar
Copy link
Author

@oberblastmeister so let's keep it as is or do you think we should have NODE_PATH?

@domenkozar
Copy link
Author

cc @sternenseemann

@oberblastmeister
Copy link
Contributor

I think we can keep it as is. Maybe we can create an enum for the path nodes using the node! macro similar to Expr?

@domenkozar domenkozar force-pushed the path-types branch 2 times, most recently from 2af4cea to fff5eb1 Compare May 2, 2025 10:55
- 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.
@domenkozar
Copy link
Author

domenkozar commented May 2, 2025

@oberblastmeister thanks, I've done that and implemented a hierarchy of traits on top of it to extract parts of the path out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants