Skip to content

feat(parsing): add Nix language parser#106

Open
antono wants to merge 4 commits into
bartolli:mainfrom
antono:feature/parser-for-nix-lang
Open

feat(parsing): add Nix language parser#106
antono wants to merge 4 commits into
bartolli:mainfrom
antono:feature/parser-for-nix-lang

Conversation

@antono
Copy link
Copy Markdown
Contributor

@antono antono commented May 21, 2026

Purpose

Adds full Nix expression-language support to codanna, enabling symbol extraction, call tracking, import resolution, and scope-aware lookup for .nix files (NixOS configs, Home Manager modules, flakes, packages, overlays).

Implementation

Built on tree-sitter-nix 0.3.0 (nix-community, ABI-14/15), wired identically to the existing Lua parser (no trait overhead, attrset-centric scoping).

New files — src/parsing/nix/

File Purpose
definition.rs NixLanguageLanguageDefinition trait, registers the grammar
parser.rs NixParser — symbol extraction, call tracking, import resolution
behavior.rs NixBehaviorLanguageBehavior trait, scope factory
resolution.rs NixResolutionContext — lexical + attrset scope chain
audit.rs ABI-15 grammar coverage audit (node-type completeness)
mod.rs re-exports + register_nix_language()

Symbols extracted

  • let-binding identifiers
  • Attribute-set keys (top-level and nested)
  • Function parameters (plain, @-pattern with default)
  • inherit names
  • rec-attrset bindings

Edited — existing files

Cargo.toml, parsing/mod.rs, parsing/registry.rs, parsing/language.rs, tests/parsers_tests.rs, contributing/parsers/grammar-versions.lock

Tests

  • tests/parsers/nix/test_symbol_extraction.rs — 10 cases covering let bindings, attrsets, functions, inherit, rec
  • tests/parsers/nix/test_call_tracking.rs — 8 cases covering direct calls, lib references, pkgs.*, import
  • tests/exploration/abi15_grammar_audit/nix.rs — ABI-15 coverage completeness
  • Fixtures: tests/fixtures/nix/{basic,functions,imports}.nix
  • Examples: examples/nix/{main,comprehensive}.nix

Implementation plan

Full design doc with trait architecture, module wiring, node mapping, and grammar audit:
contributing/parsers/nix/IMPLEMENTATION_PLAN.md

Supporting docs:

antono added 2 commits May 21, 2026 14:14
Execution plan for adding Nix language support to codanna under the
per-parser docs convention (contributing/parsers/nix/).

- Compatibility verdict for tree-sitter-nix 0.3.0 (LanguageFn / ABI-15,
  compatible with tree-sitter 0.26)
- Module + wiring map, trait architecture, and Nix->symbol mapping
- Parser traversal and scope-resolution logic
- 6-phase execution plan with touch-point checklist
- 5 Mermaid diagrams (GitHub-render-safe, quoted labels)
- tree-sitter-nix 0.3.0 via nix-community (ABI-15)
- Parses attrsets, rec attrsets, let expressions, lambdas (universal + formals),
  inherit / inherit_from, apply_expression, select_expression
- 100% key-node coverage (18/18) in audit
- Language::Nix wired into registry, factory, language.rs, io/parse.rs
- default_enabled = false (flip to true at release)
- flake.lock → rustc 1.95.0 (required by sysinfo 0.39.2)
- 40 new tests across unit, integration, and abi15 audit
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

❌ Quick checks failure

antono added 2 commits May 21, 2026 19:53
Fix cargo fmt check failures on CI.
Prior commit used standalone rustfmt which sorts imports differently
from cargo fmt run inside the nix devshell. Use nix develop going
forward to match CI exactly.
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.

1 participant