In the tradition of Perl concision, I would like newline to be a
statement terminator everywhere it can: that is when 
       a) the parser expects an operator 
 _and_ b)  we are not in the middle of a parenthesised expression.

Accessorily, it would also help people to switch back and forth
between language that use newline as statement terminator and perl6:
they will not be burn anymore when forgetting a semicolon.

Semicolons are still allowed everywhere as statement terminator
because empty statements are.

So, In the common case, oneliner atomic statements, the proposed rule
means: you can drop the ending semicolon.

BTW: Atomic statement are statement composed of one expression only.
For composite multiline statements, see "About the b) rule" below.

Multiline atomic statements just have to be broken at the right
place to avoid to break them:

 a +
 b

is equivalent to

 a + b

But

 a
 + b

are two statements.

Note that in Perl5, semicolon is not always required as statement
terminator.  At the end of a scope, being a closing brace, or the end
of a program, including an explicit eval or an implicit one (perldb
shell).

Note that, for Perl 6,  Larry has already opened the path in his fourth apocalypse:

 $x = do {
        ...
    } + 1;
 

is different from

 
    $x = do {
        ...
    }
    + 1;

I just want to make a rule of what Larry made a special case.

About the b) rule.
------------------

The following code does not parse because of the newlines that are
interpreted as statement terminator.

  for 
  1..10
  { ... }

But

  for (
    1.. 10
  ) {
  } 

is legit.

Smart parser may allow to avoid these otherwise spurious parentheses
--------------------------------------------------------------------

.. and make

  for 
  1..10
  { ... }

a legit expression following the rule "what could have a meaning should".


The b) rule may not even be necessary with enough  parsing state.
The parser could have the following exclusive states:
  1) expecting an operator
  2) expecting an operand (newline is statement terminator)
      The expected operand is an expression that is part of an atomic statement
      deemed as atomic.
  3) expecting  an operand (newline is ignored)
      The expected operand is an expression that is directly part of
      a composite statement. (as opposed as part of an atomic
      statement part of a composite one).

What I mean by "deemed as atomic"? 

When parsing a composite statement, we don't know from the start that
it is so.  The following statement:

  $a if $b

is deemed atomic until the parse deals with the 'if' token.

My proposition could then be expressed informally:

  Newline is interpred as statement terminator when it makes sense.

It does not when :
  A) in the middle of an expression when an operand is expected
  B) within a parenthesised expression
  C) and other cases that would also cause the parsing to return an error

Note: The b/ rule was an undeeded attempt to force C/ into B/.

--
 stef


Reply via email to