|
|
@@ -65,11 +65,36 @@ export default class Parser {
|
|
65
|
65
|
const args = [];
|
|
66
|
66
|
|
|
67
|
67
|
while (true) {
|
|
68
|
|
- const arg = this.expr();
|
|
69
|
|
- if (isError(arg)) {
|
|
70
|
|
- return arg;
|
|
|
68
|
+ if (this.match(TokenKind.STAR)) {
|
|
|
69
|
+ this.eat(TokenKind.STAR);
|
|
|
70
|
+ args.push(new AST.Star());
|
|
|
71
|
+ } else if (this.match(TokenKind.IDENTIFIER) && this.peek_match(TokenKind.DOT)) {
|
|
|
72
|
+ const left = this.identifier();
|
|
|
73
|
+ if (isError(left)) {
|
|
|
74
|
+ return left;
|
|
|
75
|
+ }
|
|
|
76
|
+ const right = this.selectArgumentDotExpression(left);
|
|
|
77
|
+ if (isError(right)) {
|
|
|
78
|
+ return right;
|
|
|
79
|
+ }
|
|
|
80
|
+ args.push(right);
|
|
|
81
|
+ } else if (this.match(TokenKind.BACKTICK) && this.peek_match(TokenKind.DOT, 3)) {
|
|
|
82
|
+ const left = this.backtick();
|
|
|
83
|
+ if (isError(left)) {
|
|
|
84
|
+ return left;
|
|
|
85
|
+ }
|
|
|
86
|
+ const right = this.selectArgumentDotExpression(left);
|
|
|
87
|
+ if (isError(right)) {
|
|
|
88
|
+ return right;
|
|
|
89
|
+ }
|
|
|
90
|
+ args.push(right);
|
|
|
91
|
+ } else {
|
|
|
92
|
+ const arg = this.expr();
|
|
|
93
|
+ if (isError(arg)) {
|
|
|
94
|
+ return arg;
|
|
|
95
|
+ }
|
|
|
96
|
+ args.push(arg);
|
|
71
|
97
|
}
|
|
72
|
|
- args.push(arg);
|
|
73
|
98
|
|
|
74
|
99
|
if (this.match(TokenKind.COMMA)) {
|
|
75
|
100
|
this.eat(TokenKind.COMMA);
|
|
|
@@ -81,6 +106,22 @@ export default class Parser {
|
|
81
|
106
|
return args;
|
|
82
|
107
|
}
|
|
83
|
108
|
|
|
|
109
|
+ private selectArgumentDotExpression(left: AST.Identifier | AST.Backtick): AST.Expr | Error {
|
|
|
110
|
+ this.eat(TokenKind.DOT);
|
|
|
111
|
+
|
|
|
112
|
+ if (this.match(TokenKind.STAR)) {
|
|
|
113
|
+ this.eat(TokenKind.STAR);
|
|
|
114
|
+ const right = new AST.Star();
|
|
|
115
|
+ return new AST.Binary({ left, right, type: AST.BinaryExpressionTypes.DOT });
|
|
|
116
|
+ } else {
|
|
|
117
|
+ const right = this.expr();
|
|
|
118
|
+ if (isError(right)) {
|
|
|
119
|
+ return right;
|
|
|
120
|
+ }
|
|
|
121
|
+ return new AST.Binary({ left, right, type: AST.BinaryExpressionTypes.DOT });
|
|
|
122
|
+ }
|
|
|
123
|
+ }
|
|
|
124
|
+
|
|
84
|
125
|
private from(): AST.FromTarget | Error {
|
|
85
|
126
|
this.eat(TokenKind.FROM);
|
|
86
|
127
|
return this.fromTarget();
|
|
|
@@ -404,6 +445,11 @@ export default class Parser {
|
|
404
|
445
|
return this.currentToken().kind === kind;
|
|
405
|
446
|
}
|
|
406
|
447
|
|
|
|
448
|
+ private peek_match(kind: TokenKind, step: number = 1): boolean {
|
|
|
449
|
+ const token = this.tokens[this.position + step];
|
|
|
450
|
+ return token && token.kind === kind;
|
|
|
451
|
+ }
|
|
|
452
|
+
|
|
407
|
453
|
private currentToken(): Token {
|
|
408
|
454
|
return this.tokens[this.position];
|
|
409
|
455
|
}
|