From: Thomas 'PointedEars' Lahn on
Michael Wojcik wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Still it remains to be seen if there are enough programming languages
>> that do not require special syntax to justify your "many". For example,
>> it does not apply to the following languages I know rather well: BASIC
>> (and variants), Pascal (variants, and derivates), C (variants, and
>> derivates), Tcl (and derivates), Java, and Python. (And maybe I forgot
>> some.)
>
> Add COBOL and FORTRAN, so if the metric were source lines of code, we
> could say that most existing software is written in a language that
> does not allow string literals to be split across lines.

ACK, thanks.

> Personally, I prefer C's compromise: string literals can't contain
> line terminators, but adjacent string literals are concatenated during
> translation, so it's still convenient to create long literals. I
> generally prefer this even to here-doc syntax in Bourne shell and
> derivatives, as the latter tends to break the source formatting, even
> with the tab-removal option.

Perhaps that is why Python supports both approaches:

# equivalent to "b\na\nr"
foo = """b
a
r"""

# equivalent to "bar"
foo = "b" \
"a" \
"r" \

JavaScript™ becoming more pythonic as each year passes, I would really like
JavaScript™ or ECMAScript to start supporting any or all of that. Breaking
up longer RegExp literals into concatenated strings passed to RegExp() is a
PITA, too; I had expected ES5 to allow

/f\\o\\o\
\sb\na\/r/

in order to avoid

new RegExp("f\\\\o\\\\o"
+ "\\sb\\na/r");

but it didn't. (There is a way to make this easier, but it does not always
work.)


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
From: "Michael Haufe ("TNO")" on
On Feb 4, 7:08 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:

[snipped multiline string examples]

> JavaScript™ becoming more pythonic as each year passes, I would really like
> JavaScript™ or ECMAScript to start supporting any or all of that.

There was some discussion a short while ago on es-discuss about this
topic, so it's not far fetched to expect something like it to crop up
in the near future.
(sorry, can't find the relevant thread(s) atm)

> Breaking up longer RegExp literals into concatenated strings passed to RegExp() is a
> PITA, too; I had expected ES5 to allow
>
>   /f\\o\\o\
> \sb\na\/r/
>
> in order to avoid
>
>   new RegExp("f\\\\o\\\\o"
>     + "\\sb\\na/r");
>
> but it didn't.  (There is a way to make this easier, but it does not always
> work.)

It looks like Mozilla plans to introduce the /x flag in JS1.9 which
would allow something like this.

https://bugzilla.mozilla.org/show_bug.cgi?id=384232
http://wiki.ecmascript.org/doku.php?id=proposals:extend_regexps&s=flag#x_flag
From: Stefan Weiss on
On 05/02/10 02:08, Thomas 'PointedEars' Lahn wrote:
> JavaScript™ becoming more pythonic as each year passes, I would really like
> JavaScript™ or ECMAScript to start supporting any or all of that. Breaking
> up longer RegExp literals into concatenated strings passed to RegExp() is a
> PITA, too; I had expected ES5 to allow
>
> /f\\o\\o\
> \sb\na\/r/
>
> in order to avoid
>
> new RegExp("f\\\\o\\\\o"
> + "\\sb\\na/r");
>
> but it didn't. (There is a way to make this easier, but it does not always
> work.)

Perl has a very convenient way to do this: the /x ("extend") modifier on
regex literals. With /x in place, any whitespace in the expression will
be ignored, and line comments can be used. This makes it possible to
write even complex regexes in a highly readable and well documented way:

$foo =~ /
^ # anchored at start of string
0x # prefix for hex value
([a-f0-9]+) # 1st group: hexadecimal digits
\s* # followed by optional whitespace
(?: # non-capturing group
foo # any of foo, bar, or baz
| bar #
| baz #
)+ # group occurs at least once
(etc...) # ...
/ix;

Python's re.VERBOSE flag was likely inspired by this modifier, and works
in a similar way:

pat = re.compile(r"""
^ # anchored at start of string
0x # prefix for hex value
([a-f0-9]+) # 1st group: hexadecimal digits
(etc...) # ...
""", re.VERBOSE)

Unfortunately, most other PCRE engines (that I know of) don't support
this feature (Ruby does). Would be nice to see this in JS, too.


--
stefan