> Thanks for the macro. =)
> The str function is really a good replacement for interpolation.
Yes, thank you for the macro. I anticipate using this approach (I'm
accustomed to it from Ruby, Perl and JScheme), but wanted to support a
way of stopping the parser (by backslashing the opening brace:
"$\\{x}" ). I think adding the zero-width assertion in the re-matcher
and the replaceAll to knock the backslash out gets me there:
(defn tokenize [s]
(let [positions (let [mm (re-matcher #"\\$(?!\\\\)\\{.*?\\}" s)]
(loop [acc []]
(if (.find mm)
(recur (conj acc [(.start mm) (.end mm)]))
acc)))
intermed (conj (apply vector 0 (apply concat positions))
(.length s))
textposns (partition 2 intermed)]
(my-interleave (map (fn [[a b]] [:text (. (.substring s a b)
(replaceAll "\\$\\\\\\{" "\\${"))])
textposns)
(map (fn [[a b]] [:pat (.substring s (+ a 2) (- b 1))])
positions))))
Regards,
Kyle Burton
> On Oct 28, 8:29 pm, "Graham Fawcett" <[EMAIL PROTECTED]> wrote:
>> On Tue, Oct 28, 2008 at 7:27 PM, Graham Fawcett
>>
>> <[EMAIL PROTECTED]> wrote:
>> > But for fun, here's an (i ...) macro, that will give you ${}
>> > interpolation in strings (if it works at all, I test it very
>> > thorougly!).
>>
>> Haha, nor did I spell- or grammar-check very thoroughly!
>>
>> I meant: I didn't test the code very thoroughly, so I hope it works at all.
>>
>> Graham
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---