From f4b04a1b8cd882e25fee592c819650c9b7e8566b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 18 Aug 2024 14:44:15 -0400 Subject: Improved syntax for dollar-string literals --- test/arrays.tm | 4 ++-- test/corecursive_func.tm | 8 ++++---- test/defer.tm | 4 ++-- test/enums.tm | 8 ++++---- test/for.tm | 8 ++++---- test/integers.tm | 4 ++-- test/iterators.tm | 6 +++--- test/lambdas.tm | 4 ++-- test/lang.tm | 14 +++++++------- test/tables.tm | 4 ++-- test/text.tm | 22 +++++++++++++++++++--- 11 files changed, 51 insertions(+), 35 deletions(-) (limited to 'test') diff --git a/test/arrays.tm b/test/arrays.tm index c870ce04..76507c5b 100644 --- a/test/arrays.tm +++ b/test/arrays.tm @@ -23,7 +23,7 @@ func main(): str := "" for i,x in arr: - str ++= "({i},{x})" + str ++= "($i,$x)" >> str = "(1,10)(2,20)(3,30)" @@ -148,7 +148,7 @@ func main(): xs := ["A", "B", "C", "D"] for i,x in xs:to(-2): for y in xs:from(i+1): - say("{x}{y}") + say("$(x)$(y)") do: >> nums := [-7, -4, -1, 2, 5] diff --git a/test/corecursive_func.tm b/test/corecursive_func.tm index a5c13dde..168300d4 100644 --- a/test/corecursive_func.tm +++ b/test/corecursive_func.tm @@ -1,14 +1,14 @@ func ping(x:Int)->[Text]: if x > 0: - return ["ping: {x}"] ++ pong(x-1) + return ["ping: $x"] ++ pong(x-1) else: - return ["ping: {x}"] + return ["ping: $x"] func pong(x:Int)->[Text]: if x > 0: - return ["pong: {x}"] ++ ping(x-1) + return ["pong: $x"] ++ ping(x-1) else: - return ["pong: {x}"] + return ["pong: $x"] func main(): >> ping(3) diff --git a/test/defer.tm b/test/defer.tm index 121878b1..deccaa70 100644 --- a/test/defer.tm +++ b/test/defer.tm @@ -16,7 +16,7 @@ func main(): for word in ["first", "second", "third"]: defer: - say("Got {word} deferred") + say("Got $word deferred") if word == "second": say("") @@ -27,7 +27,7 @@ func main(): for i in 3: defer: - say("Inner loop deferred {i}") + say("Inner loop deferred $i") if i == 2: say("") diff --git a/test/enums.tm b/test/enums.tm index 65ef6398..b734d487 100644 --- a/test/enums.tm +++ b/test/enums.tm @@ -5,15 +5,15 @@ func choose_text(f:Foo)->Text: when f is Zero: return "Zero" is One(one): - return "One: {one}" + return "One: $one" is Two(x, y): - return "Two: x={x}, y={y}" + return "Two: x=$x, y=$y" is Three(three): - return "Three: {three}" + return "Three: $three" is Four: return "Four" else: - return "else: {f}" + return "else: $f" func main(): >> Foo.Zero diff --git a/test/for.tm b/test/for.tm index a050c892..6ac77be6 100644 --- a/test/for.tm +++ b/test/for.tm @@ -2,7 +2,7 @@ func all_nums(nums:[Int])->Text: result := "" for num in nums: - result ++= "{num}," + result ++= "$num," else: return "EMPTY" return result @@ -10,7 +10,7 @@ func all_nums(nums:[Int])->Text: func labeled_nums(nums:[Int])->Text: result := "" for i,num in nums: - result ++= "{i}:{num}," + result ++= "$i:$num," else: return "EMPTY" return result @@ -18,14 +18,14 @@ func labeled_nums(nums:[Int])->Text: func table_str(t:{Text:Text})->Text: str := "" for k,v in t: - str ++= "{k}:{v}," + str ++= "$k:$v," else: return "EMPTY" return str func table_key_str(t:{Text:Text})->Text: str := "" for k in t: - str ++= "{k}," + str ++= "$k," else: return "EMPTY" return str diff --git a/test/integers.tm b/test/integers.tm index 36119f01..11603b22 100644 --- a/test/integers.tm +++ b/test/integers.tm @@ -28,7 +28,7 @@ func main(): nums := "" for x in 5: - nums ++= "{x}," + nums ++= "$x," >> nums = "1,2,3,4,5," @@ -79,6 +79,6 @@ func main(): for in 20: >> n := Int.random(-999999, 999999) >> d := Int.random(-999, 999) - //! n={n}, d={d}: + //! n=$n, d=$d: >> (n/d)*d + (n mod d) == n = yes diff --git a/test/iterators.tm b/test/iterators.tm index 999194d9..1f7ce342 100644 --- a/test/iterators.tm +++ b/test/iterators.tm @@ -19,15 +19,15 @@ func range(first:Int, last:Int)->func()->RangeIteration: func main(): values := ["A", "B", "C", "D"] - >> ((++) "({foo}{baz})" for foo, baz in pairwise(values)) + >> ((++) "($(foo)$(baz))" for foo, baz in pairwise(values)) = "(AB)(BC)(CD)" - >> ["{foo}{baz}" for foo, baz in pairwise(values)] + >> ["$(foo)$(baz)" for foo, baz in pairwise(values)] = ["AB", "BC", "CD"] do: result := [:Text] for foo, baz in pairwise(values): - result:insert("{foo}{baz}") + result:insert("$(foo)$(baz)") >> result = ["AB", "BC", "CD"] diff --git a/test/lambdas.tm b/test/lambdas.tm index 40f24abb..8d543bfc 100644 --- a/test/lambdas.tm +++ b/test/lambdas.tm @@ -12,7 +12,7 @@ func main(): >> add_one(10) = 11 - >> shout := func(msg:Text): say("{msg:upper()}!") + >> shout := func(msg:Text): say("$(msg:upper())!") >> shout("hello") >> asdf := add_one @@ -36,7 +36,7 @@ func main(): fn := func(): return func(): return func(): - defer: //! {outer} + defer: //! $outer return outer >> fn()()() = "Hello" diff --git a/test/lang.tm b/test/lang.tm index 01551e27..dfe1c663 100644 --- a/test/lang.tm +++ b/test/lang.tm @@ -1,5 +1,5 @@ lang HTML: - HEADER := $HTML$"" + HEADER := $HTML"" func escape(t:Text)->HTML: t = t:replace("&", "&") t = t:replace("<", "<") @@ -9,25 +9,25 @@ lang HTML: return HTML.from_unsafe_text(t) func escape_int(i:Int)->HTML: - return HTML.from_unsafe_text("{i}") + return HTML.from_unsafe_text("$i") func paragraph(content:HTML)->HTML: - return $HTML$"

