rokucommunity/brighterscript

Merge `ExitWhileStatement` and `ExitForStatement`

Closed this issue · 4 comments

I'm not sure why there are two separate statements here, for exit while and exit for. I think exit on its own is also technically valid syntax.

We should merge them into a single ExitStatement that optionally takes a tokenKind for the thing that comes after it.

exit on its own is a syntax error:

  for i = 1 to 10
    if i mod 4 = 0
      exit
    end if
    print i
  end for

produces:

Syntax Error. (compile error &h02 (ERR_SYNTAX): syntax error ) in main.main(12)
=================================================================
An error occurred while attempting to compile the application's components:
-------> Compilation Failed.
pkg:/source/main.brs(NaN)
Syntax Error. (compile error &h02 (ERR_SYNTAX): syntax error ) in main.main(12)

I think we should just leave it as-is.

Regardless of the standalone exit not being valid, is there any reason to have separate exit for and exit while statements? We have a single ContinueStatement, I think exit <something> makes sense to be a single statement type as well.

export class ContinueStatement extends Statement {

Good point... i'll merge them