From 9eac5681b2e30323663ff22406b065d0f875bb21 Mon Sep 17 00:00:00 2001 From: James Clark Date: Tue, 18 Aug 2020 12:40:47 +0700 Subject: [PATCH] Start adding "on fail" Grammar changes done. Rearrange statement subsections. Part of #337. --- lang/spec.html | 163 +++++++++++++++++++++++++++++-------------------- 1 file changed, 97 insertions(+), 66 deletions(-) diff --git a/lang/spec.html b/lang/spec.html index 3ac727ca..5f995756 100644 --- a/lang/spec.html +++ b/lang/spec.html @@ -5991,10 +5991,10 @@

Function and worker execution

block-function-body :=
    { [default-worker-init named-worker-decl+] default-worker }
-default-worker-init := sequence-stmt
-default-worker := sequence-stmt
+default-worker-init := statement*
+default-worker := statement*
 named-worker-decl :=
-   [annots] worker worker-name return-type-descriptor { sequence-stmt }
+   [annots] worker worker-name return-type-descriptor statement-block
 worker-name := identifier
 

@@ -6048,7 +6048,7 @@

Function and worker execution

  1. The statements in default-worker-init are executed.
  2. All the named workers are started. Each named worker executes its -sequence-stmt on its strand.
  3. +statement-block on its strand.
  4. The statements in default-worker are executed. This happens without waiting for the termination of the named workers started in stage 2.
@@ -6057,10 +6057,10 @@

Function and worker execution

whereas variables declared in default-worker are not.

-The execution of a worker's sequence-stmt may result in the execution of a +The execution of a worker's statements may result in the execution of a statement that causes the worker to terminate. For example, a return statement causes the worker to terminate. If this does not happen, then the worker -terminates as soon as it has finished executing its sequence-stmt. In this case, +terminates as soon as it has finished executing its statements. In this case, the worker terminates normally, and the termination value is nil. In other words, falling off the end of a worker is equivalent to return;, which is in turn equivalent to return ();. @@ -6098,7 +6098,6 @@

Statement execution

statement := 
    action-stmt
-   | block-stmt
    | local-var-decl-stmt
    | xmlns-decl-stmt
    | assignment-stmt
@@ -6106,15 +6105,21 @@ 

Statement execution

| destructuring-assignment-stmt | call-stmt | if-else-stmt - | match-stmt - | foreach-stmt - | while-stmt - | break-stmt + | regular-compound-stmt | continue-stmt - | fork-stmt + | break-stmt + | stmt-with-on-fail + | fail-stmt | panic-stmt | return-stmt - | lock-stmt + | fork-stmt + +regular-compound-stmt := + do-stmt + | match-stmt + | foreach-stmt + | while-stmt + | lock-stmt

The execution of any statement may involve the evaluation of actions and @@ -6133,14 +6138,17 @@

Statement execution

sequence-stmt := statement*
-block-stmt := { sequence-stmt }
+class="grammar">
+statement-block := { statement* }
 

-A sequence-stmt executes its statements sequentially. A -block-stmt is executed by executing its sequence-stmt. +A statement-block is a syntactic grouping of statements, which are +executed sequentially.

+ + +

Fork statement

@@ -6637,7 +6645,7 @@

Remote interaction

Query action

query-action := query-pipeline do-clause
-do-clause := do block-stmt
+do-clause := do statement-block
 

The clauses in the query-pipeline of query-action are executed in the same way @@ -6645,7 +6653,7 @@

Query action

The query-action is executed as follows. For each input frame f -emitted by the query-pipeline, execute the block-stmt with f in +emitted by the query-pipeline, execute the statement-block with f in scope. If a clause in the query-pipeline completes early with error e, the result of the query-action is e. Otherwise, the result of the query-action is nil. @@ -6669,7 +6677,7 @@

Local variable declaration statements

The scope of variables declared in a local-var-decl-stmt starts -immediately after the statement and continues to the end of the block statement +immediately after the statement and continues to the end of the statement block in which it occurs.

@@ -7177,31 +7185,37 @@

Conditional statement

if-else-stmt :=
-   if expression block-stmt 
-   [ else if expression block-stmt ]* 
-   [ else block-stmt ]
+   if expression statement-block 
+   [ else if expression statement-block ]* 
+   [ else statement-block ]
 

The if-else statement is used for conditional execution.

The static type of the expression following if must be boolean. -When an expression is true then the corresponding block statement is executed +When an expression is true then the corresponding statement block is executed and the if statement completes. If no expression is true then, if the else block -is present, the corresponding block statement is executed. +is present, the corresponding statement block is executed.

+

Do statement

+
do-stmt := do statement-block
+
+
+

Match statement

match-stmt := match action-or-expr { match-clause+ }
 match-clause :=
-  match-pattern-list [match-guard] => block-stmt
+  match-pattern-list [match-guard] => statement-block
 match-guard := if expression
 

