From 2679d2621615ae9b74542db6eb26858ff46cf6dd Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Sun, 3 May 2020 15:06:15 -0400 Subject: [PATCH] Allow certain keywords as function param names. Fixes #69. --- CHANGELOG.md | 4 ++++ src/parser/Parser.spec.ts | 6 ++++++ src/parser/Parser.ts | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a662b1c4c..1da069fff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased +### Fixed + - issue that prevented certain keywords from being used as function parameter names ([#69](https://github.com/rokucommunity/brighterscript/issues/69)) + ## 0.9.2 - 2020-05-02 ### Changed diff --git a/src/parser/Parser.spec.ts b/src/parser/Parser.spec.ts index 5c4b45569..8dfca93b7 100644 --- a/src/parser/Parser.spec.ts +++ b/src/parser/Parser.spec.ts @@ -25,6 +25,12 @@ describe('parser', () => { }); describe('parse', () => { + it('supports using "interface" as parameter name', () => { + expect(parse(` + sub main(interface as object) + end sub + `, ParseMode.BrighterScript).diagnostics[0]?.message).not.to.exist; + }); describe('namespace', () => { it('catches namespaces declared not at root level', () => { expect(parse(` diff --git a/src/parser/Parser.ts b/src/parser/Parser.ts index 6962ea715..26c9a268b 100644 --- a/src/parser/Parser.ts +++ b/src/parser/Parser.ts @@ -589,7 +589,7 @@ export class Parser { } private functionParameter(): FunctionParameter { - if (!this.check(TokenKind.Identifier)) { + if (!this.check(TokenKind.Identifier, ...AllowedLocalIdentifiers)) { this.diagnostics.push({ ...DiagnosticMessages.expectedParameterNameButFound(this.peek().text), range: this.peek().range @@ -598,6 +598,9 @@ export class Parser { } let name = this.advance() as Identifier; + // force the name into an identifier so the AST makes some sense + name.kind = TokenKind.Identifier; + let type: ValueKind = ValueKind.Dynamic; let typeToken: Token | undefined; let defaultValue;