repl: Always use parser, allow trailing ; in assignments

We now properly shell out to the parser instead of hacking stuff
together with a regex. Stuff we get for free by doing this:

- Optional trailing semicolon
- Declaring nested attribute sets
- String identifiers, and future proofing for eventual grammar
improvements to identifiers
- Dynamic attributes

Change-Id: Ibf1ad815e5e27caf162df05ea5ba5b1b4955d9c9
This commit is contained in:
piegames
2025-04-21 20:19:25 +02:00
parent 930ac12346
commit abb8ad29c0
10 changed files with 240 additions and 40 deletions
@@ -0,0 +1,50 @@
@args -v
Adding variables gives simple user feedback
Lix $VERSION
Type :? for help.
nix-repl> foo = 5
Added foo.
nix-repl> foo = 10
Updated foo.
Optional semicolon at the end, allow setting multiple variables in one line
nix-repl> foo = 2;
Updated foo.
nix-repl> foo = 2; bar = 3;
Updated foo.
Added bar.
String identifiers work
nix-repl> "silly name" = null
Added "silly name".
Attrset syntax works, but without dynamic attrs or merging
nix-repl> foo.bar = "baz"
Updated foo.
nix-repl> foo
{ bar = "baz"; }
nix-repl> foo."this works" = 42
Updated foo.
nix-repl> foo
{ "this works" = 42; }
nix-repl> foo.bar = "baz"; foo.more = "error"
error: attribute 'foo' already defined at «string»:1:18
at «string»:1:12:
1| foo.bar = "baz"; foo.more = "error"
| ^
nix-repl> ${foo} = 10
error: dynamic attributes not allowed in REPL
at «string»:1:1:
1| ${foo} = 10
| ^
@@ -90,8 +90,12 @@ public:
}
session.close();
// Remove references to the checkout path
auto replacedOutLog =
boost::algorithm::replace_all_copy(session.outLog, unitTestData, "$TEST_DATA");
// Remove references to the current version
replacedOutLog =
boost::algorithm::replace_all_copy(replacedOutLog, PACKAGE_VERSION, "$VERSION");
auto cleanedOutLog = trimOutLog(replacedOutLog);
auto parsedOutLog = cli_literate_parser::parse(
@@ -178,6 +182,7 @@ REPL_TEST(regression_9917);
REPL_TEST(regression_9918);
REPL_TEST(regression_l145);
REPL_TEST(regression_l592);
REPL_TEST(repl_input);
REPL_TEST(repl_overlays);
REPL_TEST(repl_overlays_compose);
REPL_TEST(repl_overlays_destructure_without_dotdotdot_errors);