1. Just a little question before 4.0 will be released

Greetings.

Sorry, if I am missing something vital in documentation, but is there a way for difining stings in Euphoria in 'heredoc' style? It's very boring to escape all quotes in HTML/XML, Java scipts and so on. So instead of writing complicated escaped strings it is abslotely must:

k=here comes the text as it will be present, no need to escape " and ' and other stuff Is there a heredoc syntax of strings present? If no, please consider it may be in future releases.

new topic     » topic index » view message » categorize

2. Re: Just a little question before 4.0 will be released

nurminski said...
 
k=!!! 
here comes 
the text    as 
it will be present, no need to escape " and ' and other stuff 
!!! 
 
new topic     » goto parent     » topic index » view message » categorize

3. Re: Just a little question before 4.0 will be released

nurminski said...

Greetings.

Sorry, if I am missing something vital in documentation, but is there a way for difining stings in Euphoria in 'heredoc' style?

Ok, I can do this. I suggest this syntax ...

k=#/ 
here comes 
the text    as 
it will be present, no need to escape " and ' and other stuff 
/ 

The idea is that if a '#' is found that is immediately followed by any one of #'`~$^/\|, it indicates the begining of a string literal that terminates with the next occurance of whatever character followed the initial '#'. The one exception here is that if the resulting text begins with a new-line character, the text is trimmed of the leading new-line and any trailing new-line character.

-- Example Code -- 
constant s = #/"one" "two"/ 
constant t = #` 
 
"three"  
"four" 
 
