November 11, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #10 from bearophile_hugs@eml.cc 2010-11-10 18:21:06 PST --- The C# language, that has a very refined design, refuses this code, showing that it doesn't perform automatic joining of adjacent strings: public class Test { public static void Main() { string s = "hello " "world"; } } prog.cs(3,35): error CS1525: Unexpected symbol `world' Compilation failed: 1 error(s), 0 warnings -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 12, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #11 from bearophile_hugs@eml.cc 2010-11-12 04:24:57 PST --- Walter agrees: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=121830 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 12, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #12 from bearophile_hugs@eml.cc 2010-11-12 04:32:16 PST --- A comment from Andrei Alexandrescu: Walter, please don't forget to tweak the associativity rules: var ~ " literal " ~ " literal " concatenates literals first. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 14, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #13 from bearophile_hugs@eml.cc 2010-11-13 19:19:03 PST --- (In reply to comment #12) A comment from Stewart Gordon: > You mean make ~ right-associative? I think this'll break more code than it fixes. > > But implementing a compiler optimisation so that var ~ ctc ~ ctc is processed as var ~ (ctc ~ ctc), _in those cases where they're equivalent_, would be sensible. > > ctc = compile-time constant -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 14, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #14 from Ellery Newcomer <ellery-newcomer@utulsa.edu> 2010-11-13 19:26:18 PST --- you don't need to mess with associativity rules, you just need to be able to handle two or three ast cases: 1. (~ str str) ie str ~ str 2. (~ (~ x str) str) ie x ~ str ~ str 3. (~ str (~ str x)) ie str ~ (str ~ x) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 14, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |clugdbug@yahoo.com.au --- Comment #15 from Don <clugdbug@yahoo.com.au> 2010-11-13 23:51:58 PST --- (In reply to comment #14) > you don't need to mess with associativity rules, you just need to be able to handle two or three ast cases: > > 1. (~ str str) ie str ~ str > 2. (~ (~ x str) str) ie x ~ str ~ str > 3. (~ str (~ str x)) ie str ~ (str ~ x) Like this (optimize.c, line 1023): Expression *CatExp::optimize(int result) { Expression *e; //printf("CatExp::optimize(%d) %s\n", result, toChars()); e1 = e1->optimize(result); e2 = e2->optimize(result); + if (e1->op == TOKcat && (e2->op == TOKstring || e2->op == TOKnull) + && (((CatExp *)e1)->e2->op == TOKstring || ((CatExp *)e1)->e2->op == TOKnull)) + { + // Convert (e ~ str) ~ str into e ~ (str ~ str) + CatExp *ce = ((CatExp *)e1); + e1 = ce->e1; + ce->e1 = ce->e2; + ce->e2 = e2; + e2 = ce; + } e = Cat(type, e1, e2); if (e == EXP_CANT_INTERPRET) e = this; return e; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 14, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #16 from Don <clugdbug@yahoo.com.au> 2010-11-13 23:58:35 PST --- Sorry, missed out a line: if (e1->op == TOKcat && (e2->op == TOKstring || e2->op == TOKnull) && (((CatExp *)e1)->e2->op == TOKstring || ((CatExp *)e1)->e2->op == TOKnull)) { // Convert (e ~ str) ~ str into e ~ (str ~ str) CatExp *ce = ((CatExp *)e1); e1 = ce->e1; ce->e1 = ce->e2; ce->e2 = e2; e2 = ce; + e2 = e2->optimize(result); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 17, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 Stewart Gordon <smjg@iname.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |smjg@iname.com --- Comment #17 from Stewart Gordon <smjg@iname.com> 2010-11-16 17:09:41 PST --- (In reply to comment #5) > The error message for the missing ~ can be something like this (adapted from the "'l' suffix is deprecated, use 'L' instead" error message generated by the usage of a 10l long literal): > > adjacent string literals concatenation is deprecated, add ~ between them instead. Better watch out for cases where just adding ~ changes the behaviour. For example, if a is a string[], then a ~ "this" "that" and a ~ "this" ~ "that" evaluate to different strings. Not that there's any real use case for "this" "that" anyway. And those rare use cases it does have in D can be fixed by inserting the ~, though there may be easier-to-miss cases of the above of which to be wary. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 17, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #18 from Stewart Gordon <smjg@iname.com> 2010-11-16 17:15:03 PST --- (In reply to comment #17) > For example, if a is a string[], then a ~ "this" "that" and a ~ "this" ~ "that" evaluate to different strings. Different string arrays even. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 17, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 nfxjfg@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |nfxjfg@gmail.com --- Comment #19 from nfxjfg@gmail.com 2010-11-16 19:01:06 PST --- (In reply to comment #17) > Not that there's any real use case for "this" "that" anyway. And those rare use cases I use automatic joining all the time for long string literals. I want them to span multiple source lines without containing line breaks. No, not a rarely used feature. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation