Skip to content

Commit

Permalink
Allow certain keywords as function param names.
Browse files Browse the repository at this point in the history
Fixes #69.
  • Loading branch information
TwitchBronBron committed May 3, 2020
1 parent b458a03 commit 2679d26
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/parser/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down
5 changes: 4 additions & 1 deletion src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 2679d26

Please sign in to comment.