From 9b8ba915c8c006f55c12a8af927810a901e7a378 Mon Sep 17 00:00:00 2001 From: sterni Date: Wed, 4 Jan 2023 13:29:58 +0100 Subject: fix(tvix/eval): ' is allowed in nonfirst position in Nix identifiers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this is_valid_nix_identifier should line up with the upstream lexer definition: ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]* While we're working on this, add a simple test checking the various formatting rules. Interestingly, it would not be suitable as an identity test, since you have to write { "assert" = null; } in order to avoid an evaluation error, but C++ Nix is happy to print this as { assert = null; } – maybe should be considered to be a bug. Change-Id: I0a4e1ccb5033a80f3767fb8d1c4bba08d303c5d8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7744 Autosubmit: sterni Tested-by: BuildkiteCI Reviewed-by: tazjin --- .../tvix_tests/eval-okay-identifier-formatting.exp | 1 + .../tvix_tests/eval-okay-identifier-formatting.nix | 30 ++++++++++++++++++++++ tvix/eval/src/value/string.rs | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.nix (limited to 'tvix/eval/src') diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.exp new file mode 100644 index 000000000000..074f5f07f5f0 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.exp @@ -0,0 +1 @@ +{ "'quoted'" = false; "-20°" = false; "2normal" = false; "45 44 43-'3 2 1" = false; "9front" = false; Very2Normal = true; VeryNormal = true; _'12 = true; "_'12.5" = false; __internal = true; _internal = true; abort = true; assert = true; "attr.path" = false; false = true; foldl' = true; normal = true; normal2 = true; null = true; or = true; throw = true; true = true; x = true; x' = true; x'' = true; "😀" = false; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.nix new file mode 100644 index 000000000000..8f9aa2823801 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.nix @@ -0,0 +1,30 @@ +{ + __internal = true; + _internal = true; + normal = true; + VeryNormal = true; + normal2 = true; + Very2Normal = true; + _'12 = true; + foldl' = true; + x = true; + x' = true; + x'' = true; + + true = true; + false = true; + null = true; + or = true; + "assert" = true; # -ish + throw = true; + abort = true; + + "9front" = false; + "2normal" = false; + "-20°" = false; + "45 44 43-'3 2 1" = false; + "attr.path" = false; + "'quoted'" = false; + "_'12.5" = false; + "😀" = false; +} diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs index 5b2cb83a17de..9ebdf687d284 100644 --- a/tvix/eval/src/value/string.rs +++ b/tvix/eval/src/value/string.rs @@ -168,7 +168,7 @@ fn is_valid_nix_identifier(s: &str) -> bool { } for c in chars { match c { - 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '-' => (), + 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '-' | '\'' => (), _ => return false, } } -- cgit 1.4.1