1. Just a little question before 4.0 will be released
- Posted by nurminski Feb 18, 2009
- 1111 views
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.
2. Re: Just a little question before 4.0 will be released
- Posted by nurminski Feb 18, 2009
- 1061 views
k=!!! here comes the text as it will be present, no need to escape " and ' and other stuff !!!
3. Re: Just a little question before 4.0 will be released
- Posted by DerekParnell (admin) Feb 18, 2009
- 1082 views
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"]
4. Re: Just a little question before 4.0 will be released
- Posted by nurminski Feb 19, 2009
- 1068 views
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.
5. Re: Just a little question before 4.0 will be released
- Posted by jeremy (admin) Feb 19, 2009
- 1032 views
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
6. Re: Just a little question before 4.0 will be released
- Posted by SDPringle Feb 20, 2009
- 1000 views
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
7. Re: Just a little question before 4.0 will be released
- Posted by nurminski Feb 20, 2009
- 1033 views
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.
- / for example command interpreter to generate UNIX-formated LF
- $ 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.
8. Re: Just a little question before 4.0 will be released
- Posted by DerekParnell (admin) Feb 21, 2009
- 986 views
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:
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.
9. Re: Just a little question before 4.0 will be released
- Posted by jeremy (admin) Feb 21, 2009
- 998 views
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
10. Re: Just a little question before 4.0 will be released
- Posted by DerekParnell (admin) Feb 21, 2009
- 987 views
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 //
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
11. Re: Just a little question before 4.0 will be released
- Posted by ScriptBasic Feb 22, 2009
- 953 views
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
12. Re: Just a little question before 4.0 will be released
- Posted by ScriptBasic Feb 22, 2009
- 975 views
In the last post, each word WAS on a separate line.
13. Re: Just a little question before 4.0 will be released
- Posted by DerekParnell (admin) Feb 22, 2009
- 969 views
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.
14. Re: Just a little question before 4.0 will be released
- Posted by jeremy (admin) Feb 22, 2009
- 956 views
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
15. Re: Heredoc strings
- Posted by mattlewis (admin) Feb 22, 2009
- 954 views
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
16. Re: Just a little question before 4.0 will be released
- Posted by DerekParnell (admin) Feb 23, 2009
- 914 views
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" ----
17. Re: Heredoc strings
- Posted by DerekParnell (admin) Feb 23, 2009
- 932 views
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.
18. Re: Heredoc strings
- Posted by jeremy (admin) Feb 23, 2009
- 908 views
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
19. Re: Heredoc strings
- Posted by DerekParnell (admin) Feb 23, 2009
- 920 views
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.
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.
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.
Are their any other implementation ideas on this subject?
I hope so.
20. Re: Heredoc strings
- Posted by mattlewis (admin) Feb 23, 2009
- 947 views
- Last edited Feb 24, 2009
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.
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.
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