Am 21.01.2015 um 14:52 schrieb Urs Liska:
Am 21.01.2015 um 14:45 schrieb Sven Axelsson:
On 21 January 2015 at 14:01, Urs Liska <[email protected]> wrote:>
Hm, it's not as easy as that because the escaping can be quite
different,
e.g.
"&" -> "\&"
"\" -> "\textbackslash"
"[" -> "{[}"
etc.
So what I really need is:
match (&)(\)([)
and replace that with
(\&)(\textbackslash )({})
And I would be glad if I wouldn't have to do that with individual
runs of
regexp-substitute.
Looks like you can use a callback function with regexp-substitute and
then do whatever
necessary there, eg. (from the Guile manual).
(regexp-substitute/global #f "[a-z]+" "to do and not-do"
'pre (lambda (m) (string-reverse (match:substring m))) 'post)
⇒ "ot od dna ton-od"
That looks promising, and I think I can combine that with Johan's
suggestion of an association list.
Thanks to both.
Urs
It works :-)
\version "2.19.16"
#(use-modules (ice-9 regex))
str = "This should be \partcombine[or]{Apart} & match everything"
#(define escape-pairs
'(("\\" . "\\textbackslash ")
("&" . "\\&")
("{" . "\\{")
("}" . "\\}")
("[" . "{[}")
("]" . "{]}")))
escape-regexp = "&|\\\\|\{|\}|\[|\]"
#(set! str
(regexp-substitute/global #f escape-regexp str
'pre (lambda (m)
(assoc-ref escape-pairs (match:substring m)))
'post))
#(ly:message "")
#(ly:message str)
#(ly:message "")
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user