Forums

Multiline strings

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Re: Multiline strings

Postby hopscc » Sun Oct 04, 2009 12:44 am

No idea
works fine for me on WinXp (as of last post)

Whats your platform ?

Did you chk the eoln thing in both your src files and the patch file ?
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Multiline strings

Postby torial » Mon Nov 29, 2010 8:26 am

Did any multi-line string mechanism ever get implemented?
torial
 
Posts: 229
Location: IA

Re: Multiline strings

Postby Charles » Mon Nov 29, 2010 10:49 am

Not yet.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Multiline strings

Postby torial » Mon Nov 29, 2010 12:10 pm

Do you have any leanings? (Personally) I would prefer the """ syntax that Python also uses, for consistency AND for ease of copying.
torial
 
Posts: 229
Location: IA

Re: Multiline strings

Postby Charles » Mon Nov 29, 2010 2:23 pm

Overall I prefer triple quotes as well (single or double) but dislike the loss of indentation when the strings are flush against the left side.

I'm still finishing up some site tweaking and server maintenance. Then I plan on some fixes and a release before I return to this topic.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Multiline strings

Postby hopscc » Tue Nov 30, 2010 1:28 am

So where are we with how we think this should look/behave?

Introduce """.."" for (multiiline) strings supporting all the existing 'r/ns/..' prefixes with the only difference being that the 3 quote delimiters allow multiple lines and preserve the embedded line terminators.

Have some default (clean,minimal.obvious) formatting that indents cleanly for source code appearance but does some initial wspace stripping for display?

Allow any/some other formatting ( or some switch) that specifies to display leading whitespace as is?

Support some form of embedded switch/command to allow/control alternative coding formats ?

Other?
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Multiline strings

Postby Charles » Tue Nov 30, 2010 7:14 pm

I haven't made final decisions regarding multiline strings except that we'll have them. Sorry, but this is not on my very short term radar right which looks something like:
-- finish web site and server work
-- fix some bugs
-- cut a release

This will have to wait.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Multiline strings

Postby hopscc » Wed Feb 02, 2011 12:37 am

FWIW same discussion less illumination for a different language
Java multi line strings.

FWIW I have an implementation using """ delimiters (slightly tweaked docstrings) for multiline raw strings,
(leading wspace trim and optional edge delimiters)
great for most common uses
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Multiline strings

Postby nerdzero » Tue Dec 11, 2012 12:00 pm

/nerdzero raises this thread from the dead

I have a question (maybe it's a dumb one): Why do multiline strings need a special token to identify them? Why can't all strings be multiline? What do you guys think of the following?

class Example

def main

sample1 = 'I can start the string on the same line as the variable.
Leading indents up to the indent level of the line that opened the string are ignored.
Any further indents are included in the string.'

print sample1

sample2 =
'Since in Cobra, line continuations can be indented more than the first line,
this would also be valid syntax. None of these lines would be displayed with
leading indents.'

print _
'Here is an example with a print statement and an explicit line continutation.
Variable substituion is supported like usual.
[sample2]'

crazy = "
Of course this means, you can create some goofy stuffy unintentionally.\n
\t[sample1]\n\nBut maybe just don't do that?
"

print crazy


/#
outputs:
I can start the string on the same line as the variable.
Leading indents up to the indent level of the line that opened the string are ignored.
Any further indents are included in the string.
Here is an example with a print statement and an explicit line continutation.
Variable substituion is supported like usual.
Since in Cobra, line continuations can be indented more than the first line,
this would also be valid syntax. None of these lines would be displayed with
leading indents.

Of course this means, you can create some goofy stuffy unintentionally.

I can start the string on the same line as the variable.
Leading indents up to the indent level of the line that opened the string are ignored.
Any further indents are included in the string.

But maybe just don't do that?

/#


This would be a syntax error because the follwing lines must be indented at least to the level of the line that opened the string.

def foo
bar = 'line1
line2'


Except for blank lines, those don't need to be indented.

def foo
bar = 'line1

line3'


And a more practical example...

class Parser
def parse(fileName as String, source as String) as CobraModule
test
p = Parser()

source =
"class Hello
def main
print 'Hello, World!'"

module = p.parse('HelloTest.cobra', source)
...
body
...
nerdzero
 
Posts: 286
Location: Chicago, IL

Re: Multiline strings

Postby Charles » Tue Dec 11, 2012 2:54 pm

The idea was taken from Python which starts multiline strings with triple single quotes or triple double quotes.

One nice thing about a special token is that it immediately signals what's going on. The other nice thing about triple quotes is that you don't have to escape single instances of quotes inside the string such as when writing the word don't or quoting something.

I haven't forgotten about multiline strings, but as you can see from the release notes, fixes have had a higher priority. Currently, there is a bug with partial classes and debugging symbols. Also, there is the critical gap that Cobra doesn't pick up C# extension methods (which prevents effective usage of various libraries). That also ties into Cobra's method binding especially regarding overloads and will not be trivial to fix.

Back to multiline strings. There was a lot of discussion here. I have to reread it and make some decisions. But I won't be doing so until at least the above items are finished.
Charles
 
Posts: 2515
Location: Los Angeles, CA

PreviousNext

Return to Discussion

Who is online

Users browsing this forum: No registered users and 18 guests