* regexp literals. Hey, look ma, no backslash escapes, and... compile-time checked for validity (which is less useful than you might think; almost any random collection of characters is a syntactically valid regexp. We're pretty much checking that all the parens and brackets are matched, that's pretty much it).
Regexps:
Pattern p = Lombok.pattern(/*^[CD]:\([^\]+\)(.*)$*/ Pattern.CASE_INSENSITIVE);name again debatable (either 'pattern' or 'regexp' seem like the obvious candidates). Again no deps at all.
* 'long' strings that can contain anything (well, except */), as per your example.
It would look like:
String longString = Lombok.S(/*This \ will be a long string
that can contain newlines and backslashes if you want*/);
With the 'S' name statically importable, and of course we can and should debate on a good name for it. It'll compile down to a plain jane string literal, there won't be a runtime dependency on either your source file or lombok.
Python's r"" is for raw strings, not regexps. Therefore, r is out because it is confusing and not descriptive. It's pattern, or regex, or regexp. Those are the only 3 choices.
--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Might try some sort of comment convention that softens the blow...
Javadocs use an extra *
/**
*
*/
Lombok could require an extra character or more
/*~...*/
/*~...~*/
/*"..."*/
/*{...}*/
/*[...]*/
/*%..%*/
I'd say this is primarily useful for raw strings only, especially because backslash escapes are used primarily to escape newlines, which aren't needed for long strings, and quotes, which again aren't needed, and tabs, which are never needed anyway, and that's pretty much it. backslash-u escapes will continue to work (as these apply everywhere, even in comments and outside of string literals).I like /*". We can NOT just replace all /*""*/ with strings, it HAS to be wrapped in a method call, but we can demand that its formatted that way (generate an error if it's not formatted that way). So, it would look like S(/*"string goes here"*/) – that's would be a 'long string literal' in lombok.For indents, I'm tempted to just say that all spacing is preserved, but I can see how that results in impractical formatting of source files. I'd say trailing spaces are always preserved (if you didn't want them, then don't put them in the source!),
but leading spacing is a different matter; often those are actually indents.How about this:IF the 'string literal comment' is the first non-whitespace character on its line, THEN we take the spacing that precedes it and consider that the prefix of all further lines. That is, if further lines start with the same characters, we strip those. We don't strip anything else.This still results in an annoying 3 character disjoint (the string literal starts with /*" but further lines won't). So, let's add another rule: _IF_, after stripping at least 1 character of whitespace due to the above rule, the remaining string starts with at least 3 spaces (and only spaces will do, not tabs), those are stripped.This has the following properties:
* If you want to long-string something where whitespace is really really important, you can do that.* You can indent your files with tabs. Or spaces. Or both. But if you want to keep the content exactly aligned, you MUST skip past the /*" of the opening line with spaces, not tabs. That might mean you indent with tabs, then write 3 spaces, then start the continuation of the long string.* If your long string literal does not start on its own line, indentation is wonky anyway, so in this case we simply don't treat any spacing as indents; It's ALL preserved. An alternative would be to look at the indent of the line itself, but often a continued line is itself indented more than its parent line, so how do we know how much more? That's why I propose we don't try to guess which leading whitespace is indent and which is significant unless the long string comment itself starts the line. So, your code would look like:System.out.println(S(/*" This is a really long line that is continuedhere. This line has 1 leading preserved space.but this line doesn't."*/"));
Look at the above snippet in a monospace font or it won't make sense.* You cannot put non-u backslash escapes in this thing. It is impossible to escape */ (you can't even escape this with a backslash-u escape!).* You cannot reverse-escape a newline. I can imagine that you'd want to start a new line for the sake of source code formatting, but you do NOT want that newline to be in the string literal that lombok constructs for you. However, while that's nice, this proposal does not allow you to do that. A newline in your /*""*/ comment will end up as a \n in your string literal. Also, we'll always make that \n, not \r\n, even if your source file is formatted with dos-style line endings.* We COULD allow escapable strings, possibly by using a different symbol or a prefix (/*\""*/ for example, or single quotes instead of double quotes). In these, you can escape as usual with \t, \n, etcetera, and you can also end a line in a backslash (backslash, then hit enter) to have newlines in your source that don't result in \n in your longstring.
* While we use the same mechanism to process longstrings and regexp literals, the rules are completely different. For example, I'd say in a regexp literal, ALL leading and trailing spaces are ALWAYS ignored. Possibly it's not even legal to multiline it in the first place.
Certainly the comment's boundary symbols will not be /*" and "*/ but something else. Possibly just /* */ for regexps, possibly /*/ and /*/.
--
The problem with ignoring all leading and trailing whitespace is that there are tons of things you can't write then. For example, if I write:
String commandLineHelp = S(/*"Yoyodyne tool v1.0-------------------------------------------foo - bargle bar bar barglebarbar - hmmmmmmm*/");What if the indents for the 'foo' and bar' lines are intentional? How would I tell lombok this? I don't really like forcing the use of leading stars as a faux indicator of whitespace, for two reasons:* This too is complicated; the actual leading indicator is * and a space. So now we need to make up rules for when those aren't there. The best rule is probably: That is an error; if you decide to use leading stars, it has to be done right.
* You now can NOT paste in any random string (and copy it into the clipboard from your source file), and have it preserved 100% in both directions, which is part of the charm of these things, I'd say.
The indent rules seem complicated but they aren't. Basically, the rule goes: If you want to indent your string literals, put the entire literal, including the start of it, on its own line, and indent as normal.
We have to freedom to make up an infinite amount of syntaxis for this; one for raw strings, one for escape-interpreted strings, one where indents are removed, one where they aren't, and so on and so forth. But we already have a huge delimiter of 5 characters prefix (capital-S, open paren, slash, star, quote) and 4 characters suffix (quote, star, slash, close paren), so if we would do that we're almost forced into using symbolics instead of english words, at which point it just becomes a punch of complex cartoon swearing.
We have to only make a few options. I don't like the stars because they make it look like javadoc content or an actual comment, and not a string literal.
* While we use the same mechanism to process longstrings and regexp literals, the rules are completely different. For example, I'd say in a regexp literal, ALL leading and trailing spaces are ALWAYS ignored. Possibly it's not even legal to multiline it in the first place.
This both makes sense.
--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
On 10/12/2013 03:52 AM, Martin Grajcar wrote:
But this is not what you did in your above example. Or am I missing something?
A simple rule could go like this: If a character should get a special meaning, put it before the leading quote, so /*\$" would give special meaning to backslash and dollar, thus switching on escaping and interpolation:
My reason for the stars was that eclipse inserts them after each newline, so I wanted to use them instead of fighting them. For copy-pasted strings the situation is different.