repl: support inherit statements and multiple bindings#15082
Merged
xokdvium merged 3 commits intoNixOS:masterfrom Feb 25, 2026
Merged
repl: support inherit statements and multiple bindings#15082xokdvium merged 3 commits intoNixOS:masterfrom
xokdvium merged 3 commits intoNixOS:masterfrom
Conversation
Fixes NixOS#15053 This adds support for inherit statements and multiple bindings per line in nix repl: nix-repl> a = { x = 1; y = 2; } nix-repl> inherit (a) x y nix-repl> x + y 3 nix-repl> p = 1; q = 2; nix-repl> p + q 3 Design ------ The REPL now uses a parser-based approach instead of ad-hoc regex matching. It tries parsing input in order: 1. As an expression (using the regular parser entry point) 2. As bindings (using a new REPL_BINDINGS entry point) 3. As bindings with an appended semicolon (for convenience) The third attempt allows users to omit the trailing semicolon for single statements like "inherit (a) x" or "foo = 1". A separate REPL_BINDINGS parser entry point is required because combining expressions and bindings in the same production causes reduce/reduce conflicts: "ID ." is ambiguous between attribute access (a.b) and the start of a nested binding path (a.b = 1). Alternatives considered ----------------------- GLR parsing: Would resolve the ambiguity but risks parsing performance regression for all Nix code, not just the REPL. Duplicated grammar: A REPL-specific repl_binds production that duplicates binds1 rules. Rejected to avoid maintenance burden and grammar drift. Single binding per line: Simpler but less useful. The current approach reuses binds1 directly, getting multiple bindings and nested attribute paths for free. Tradeoffs --------- Binding input may be parsed twice (once as expression, then as bindings). This is acceptable for interactive REPL use where input is typically small and latency from parsing is negligible. Error messages preserve the original input even when the semicolon- appended parse is attempted, so users see "inherit (a) y" in errors rather than "inherit (a) y;".
xokdvium
reviewed
Feb 14, 2026
xokdvium
reviewed
Feb 14, 2026
xokdvium
approved these changes
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
inheritstatements innix repl#15053This adds support for
inheritstatements and multiple bindings perline in
nix repl:Details
Design
The REPL now uses a parser-based approach instead of ad-hoc regex
matching. It tries parsing input in order:
The third attempt allows users to omit the trailing semicolon for
single statements like
inherit (a) xorfoo = 1.A separate REPL_BINDINGS parser entry point is required because
combining expressions and bindings in the same production causes
reduce/reduce conflicts:
ID .is ambiguous between attribute access(
a.b) and the start of a nested binding path (a.b = 1).Alternatives considered
GLR parsing: Would resolve the ambiguity but risks parsing
performance regression for all Nix code, not just the REPL.
Duplicated grammar: A REPL-specific
repl_bindsproduction thatduplicates
binds1rules. Rejected to avoid maintenance burden andgrammar drift.
Single binding per line: Simpler but less useful. The current
approach reuses
binds1directly, getting multiple bindings andnested attribute paths for free.
Tradeoffs
Binding input may be parsed twice (once as expression, then as
bindings). This is acceptable for interactive REPL use where input is
typically small and latency from parsing is negligible.
Error messages preserve the original input even when the semicolon-
appended parse is attempted, so users see
inherit (a) yin errorsrather than
inherit (a) y;.Context
inheritstatements innix repl#15053Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.