[e-lang] Indentation and line breaks in string literals
Kevin Reid
kpreid at mac.com
Mon Mar 3 08:29:56 EST 2008
? e`{"abc\ndef"}`
# value: e`{
# "abc
# def"
# }`
? e`{
> "abc
> def"
> }`
# value: e`{
# "abc
# def"
# }`
As the above demonstrates, the E parser and printer fail to be
consistent when given a string literal containing a line break.
For this reason, and for use of multi-line quasiliterals in ordinary
source, it seems to me that there ought to be a notation for ignoring
indentation whitespace in string and quasi-literals.
What should this be?
Some prior art I know of:
In Common Lisp format strings, a ~ followed by a newline ignores that
newline and any following whitespace, with options to not ignore
either one:
http://www.lispworks.com/documentation/HyperSpec/Body/22_cic.htm
(format nil "foo~
bar")
=> foobar
(format nil "foo~@
bar")
=> foo
=> bar
In Haskell, whitespace surrounded by \ is ignored. This allows for
leading whitespace to be specified in continuation lines.
http://www.haskell.org/onlinereport/lexemes.html#sect2.6
"{\n\
\ foo\n\
\ bar\n\
\}"
=> {
=> foo
=> bar
=> }
Then there are the languages (C?) which allow adjacent string
literals and consider them concatenated:
"foo\n"
" bar"
=> foo
=> bar
(This has the advantage of not introducing additional escape-ish
syntax, but using it in E would require extra backslashes to prohibit
statement termination, and the quasiliteral form of the preceding
example would look funny:
quasiname`foo$\n` \
` bar`
)
Your opinions?
--
Kevin Reid <http://homepage.mac.com/kpreid/>
More information about the e-lang
mailing list