SugarCpp
SugarCpp copied to clipboard
Ruby style string formater via stringstream.
In ruby we can format string in this way:
k = 123
str = "x=#{k+1}"
So in SugarCpp, we can just write this
import "iostream"
int main()
k := 123
str := "x=#{k+1}"
Which compiles into this
#include <iostream>
#include <sstream>
int main()
{
auto k = 123;
auto str = ({
std::stringstream _t_sstream;
_t_sstream << "x=" << k + 1;
_t_sstream.str();
});
}
Amazing feature.!
Amazing! plz pay attention to the left part for that sometimes it's easy to use these if you brought out this feature.
cout << "x=#{k + 1}"
It shall be compiled to
cout << ({
std::stringstream _t_sstream;
_t_sstream << "x=" << k + 1;
_t_sstream.str();
});
Seems it's easy for only dealing with "#{}", plz make sure there are some way to get exactly #{.*}.
Please check it when finished, THX.
这一坨feature等我完成编译器自举以后再继续写……
I've used this all the time in LS, but there's this one thing that's always nagged me about it: The assymetry of the notation - I find it often is a bit cluttered and unclear. A notation I do find to be very clear in this regard is:
interpolation := "elephant"
text := "room"
"Here we have an {{interpolation}} in the {{text}}"
Ofcourse it doesn't follow the Ruby or LiveScript syntax, but still, it is much clearer imho.
Seems good, I'll check this.
Yeah, the where clauses from Haskell is neat, would also be for making
localized functions etc. Generally.
In the case of the interpolations, I mean ofcourse it should interpolate
variables in the scope as usual, just with the change (or addition) of the
double braces notation..
2014-12-10 4:42 GMT+01:00 curimit [email protected]:
How about this?
text := "Here we have an {{interpolation}} in the {{text}}" where interpolation := "elephant" text := "room"
— Reply to this email directly or view it on GitHub https://github.com/curimit/SugarCpp/issues/25#issuecomment-66400441.