Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #26340

Re: Optional semicolons - wrong rule or wrong example?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.javascript
Subject Re: Optional semicolons - wrong rule or wrong example?
Date Tue, 16 Dec 2014 23:21:15 +0100
Organization solani.org
Lines 41
Message-ID <m6qb8p$2bg$1@solani.org> (permalink)
References <4ca7db7d-5a3b-457d-8601-aa9c72afab36@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace solani.org 1418768473 2416 eJwNx8ERwDAIA7CVYsCAxym9sP8IrX6iJ/KtSGZwudesHeeJUG+ZZv4ArcKGriCgXATrDMo++G0PVQ== (16 Dec 2014 22:21:13 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Tue, 16 Dec 2014 22:21:13 +0000 (UTC)
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
X-User-ID eJwNyMkBwCAMA7CVUnBi1smB9x+B6inf8UUT4QGXS2Frzm6kbG5DrP9xV5F1pCKsOLiWxU5/MqgSHw==
In-Reply-To <4ca7db7d-5a3b-457d-8601-aa9c72afab36@googlegroups.com>
Cancel-Lock sha1:/5lv50p3kXj/UgE/hEAWeE7mey4=
X-NNTP-Posting-Host eJwFwYkBgDAIA8CVaiFBx+HL/iN4B+PDDifoEBTemk37TtQKmevJE5zrr4o+DA1W1W4ouz84JBH4
Xref csiph.com comp.lang.javascript:26340

Show key headers only | View raw


Peter wrote:

> In the 6th edition of "JavaScript: The Definitive Guide", in chapter
> 2.5 (Optional Semicolons), the following rule can be found:
> 
> "JavaScript treats a line break as a semicolon if the next nonspace
> character cannot be interpreted as a continuation of the current
> statement".
> 
> and the following example is given:
> 
> var a a = 3 console.log(a)
> 
> According to the author, the above shall be treated as:
> 
> var a; a = 3; console.log(a);
> 
> He justifies it as follows:
> 
> "JavaScript does treat the first line break as a semicolon because it
> cannot parse the code var a a without a semicolon.">

The ECMAScript specification, edition 5.1, explains the rule more
clearly[1]:

| When, as the program is parsed from left to right, a token (called
| the offending token) is encountered that is not allowed by any
| production of the grammar, then a semicolon is automatically inserted
| before the offending token if one or more of the following conditions
| is true:
| * The offending token is separated from the previous token by at
| least one LineTerminator.
| * The offending token is }.

Obviously, it is important to clearly distinguish between *tokens* and
*characters* for this rule.

<http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1>

-- 
Christoph M. Becker

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Optional semicolons - wrong rule or wrong example? Peter <pilarp@poczta.onet.pl> - 2014-12-16 13:58 -0800
  Re: Optional semicolons - wrong rule or wrong example? "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-12-16 23:21 +0100
  Re: Optional semicolons - wrong rule or wrong example? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-17 00:10 +0100
    JavaScript: The Definitive Guide (was: Optional semicolons - wrong rule or wrong example?) "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-12-17 01:29 +0100
      Re: JavaScript: The Definitive Guide Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-20 23:00 +0100
        Re: JavaScript: The Definitive Guide Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-20 23:04 +0100
        Re: JavaScript: The Definitive Guide "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-12-28 23:52 +0100
          Re: JavaScript: The Definitive Guide Tim Streater <timstreater@greenbee.net> - 2014-12-28 23:52 +0000
            Re: JavaScript: The Definitive Guide Scott Sauyet <scott.sauyet@gmail.com> - 2015-01-01 21:46 -0800
              Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-02 09:32 +0100
                Re: JavaScript: The Definitive Guide Andrew Poulos <ap_prog@hotmail.com> - 2015-01-03 07:54 +1100
                Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-02 22:14 +0100
                Re: JavaScript: The Definitive Guide Andrew Poulos <ap_prog@hotmail.com> - 2015-01-03 11:46 +1100
                Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-03 11:59 +0100
                Re: JavaScript: The Definitive Guide Andrew Poulos <ap_prog@hotmail.com> - 2015-01-03 23:46 +1100
                Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-03 14:57 +0100
                Re: JavaScript: The Definitive Guide Andrew Poulos <ap_prog@hotmail.com> - 2015-01-04 09:31 +1100
                Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-04 00:29 +0100
                Re: JavaScript: The Definitive Guide Andrew Poulos <ap_prog@hotmail.com> - 2015-01-04 20:17 +1100
                Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-04 10:57 +0100
                OT: Mass, weight and friction (was: JavaScript: The Definitive Guide) "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-01-03 02:52 +0100
  Re: Optional semicolons - wrong rule or wrong example? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2014-12-18 14:39 +0100
    Re: Optional semicolons - wrong rule or wrong example? Tim Streater <timstreater@greenbee.net> - 2014-12-18 14:04 +0000

csiph-web