Skip to content

Commit

Permalink
Add interface parameter support (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Oct 2, 2023
1 parent 3b45aa6 commit d9366b9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
19 changes: 18 additions & 1 deletion docs/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,21 @@ end interface
```BrightScript
```
</details>
</details>

</details>

## Methods
Interfaces can describe complex methods as well
```brighterscript
interface Dog
sub barkAt(nemesis as Cat)
end interface
```

<details>
<summary>View the transpiled BrightScript code</summary>

```BrightScript
```
</details>
14 changes: 13 additions & 1 deletion src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,19 @@ export class Parser {
const name = this.identifier(...AllowedProperties);
const leftParen = this.consumeToken(TokenKind.LeftParen);

const params = [];
let params = [] as FunctionParameterExpression[];
if (!this.check(TokenKind.RightParen)) {
do {
if (params.length >= CallExpression.MaximumArguments) {
this.diagnostics.push({
...DiagnosticMessages.tooManyCallableParameters(params.length, CallExpression.MaximumArguments),
range: this.peek().range
});
}

params.push(this.functionParameter());
} while (this.match(TokenKind.Comma));
}
const rightParen = this.consumeToken(TokenKind.RightParen);
let asToken = null as Token;
let returnTypeToken = null as Token;
Expand Down
9 changes: 9 additions & 0 deletions src/parser/tests/statement/InterfaceStatement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,13 @@ describe('InterfaceStatement', () => {
'this comment was throwing exception during transpile
`);
});

it('allows parameters in interface method signatures', () => {
testGetTypedef(`
interface Person
sub someFunc(name as string, age as integer) as string
someField as string
end interface
`, undefined, undefined, undefined, true);
});
});

0 comments on commit d9366b9

Please sign in to comment.