Looks like a good start!
You might also want to handle the $(xxx) form of interpolation (which can 
get pretty tricky I imagine), as well as all of the \ escapes, such as \n, 
\x, \u, \U, etc.

I'd like just this, but with the Swift syntax for interpolation, i.e. 
\(xxx), which doesn't have the problem of causing a frequently used 
character ($) to have to be quoted
(\$) where it wouldn't be in C/C++/Java/etc. (or for LaTex strings).

On Tuesday, January 5, 2016 at 9:34:06 PM UTC-5, Eric Forgy wrote:
>
> Hi,
>
> It's not easy getting my old grey matter to learn new tricks, but I'm 
> slowly learning Julia. I doubt this is worth adding to METADATA, but I find 
> it useful for my work and hope others do too. If there are any ways to 
> improve it, please let me know.
>
> Best regards,
> Eric
>
> From the README:
>
> https://github.com/EricForgy/StringInterpolation.jl
>
> *StringInterpolation.jl*
>
> String interpolation is an awesome feature of Julia, but string 
> interpolation for non-standard string literals 
> <http://docs.julialang.org/en/latest/manual/metaprogramming/#non-standard-string-literals>
>  
> is not automatic and requires significant boilerplate code to make it work.
>
> This package simply resurrects an old Base method 
> <https://github.com/JuliaLang/julia/blob/deab8eabd7089e2699a8f3a9598177b62cbb1733/base/string.jl#L613>
>  `interp_parse` 
> and adds a macro `@interpolate`. For example:
>
> julia> Pkg.clone("https://github.com/EricForgy/StringInterpolation.jl.git";
> )
> julia> using StringInterpolation
> julia> x = "World"
> julia> @interpolate "Hello \$x"
> "Hello World"
>
> Note the $ is escaped in the string we want to interpolate.
>
> The intended use for this package is when building non-standard string 
> literals. For example:
>
> macro test_str(s)
>     return quote
>         str = @interpolate $s
>         # Do what you want to do with interpolated string here.
>         sprint(print,str)
>     end
> end
>
> *Example*
>
> The following non-standard string literal simply makes 3 copies of the 
> interpolated string:
>
> macro triple_str(s)
>     return quote
>         str = @interpolate $s
>         sprint(print,str^3)
>     end
> end
>
> Then, you can use the macro as follows:
>
> julia> x = "World"; println(triple"Hello \$x\n")
> Hello World
> Hello World
> Hello World
>
>

Reply via email to