From f7980b471273d695aa0b28f2f73e6ee443dfe9eb Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Sun, 14 Feb 2016 01:16:30 -0600 Subject: [PATCH 1/3] Parse `foo-bar = expr` as an assignment. --- nix-repl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix-repl.cc b/nix-repl.cc index 474ad4fc9..25f84a308 100644 --- a/nix-repl.cc +++ b/nix-repl.cc @@ -255,7 +255,7 @@ bool isVarName(const string & s) if (!((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z') || (i >= '0' && i <= '9') || - i == '_' || i == '\'')) + i == '_' || i == '-' || i == '\'')) return false; return true; } From 2111098a3a26d11edf4452f021245b55287c45b8 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Sun, 14 Feb 2016 01:29:48 -0600 Subject: [PATCH 2/3] Don't consider strings starting with - or ' as variable names. --- nix-repl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix-repl.cc b/nix-repl.cc index 25f84a308..5c319f068 100644 --- a/nix-repl.cc +++ b/nix-repl.cc @@ -250,7 +250,8 @@ static int runProgram(const string & program, const Strings & args) bool isVarName(const string & s) { - // FIXME: not quite correct. + if (s.size() > 0 && (s[0] == '-' || s[0] == '\'')) + return false; for (auto & i : s) if (!((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z') || From f30fd9c47b1ae7a48f4854c86b3ad5e038845aa3 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Sun, 14 Feb 2016 01:50:47 -0600 Subject: [PATCH 3/3] Don't consider empty strings or strings beginning with numbers as variable names. --- nix-repl.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nix-repl.cc b/nix-repl.cc index 5c319f068..1077f5d8f 100644 --- a/nix-repl.cc +++ b/nix-repl.cc @@ -250,8 +250,9 @@ static int runProgram(const string & program, const Strings & args) bool isVarName(const string & s) { - if (s.size() > 0 && (s[0] == '-' || s[0] == '\'')) - return false; + if (s.size() == 0) return false; + char c = s[0]; + if ((c >= '0' && c <= '9') || c == '-' || c == '\'') return false; for (auto & i : s) if (!((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z') ||