From 8ab35dd55f25ee850d36c8b05eaaaf3b3506c355 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Thu, 27 Oct 2022 14:24:54 -0400 Subject: [PATCH] Allow `continue` as local var --- src/parser/Parser.ts | 3 ++- src/parser/tests/statement/Continue.spec.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/parser/Parser.ts b/src/parser/Parser.ts index 3f619d5e8..3282b7c9a 100644 --- a/src/parser/Parser.ts +++ b/src/parser/Parser.ts @@ -1112,7 +1112,8 @@ export class Parser { return this.gotoStatement(); } - if (this.check(TokenKind.Continue)) { + //the continue keyword (followed by `for`, `while`, or a statement separator) + if (this.check(TokenKind.Continue) && this.checkAnyNext(TokenKind.While, TokenKind.For, TokenKind.Newline, TokenKind.Colon, TokenKind.Comment)) { return this.continueStatement(); } diff --git a/src/parser/tests/statement/Continue.spec.ts b/src/parser/tests/statement/Continue.spec.ts index 099b8aa69..70d2d5581 100644 --- a/src/parser/tests/statement/Continue.spec.ts +++ b/src/parser/tests/statement/Continue.spec.ts @@ -82,6 +82,20 @@ describe('parser continue statements', () => { ]); }); + it('allows `continue` to be used as a local variable', () => { + program.setFile('source/main.bs', ` + sub main() + continue = true + print continue + if not continue then + print continue + end if + end sub + `); + program.validate(); + expectZeroDiagnostics(program); + }); + it('transpiles properly', () => { testTranspile(` sub main()