Repository: tweag/nickel
Pull request #1097 (2023-02-02 16:42:58)

Use enum tags for symbolic string prefixes


Patch:
diff --git a/src/parser/grammar.lalrpop b/src/parser/grammar.lalrpop
index 2f578b7a..2be6e18b 100644
--- a/src/parser/grammar.lalrpop
+++ b/src/parser/grammar.lalrpop
@@ -519,7 +519,7 @@ StrChunks: RichTerm = {
 
             RichTerm::from(build_record([
                 (FieldPathElem::Ident("tag".into()), RichTerm::from(Term::Enum("SymbolicString".into()))),
-                (FieldPathElem::Ident("prefix".into()), RichTerm::from(Term::Str(prefix.to_owned()))),
+                (FieldPathElem::Ident("prefix".into()), RichTerm::from(Term::Enum(prefix.into()))),
                 (FieldPathElem::Ident("fragments".into()), RichTerm::from(Term::Array(terms, Default::default())))
             ], Default::default()))
         } else {


Test patch:
diff --git a/src/parser/tests.rs b/src/parser/tests.rs
index 9b3d6e37..d2fba7b2 100644
--- a/src/parser/tests.rs
+++ b/src/parser/tests.rs
@@ -47,7 +47,7 @@ fn mk_symbolic_single_chunk(prefix: &str, s: &str) -> RichTerm {
             ),
             (
                 FieldPathElem::Ident("prefix".into()),
-                RichTerm::from(Term::Str(prefix.to_owned())),
+                RichTerm::from(Term::Enum(prefix.into())),
             ),
             (
                 FieldPathElem::Ident("fragments".into()),
diff --git a/tests/integration/pass/symbolic-strings.ncl b/tests/integration/pass/symbolic-strings.ncl
index 4895789e..6de24f3d 100644
--- a/tests/integration/pass/symbolic-strings.ncl
+++ b/tests/integration/pass/symbolic-strings.ncl
@@ -2,22 +2,22 @@ let {check, ..} = import "lib/assert.ncl" in
 let sym = fun prefix_ fragments_ => { tag = `SymbolicString, prefix = prefix_, fragments = fragments_ } in
 [
   # Static symbolic string
-  foo-s%"hello, world"% == sym "foo" ["hello, world"] ,
+  foo-s%"hello, world"% == sym `foo ["hello, world"] ,
   # Interpolating a string
   let s = "test" in
-  foo-s%"This is a %{s}"% == sym "foo" ["This is a ", "test"],
+  foo-s%"This is a %{s}"% == sym `foo ["This is a ", "test"],
   # Interpolating an interpolated string
   let f = "f" in
-  foo-s%"abc %{"de%{f}"}"% == sym "foo" ["abc ", "def"],
+  foo-s%"abc %{"de%{f}"}"% == sym `foo ["abc ", "def"],
   # Interpolating a number
-  foo-s%"num: %{100}"% == sym "foo" ["num: ", 100],
+  foo-s%"num: %{100}"% == sym `foo ["num: ", 100],
   # Interpolating a bool
-  foo-s%"bool: %{true}"% == sym "foo" ["bool: ", true],
+  foo-s%"bool: %{true}"% == sym `foo ["bool: ", true],
   # Interpolating an array
-  foo-s%"array: %{[true, 1, "yes"]}"% == sym "foo" ["array: ", [true, 1, "yes"]],
+  foo-s%"array: %{[true, 1, "yes"]}"% == sym `foo ["array: ", [true, 1, "yes"]],
   # Interpolating a record
   let r = { a = 1, b = false } in
-  foo-s%"record: %{r}"% == sym "foo" ["record: ", r],
+  foo-s%"record: %{r}"% == sym `foo ["record: ", r],
   # Interpolating multiple values
   let str = "some string" in
   let num = 999.999 in
@@ -31,7 +31,7 @@ let sym = fun prefix_ fragments_ => { tag = `SymbolicString, prefix = prefix_, f
      4. %{array}
      5. %{record}"%
   in
-  let expected = sym "foo" [
+  let expected = sym `foo [
     "1. ", str,
     "\n2. ", num,
     "\n3. ", bool,