If your issue is purely related to echo() output, there may be other options
than globally changing string behaviour.
Could you post the .scad code (not the lib) that you had to enter to create
that picture.
Newly minted Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Feature-request-recognize-the-line-break-in-multi-line-string-tp13789p13891.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
MichaelAtOz wrote
If your issue is purely related to echo() output, there may be other
options than globally changing string behaviour.
It's all about echo() output, to my knowledge it's the only way users can
check if openscad recognizes \n.
MichaelAtOz wrote
Could you post the .scad code (not the lib) that you had to enter to
create that picture.
You are looking at the source code.
$ Runsun Pan, PhD
$ -- libs: doctest , faces ( git ), offliner ( git );
tips: hash( 1 , 2 ), sweep , var
$ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly
--
View this message in context: http://forum.openscad.org/Feature-request-recognize-the-line-break-in-multi-line-string-tp13789p13894.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
runsun wrote
You are looking at the source code.
I thought it would be a call to a library module with other parameters etc.
Anyway...
What you are after is a heredoc
https://en.wikipedia.org/wiki/Here_document , as used in many languages
http://rosettacode.org/wiki/Here_document
n possibilities which don't break existing strings;
a. Introduce a new string type using single quote ('), ie
var='this
string
includes
line
breaks';
Need to decide if it is fixed as LF only, or platform dependent LF or CRLF,
I'd propose the former.
b. Introduce a string prefix flag, possibly a kludge, but could be useful
for other things, particularly comment;
var=<some prefix characters>"this
could
be
multi-line // possibly with comments depending on the prefix
depending
on
the
prefix";
Possible prefix types; (off the top of my head)
R - raw (uses LF) possibly ignores escapes (\n etc),
C - treat // as comments
I - discard indented whitespace (with C also looses whitespace in front of
//)
etc.
Not sure how simple that would be in terms of parsers.
c. Use the popular triple quote multi-line syntax;
var="""
anything
here
""";
need to consider " escapes, prob. best as per normal strings?
also whether leading whitespace is allowed on the closing triple quote (for
code indentation)
d. The popular <<delimiter;
var=<<EOF
This is
one way
EOF;
Need to consider the semi-colon position here?? Also leading white space on
EOF
e. Or any other specific from the Rosetta link above, like the C++ one
maybe.
String processing in OpenSCAD is now a growing aspect.
If we are to introduce such a change, you could also include variable
substitution in strings.
expletive="bloody";
var=R"EOF(
This would be $expletive useful
Allowing $someVar to get replaced with $someOther
)EOF";
Newly minted Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Feature-request-recognize-the-line-break-in-multi-line-string-tp13789p13934.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
MichaelAtOz wrote
String processing in OpenSCAD is now a growing aspect.
If we are to introduce such a change, you could also include variable
substitution in strings.
expletive="bloody";
var=R"EOF(
This would be $expletive useful
Allowing $someVar to get replaced with $someOther
)EOF";
Good idea. I've been using similar feature in my code for over a year. It'd
be nice if it is builtin, which would speed up significantly.
Here are some examples of mine. I use {_} to indicate a blank to fill, and
it's also easy to type:
s ( s,arr,sp="{}" )=str ( tested:6 ) (mode:12)
| 0> s("2014.{}.{}", [3,6])= "2014.3.6"
| 1> s("", [3,6])= ""
| 2> s("2014.{}.{}", [])= "2014.{}.{}"
| 3> s("2014.{}.{}", [3])= "2014.3.{_}"
| 4> s("2014.3.6", [4,5])= "2014.3.6"
| 5> s("{} car {} seats?", ["red","blue"])= "red car blue seats?"
"
Here is the key-word substitution:
_h ( s,h, showkey=false, wrap="{,}" )=string ( tested:4 ) (mode:12)
| data= ["m", 3, "d", 6]
| 0> _h(2014.{m}.{d}, ["m", 3, "d", 6])= "2014.3.6"
| // showkey=true :
| 1> _h("2014.[m].[d]", data, showkey=true, wrap="[,]")= "2014.m=3.d=6"
| // hash has less key:val
| 2> _h(tmpl, ["m",3])= "2014.3.{d}"
| // hash has more key:val
| 3> _h(tmpl, ["a",1,"m",3,"d",6])= "2014.3.6"
I'd also strongly suggest another addition to the string syntax: allow '
(single quote) in addition to the current " (double quote). In my
application "a string inside string" is used frequently. It's another
nightmare (other than the unrecognized \n) to have to type " each time.
It's not only time wasting but also hard to read. I end up with another
approach, using ` instead of ", to quote an internal string. Then when read
out, I use a parser (written in Openscad) to scan and replace it to ". Yes,
it's crazy. But that's the only way I know.
MichaelAtOz wrote
a. Introduce a new string type using single quote ('), ie
var='this
string
includes
line
breaks';
Don't like it. Iike I said above, single quote(') is best to be used for
internal string.
MichaelAtOz wrote
b. Introduce a string prefix flag, possibly a kludge, but could be useful
for other things, particularly comment;
var=
<some prefix characters>
"this
could
be
multi-line // possibly with comments depending on the prefix
depending
on
the
prefix";
Possible prefix types; (off the top of my head)
R - raw (uses LF) possibly ignores escapes (\n etc),
C - treat // as comments
I - discard indented whitespace (with C also looses whitespace in front
of //)
etc.
Better than my current approach.
MichaelAtOz wrote
c. Use the popular triple quote multi-line syntax;
var="""
anything
here
""";
That'd be a welcome change.
MichaelAtOz wrote
d. The popular <<delimiter;
var=<<EOF
This is
one way
EOF;
No problem with me.
In summary, I'd support:
$ Runsun Pan, PhD
$ -- libs: doctest , faces ( git ), offliner ( git );
tips: hash( 1 , 2 ), sweep , var , lerp
$ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly
--
View this message in context: http://forum.openscad.org/Feature-request-recognize-the-line-break-in-multi-line-string-tp13789p13951.html
Sent from the OpenSCAD mailing list archive at Nabble.com.