Skip to content

Commit

Permalink
Handle []s after TypeAnnotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesterday17 committed Jan 28, 2019
1 parent 9c21e25 commit 4a5bf80
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions server/parser/zsInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,24 +358,26 @@ class ZenScriptInterpreter extends ZSParser.getBaseCstVisitorConstructor() {
}

protected TypeAnnotation(ctx: NodeContext): ASTNode {
let type;

// Imported type
if (ctx.IDENTIFIER) {
return {
type = {
type: 'IMPORT',
item: ctx.IDENTIFIER.map((identifier: IToken) => identifier.image),
};
}

// Type from ANY - STRING
if (Object.keys(ctx).length === 1) {
return {
type = {
type: Object.keys(ctx)[0],
};
}

// Function type
if (ctx.FUNCTION) {
return {
type = {
type: 'FUNCTION',
item: ctx.ParameterType.map((type: any) => this.visit(type)),
return: this.visit(ctx.FunctionType),
Expand All @@ -384,11 +386,21 @@ class ZenScriptInterpreter extends ZSParser.getBaseCstVisitorConstructor() {

// Array type
if (ctx.ArrayType) {
return {
type = {
type: 'ARRAY',
item: this.visit(ctx.ArrayType),
};
}

if (ctx.SQBR_OPEN) {
return {
type: 'A_ARRAY',
item: type,
level: ctx.SQBR_OPEN.length,
};
}

return type;
}
}

Expand Down

0 comments on commit 4a5bf80

Please sign in to comment.