` 

 
constant u = #$ 
"three"  
"four" 
$ 
 
printf(1, "[%s]\n", {s}) 
printf(1, "[%s]\n", {t}) 
printf(1, "[%s]\n", {u}) 
------------------ 

This would output ...

["one" "two"] 
[ 
"three" 
"four" 
] 
["three" 
"four"] 

new topic     » goto parent     » topic index » view message » categorize

4. Re: Just a little question before 4.0 will be released

Yes, thank you, it will be of great use when programing CGI-output, for example - no need for escaping /n " ' in complicated fragments of HTML code will result in cleaner and typo-prone code.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Just a little question before 4.0 will be released

I forget one language, but one thing I enjoyed about it was it's multiline string had the option to strip the indent prefix. For instance:

sequence output 
if idx = 1 then 
    idx = idx + 25 
    output = #/Hello Mr. John Doe, 
 
This email is being generated to you for some purpose of 
which I have no clue. 
 
Thank you for your support, 
 
Mr. Jeff Doe 
/ 
else 
    idx = idx + 30 
    output = #/Hello Mr. John Doe, 
 
This email is being generated to you for some purpose of 
which I have no clue. 
 
I am very sad that you have choose not to support us, 
 
Mr. Jeff Doe 
/ 
end if 

The above is very difficult to read. Sure, you can create constants outside of the if or do other tricks to make it look a little better, but that also is very hard to read, here's an example of that:

sequence msg1 = #/ 
Dear Mr. John Doe, 
 
This message ...... 
 
Thank you.... 
 
Mr. Jeff Doe/ 
sequence msg2 = #/ 
Dear Mr. John Doe, 
 
This message .... 
 
Sorry.... 
 
Mr. Jeff Doe/ 

Now, what the language did that I am speaking of (wish I could remember which one it was):

if idx = 2 then 
    idx = idx + 25 
    output = #/ 
        #Dear Mr. John Doe, 
        # 
        #I am very happy for your support 
        # 
        #Mr. Jeff Doe 
        #/ 
else 
    .... more .... 
end if 

So, if the string starts with the magic hash, then all white space preceeding it is stripped. Maybe it could be the magic character that you choose:

sequence out = #/ 
    /Hello 
    /World 
    /Next line ends it. 
    // 

On the last line in that example, the first / sets the place that will be stripped, the last ends the string definition. Therefore there is no confusion as to if the / ends the string or is just a begining of string definition character.

Just thinking aloud. This syntax of course would not be required to be used, you could do as the first example on this post and just put your entire string on the first column, but for many, the above syntax will make the difference between something readable/maintainable and something that just causes mass confusion.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

6. Re: Just a little question before 4.0 will be released

jeremy said...
if idx = 2 then 
    idx = idx + 25 
    output = #/ 
        #Dear Mr. John Doe, 
        # 
        #I am very happy for your support 
        # 
        #Mr. Jeff Doe 
        #/ 
else 
    .... more .... 
end if 

So, if the string starts with the magic hash, then all white space preceeding it is stripped. Maybe it could be the magic character that you choose:

Jeremy

Suppose we combine these ideas: Use the /@ (or whatever) once and its location determines how far whitespace will be striped to:

sequence c_code = /@if ( strcmp( "foo", "bar" ) == 1 ) { 
                       printf("strcmp works correctly."); 
                  } 
@/ 
-- c_code is "if ( strcmp( \"foo\", \"bar\" ) == 1 ) {\n\tprintf(\"strcmp works correctly.\");\n}\n" 

I don't think it is nice to require a line continuation symbol for this kind of quoting. However, it is good to allow the programmer to put whitespace for readability.

Shawn

new topic     » goto parent     » topic index » view message » categorize

7. Re: Just a little question before 4.0 will be released

And the last thing, that can be usefull. Depending of the symbol after # the CR_LF is treated as in Unix or like in Windows.

  1. / for example command interpreter to generate UNIX-formated LF
  2. $ commands to render Windows/DOS CR-LF

All other symbols except / and $ will be treated as instruction to render the string in the style default to the operating system on which interpreter is runing.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Just a little question before 4.0 will be released

jeremy said...
if idx = 2 then 
    idx = idx + 25 
    output = #/ 
        #Dear Mr. John Doe, 
        # 
        #I am very happy for your support 
        # 
        #Mr. Jeff Doe 
        #/ 
else 
    .... more .... 
end if 

So, if the string starts with the magic hash, then all white space preceeding it is stripped. Maybe it could be the magic character that you choose:

SDPringle said...

Suppose we combine these ideas:

Use the /@ (or whatever) once and its location determines how far whitespace will be striped to:

sequence c_code = /@if ( strcmp( "foo", "bar" ) == 1 ) { 
                       printf("strcmp works correctly."); 
                  } 
@/ 

I've given these ideas some thought and come up with this ...

if idx = 2 then 
    idx = idx + 25 
    output = #/ 
________ 
        Dear Mr. John Doe,  
         
            I am very happy for your support  
            with respect to the offer of 
            help. 
         
        Mr. Jeff Doe  
        / 
else 
    .... more .... 
end if 

Which will display as

Dear Mr. John Doe,  
 
    I am very happy for your support  
    with respect to the offer of 
    help. 
 
Mr. Jeff Doe  

and

sequence c_code = ## 
__________________if ( strcmp( "foo", "bar" ) == 1 ) { 
                       printf("strcmp works correctly."); 
                  } 
# 

Which displays as

if ( strcmp( "foo", "bar" ) == 1 ) { 
     printf("strcmp works correctly."); 
} 

The difference is one added line after the start of the extended string start token. This is a line of underscore characters that represents the maximum number of leading whitespace that will be trimmed off each line of string text in this extended text literal.

This is fast to implement, allows easy of entering and maintenance of the text, and visually highlights the "special" nature of the text literal.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Just a little question before 4.0 will be released

I wonder if it wouldn't be better to not allow so many delimiters but just double the delimiter. For instance:

sequence s = #// 
    abc, def 
      abc, def 
// 
 
-- "    abc, def\n      abc, def" 

Further, provide a "stripping" delimiter,

sequence s = #@@ 
    abc, def 
      abc, def 
@@ 
 
-- "abc, def\n  abc, def" 

When the stripping delimiter is used, all the white space of the first string is stripped from subsequent lines.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

10. Re: Just a little question before 4.0 will be released

jeremy said...

I wonder if it wouldn't be better to not allow so many delimiters but just double the delimiter.

I was first going to do just that but it became apparent that a choice of delimiter was needed because of the probability that the text being encode could contain it. Also, parsing it is just slightly slower.

For instance, this would fail...

sequence s = #// 
    The URL is http://www.rapideuphoria.com  
// 
jeremy said...

Further, provide a "stripping" delimiter,

sequence s = #@@ 
    abc, def 
      abc, def 
@@ 
 
-- "abc, def\n  abc, def" 

When the stripping delimiter is used, all the white space of the first string is stripped from subsequent lines.

I also toyed with this one too, but it fails when the first line is meant to to be indented.

sequence s = #@ 
__  abc, def 
  abc, def 
@ 

should display as

  abc, def 
abc, def 

new topic     » goto parent     » topic index » view message » categorize

11. Re: Just a little question before 4.0 will be released

In ScriptBasic, the """ quotes allow multi-line strings and comments.

PRINT """ This is a multi-line string."""

'""" This is a multi-line comment"""

This is a real time saver for the HTML part of CGI applications.

John

new topic     » goto parent     » topic index » view message » categorize

12. Re: Just a little question before 4.0 will be released

In the last post, each word WAS on a separate line. sad

new topic     » goto parent     » topic index » view message » categorize

13. Re: Just a little question before 4.0 will be released

ScriptBasic said...

In ScriptBasic, the """ quotes allow multi-line strings and comments.

PRINT """ This 
is 
a  
multi-line 
string.""" 
 
'""" This 
is 
a 
multi-line 
comment""" 

This is a real time saver for the HTML part of CGI applications.

Multi-line text literals have now been implemented. Multi-line comments are coming soon.

new topic     » goto parent     » topic index » view message » categorize

14. Re: Just a little question before 4.0 will be released

DerekParnell said...

Multi-line text literals have now been implemented. Multi-line comments are coming soon.

Did you change the way it works or keep your syntax? You came up with some good points on my suggestions. Just wondering if you moved to the """....""" syntax.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

15. Re: Heredoc strings

DerekParnell said...

I've given these ideas some thought and come up with this ...

if idx = 2 then 
    idx = idx + 25 
    output = #/ 
________ 
        Dear Mr. John Doe,  
         
            I am very happy for your support  
            with respect to the offer of 
            help. 
         
        Mr. Jeff Doe  
        / 
else 
    .... more .... 
end if 

Which will display as

Dear Mr. John Doe,  
 
    I am very happy for your support  
    with respect to the offer of 
    help. 
 
Mr. Jeff Doe  

I presume that the trimmed whitespace needs to be spaces. How would it deal with a tab thrown in?

Matt

new topic     » goto parent     » topic index » view message » categorize

16. Re: Just a little question before 4.0 will be released

jeremy said...
DerekParnell said...

Multi-line text literals have now been implemented. Multi-line comments are coming soon.

Did you change the way it works or keep your syntax? You came up with some good points on my suggestions. Just wondering if you moved to the """....""" syntax.

I'm using the underscore as the way to show the size of the left margin for these extended text literals.
eg.

---- 
constant ColorNames = ## 
______________________White 
                      Black 
                      Blue 
                      Green 
                      Red 
                      # 
---- 

Which is the same as ...

---- 
constant ColorNames = "White\nBlack\nBlue\nGreen\nRed" 
---- 
new topic     » goto parent     » topic index » view message » categorize

17. Re: Heredoc strings

mattlewis said...

I presume that the trimmed whitespace needs to be spaces. How would it deal with a tab thrown in?

Both the SPACE and TAB character are classed as a single whitespace character. Thus leading TABs are not expanded to equivalent SPACEs before trimming. It is not advisable to use TABS as leading whitespace in extended string literals.

new topic     » goto parent     » topic index » view message » categorize

18. Re: Heredoc strings

DerekParnell said...
mattlewis said...

I presume that the trimmed whitespace needs to be spaces. How would it deal with a tab thrown in?

Both the SPACE and TAB character are classed as a single whitespace character. Thus leading TABs are not expanded to equivalent SPACEs before trimming. It is not advisable to use TABS as leading whitespace in extended string literals.

I think we need to really think this one through. Although this ability is great, I am not sure it's the best way of going about it. Tabs and Spaces should both be alowed and the syntax is a bit cumbersome/weird, however I understand it's purpose.

Are their any other implementation ideas on this subject?

Jeremy

new topic     » goto parent     » topic index » view message » categorize

19. Re: Heredoc strings

jeremy said...

I think we need to really think this one through. Although this ability is great, I am not sure it's the best way of going about it.

Neither am I, but its the best I've come up with so far.

jeremy said...

Tabs and Spaces should both be allowed

TABs are allowed. However, you may not get the effect you were after. Unless one encodes the tabstops into the source code, the parser is never going to know how many spaces your TABs are set to.

jeremy said...

and the syntax is a bit cumbersome/weird, however I understand it's purpose.

I'm not sure about the cumbersome part as it seemed easy to do when I played with it, but the weird part might be a good thing as it certainly alerts the reader that something special is happening here.

jeremy said...

Are their any other implementation ideas on this subject?

I hope so.

new topic     » goto parent     » topic index » view message » categorize

20. Re: Heredoc strings

jeremy said...

I think we need to really think this one through. Although this ability is great, I am not sure it's the best way of going about it. Tabs and Spaces should both be alowed and the syntax is a bit cumbersome/weird, however I understand it's purpose.

Are their any other implementation ideas on this subject?

Looking around the InterWebs, it seems that indentation of heredocs is pretty rare. I found this perl example, and another ruby-emacs patch that seem to both basically ignore the whitespace of the start line.

perl said...

use Filter::Indent::HereDoc; 
{ 
  { 
    print <<EOT; 
    Hello, World! 
    EOT 
  } 
} 
# This will print "Hello, World!" and stop at EOT 
# even though the termination string is indented. 

ruby-emacs said...

Without the patch, here-doc terminators are considered to end at the 
first non-word character.  For example, `ruby-parse-partial' would think 
that the here-doc continues until line 5 of the following: 
     
  1  begin 
  2    puts <<-end_here_doc 
  3      "Hear this, Doc?" 
  4    end_here_doc 
  5  end 

I think these are pretty reasonable compromises, especially considering the standard text editor behavior of duplicating the whitespace after hitting return.

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu