A reader extension for ‘raw strings’
lloda fd299e3469 Fix license in test.scm | 10 miesięcy temu | |
---|---|---|
.github | 1 rok temu | |
mod | 2 lat temu | |
LICENSE | 1 rok temu | |
README.md | 1 rok temu | |
srfi.md | 1 rok temu | |
test.scm | 10 miesięcy temu |
guile-raw-strings
is a reader extension for GNU Guile that lets you write verbatim strings such as
#R-(quotes " and escapes \ and newlines
can " freely be used " here)-
where you'd normally need escapes:
"quotes \" and escapes \\ and newlines\n can \" freely be used \" here"
This comes in handy for docstrings, regexps, etc.
The string between the #R
and the (
is the 'delimiter'. The string ends with a )
followed by the delimiter. In the example above, the delimiter is -
. The delimiter can be empty, as in #R(put your '\"\\)
for "put your '\\\"\\\\"
.
You can also use []
or ""
instead of ()
to ‘delimit the delimiter’1. This means that you cannot use the characters [("
as part of the delimiter. Whitespace in the delimiter is forbidden.
#R(hello)
⇒ hello
#R"hello"
⇒ hello
#R[hello]
⇒ hello
#Rdo-not-repeat(hello)do-not-repeat
⇒ hello
The open-close pair must be matched, but the delimiter must be repeated verbatim.
#R("hello")
⇒ "hello"
—empty delimiter, open-close-pair is ()
.#R"(hello)"
⇒ (hello)
—since ""
is an open-close pair, this also has an empty delimiter.#R]"hello"]
⇒ hello
—here the delimiter is ]
and the open-close pair is ""
.#R["hello"]
⇒ "hello"
—here the delimiter is empty and the open-close pair is []
.The extension should run on Guile 2.2 or later. To enable it, install mod/raw-strings.scm
in your module path and then (import (raw-strings))
.
Run the test with
$GUILE -L mod -s test.scm
I hope you find this useful.
—
¹ You can configure the open-close pairs, as well as the extension character R
, with the variables openc
, closec
and extension-char
at the top of the source. A single open-close pair seems preferable, if everyone agrees on what that should be. ↩