-A match statement selects a block statement to execute based on which patterns a +A match statement selects a statement block to execute based on which patterns a value matches.

@@ -7220,14 +7234,14 @@

Match statement

resulting in a value b
  • if b is false, then the execution of the match-stmt continues to the next match-clause
  • -
  • otherwise, the block-stmt in the match-clause is executed
  • +
  • otherwise, the statement-block in the match-clause is executed
  • execution of the match-stmt completes
  • The scope of any variables created in a match-pattern-list of a match-clause is -both the match-guard, if any, and the block-stmt in that match-clause. The +both the match-guard, if any, and the statement-block in that match-clause. The static type of the expression in match-guard must be a subtype of boolean.

    @@ -7337,16 +7351,16 @@

    Foreach statement

    foreach-stmt :=
    -   foreach typed-binding-pattern in action-or-expr block-stmt
    +   foreach typed-binding-pattern in action-or-expr statement-block
     

    -A foreach statement iterates over an iterable value, executing a block statement +A foreach statement iterates over an iterable value, executing a statement block once for each value in the iterable value's iteration sequence. The static type of action-or-expr must be an iterable type with an iteration completion type of nil.

    -The scope of any variables created in typed-binding-pattern is block-stmt. These +The scope of any variables created in typed-binding-pattern is statement-block. These variables are implicitly final.

    @@ -7366,7 +7380,7 @@

    Foreach statement

  • if n is nil, then terminate execution of the foreach statement
  • match typed-binding-pattern to n.value causing assignments to any variables that were created in typed-binding-pattern
  • -
  • execute block-stmt with the variable bindings from step 5 in scope; in the +
  • execute statement-block with the variable bindings from step 5 in scope; in the course of so doing
    1. the execution of a break-stmt terminates execution of the foreach statement
    2. @@ -7391,10 +7405,10 @@

      Foreach statement

      While statement

      while-stmt := while expression block-stmt
      +class="grammar">while-stmt := while expression statement-block
       

      -A while statement repeatedly executes a block statement so long as a +A while statement repeatedly executes a statement block so long as a boolean-valued expression evaluates to true.

      @@ -7404,7 +7418,7 @@

      While statement

    3. evaluate expression;
    4. if expression evaluates to false, terminate execution of the while statement;
    5. -
    6. execute block-stmt; in the course of so doing +
    7. execute statement-block; in the course of so doing
      1. the execution of a break-stmt results in termination of execution of the while statement
      2. @@ -7428,7 +7442,7 @@

        Continue statement

        A continue statement is only allowed if it is lexically enclosed within a while-stmt or a foreach-stmt. Executing a continue statement causes execution of the nearest enclosing while-stmt or foreach-stmt to jump to the end of the -outermost block-stmt in the while-stmt or foreach-stmt. +outermost statement-block in the while-stmt or foreach-stmt.

  • @@ -7442,43 +7456,17 @@

    Break statement

    enclosing while-stmt or foreach-stmt to terminate.

    -
    -

    Panic statement

    - -
    panic-stmt := panic expression ;
    -
    -

    -A panic statement terminates the current worker abnormally. The result of -evaluating expression provides the termination value of the worker. -

    -

    -The static type of expression must be a subtype of error. -

    -
    -
    -

    Return statement

    - -
    return-stmt := return [ action-or-expr ] ;
    -
    -

    -A return statement terminates the current worker normally.The result of -evaluating the action-or-expr provides the termination value of the worker. If -action-or-expr is omitted, then the termination value is nil. -

    -

    Lock statement

    lock-stmt := lock block-stmt
    +class="grammar">lock-stmt := lock statement-block
     

    -A lock-stmt executing in the context of some strand must execute its block-stmt +A lock-stmt executing in the context of some strand must execute its statement-block in such a way that the effect on the state of the program is consistent with the -execution of the block-stmt not being interleaved with the execution of a +execution of the statement-block not being interleaved with the execution of a lock-stmt on any other strand.

    @@ -7501,6 +7489,49 @@

    Lock statement

    +
    +

    On fail clause

    +
    stmt-with-on-fail := regular-compound-stmt on-fail-clause
    +on-fail-clause := on fail typed-binding-pattern statement-block
    +
    +
    + +
    +

    Fail statement

    +
    fail-stmt := fail expression ;
    +
    +
    + +
    +

    Panic statement

    + +
    panic-stmt := panic expression ;
    +
    +

    +A panic statement terminates the current worker abnormally. The result of +evaluating expression provides the termination value of the worker. +

    +

    +The static type of expression must be a subtype of error. +

    +
    + +
    +

    Return statement

    + +
    return-stmt := return [ action-or-expr ] ;
    +
    +

    +A return statement terminates the current worker normally.The result of +evaluating the action-or-expr provides the termination value of the worker. If +action-or-expr is omitted, then the termination value is nil. +

    +
    +

    8. Module-level declarations