Skip to content

Commit 6217738

Browse files
authored
Adding stream keyword on unary parameters and returns (#13)
1 parent a8c7d75 commit 6217738

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/ast/kinds.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export enum Kind {
2323
ListType = "ListType",
2424
MapType = "MapType",
2525
Optional = "Optional",
26+
Stream = "Stream",
2627

2728
// Definitions
2829
NamespaceDefinition = "NamespaceDefinition",

src/ast/types.ts

+13
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,16 @@ export class Optional extends AbstractNode implements Type {
5959
return this.getKind();
6060
}
6161
}
62+
63+
export class Stream extends AbstractNode implements Type {
64+
type: Type;
65+
66+
constructor(loc: Location | undefined, type: Type) {
67+
super(Kind.Stream, loc);
68+
this.type = type || null;
69+
}
70+
71+
public string(): string {
72+
return this.getKind();
73+
}
74+
}

src/parser.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
Definition,
4343
ImportName,
4444
Kind,
45+
Stream,
4546
} from "./ast";
4647

4748
type parseFunction = () => Node;
@@ -325,7 +326,13 @@ class Parser {
325326
const colon = this.expectOptionalToken(TokenKind.COLON);
326327
let type: Type = new Named(undefined, new Name(undefined, "void"));
327328
if (colon) {
329+
const streamLoc = this.loc(this._lexer.token);
330+
const stream = this.expectOptionalKeyword("stream");
328331
type = this.parseType();
332+
if (stream) {
333+
const streamLoc = this.loc(this._lexer.token);
334+
type = new Stream(streamLoc, type);
335+
}
329336
}
330337
const annotations = this.parseAnnotations();
331338

@@ -798,7 +805,7 @@ class Parser {
798805
} else if (unary && this.peek(TokenKind.BRACE_L)) {
799806
// unary
800807
this._lexer.advance();
801-
const inputValueDef = this.parseParameterDefinition();
808+
const inputValueDef = this.parseParameterDefinition(true);
802809
this.expectToken(TokenKind.BRACE_R);
803810
const arr = new Array<ParameterDefinition>();
804811
arr.push(inputValueDef);
@@ -814,12 +821,17 @@ class Parser {
814821
* ParameterDefinition :
815822
* - Description? Name : Type DefaultValue? Annotations[Const]?
816823
*/
817-
parseParameterDefinition(): ParameterDefinition {
824+
parseParameterDefinition(allowStream: boolean = false): ParameterDefinition {
818825
const start = this._lexer.token;
819826
const description = this.parseDescription();
820827
const name = this.parseName();
821828
this.expectToken(TokenKind.COLON);
822-
const type = this.parseType();
829+
const streamLoc = this.loc(this._lexer.token);
830+
const stream = allowStream && this.expectOptionalKeyword("stream");
831+
var type = this.parseType();
832+
if (stream) {
833+
type = new Stream(streamLoc, type);
834+
}
823835
let defaultValue: Value | undefined;
824836
if (this.expectOptionalToken(TokenKind.EQUALS)) {
825837
defaultValue = this.parseConstValue();

0 commit comments

Comments
 (0)