gcao/gene-new

String interpolation

Closed this issue · 0 comments

gcao commented

String interpolation

Regular strings:
"..."
"""..."""

Interpolated strings:
#"..."
#"""..."""

Below forms are supported:
#{a}
#{^a b} = #{{^a b}}
#[a b] = #{[a b]}
#(a b) = #{(a b)}

Examples:
#"ab#{cd}ef" = #"ab# cd #ef" = (#Str "ab" cd "ef") : spaces are allowed before and after cd
#"ab#{1.5}ef" = (#Str "ab" 1.5 "ef")
#"ab#(c d)ef" = (#Str "ab" (c d) "ef") : spaces are not allowed before (. Spaces after ) are part of the string.
#"ab#[c d]ef" = (#Str "ab" [c d] "ef")
#"ab#{^c d}ef" = (#Str "ab" {^c d} "ef")

To embed comments in an interpolated string, use "#<>#"
#"ab##ef" = (#Str "ab" "ef")

The parser should convert (#Str "ab" "ef") to "abef" to avoid unnecessary evaluation later.

(#Str ...) will be interpreted/evaluated by the Gene language