$content

" + return $HTML"

$content

" func main(): >> HTML.HEADER = $HTML"" >> user := "I <3 hax" - >> html := $HTML$"Hello $user!" + >> html := $HTML"Hello $user!" = $HTML"Hello I <3 hax!" - >> html ++ $HTML$"
" + >> html ++ $HTML"
" = $HTML"Hello I <3 hax!
" - >> $HTML{}"{1 + 2}" + >> $HTML"$(1 + 2)" = $HTML"3" - >> $HTML{}"{3_i8}" + >> $HTML"$(3_i8)" = $HTML"3" >> html:paragraph() diff --git a/test/tables.tm b/test/tables.tm index d02a5272..7f8383d8 100644 --- a/test/tables.tm +++ b/test/tables.tm @@ -11,7 +11,7 @@ func main(): t_str := "" for k,v in t: - t_str ++= "({k}:{v})" + t_str ++= "($k:$v)" >> t_str = "(one:1)(two:2)" @@ -42,7 +42,7 @@ func main(): t2_str := "" for k,v in t2: - t2_str ++= "({k}:{v})" + t2_str ++= "($k:$v)" >> t2_str = "(three:3)" diff --git a/test/text.tm b/test/text.tm index 4051a16f..2666b6c8 100644 --- a/test/text.tm +++ b/test/text.tm @@ -1,6 +1,6 @@ func main(): >> str := "Hello Amélie!" - //! Testing strings like {str} + //! Testing strings like $str >> str:upper() = "HELLO AMÉLIE!" @@ -19,7 +19,7 @@ func main(): >> \UE9 == \U65\U301 = yes - >> amelie := "Am{\UE9}lie" + >> amelie := "Am$(\UE9)lie" >> amelie:clusters() = ["A", "m", "é", "l", "i", "e"] : [Text] >> amelie:codepoints() @@ -35,7 +35,7 @@ func main(): >> amelie:num_bytes() = 8 - >> amelie2 := "Am{\U65\U301}lie" + >> amelie2 := "Am$(\U65\U301)lie" >> amelie2:clusters() = ["A", "m", "é", "l", "i", "e"] : [Text] >> amelie2:codepoints() @@ -103,3 +103,19 @@ func main(): " = "line one\nline two" + //! Interpolation tests: + >> "A $(1+2)" + = "A 3" + >> 'A $(1+2)' + = "A $(1+2)" + >> `A $(1+2)` + = "A 3" + + >> $"A $(1+2)" + = "A 3" + >> $$"A $(1+2)" + = "A $(1+2)" + >> $="A =(1+2)" + = "A 3" + >> $(one (nested) two $(1+2)) + = "one (nested) two 3" -- cgit v1.2.3