1
0
mirror of https://github.com/fluencelabs/assemblyscript synced 2025-06-17 00:41:32 +00:00

Initial element access compilation; Carefully approaching std array

This commit is contained in:
dcodeIO
2018-01-13 23:38:07 +01:00
parent dd596b015d
commit 2c009c67d3
21 changed files with 9914 additions and 88 deletions

@ -1580,6 +1580,19 @@ export class Parser extends DiagnosticEmitter {
var startPos = expr.range.start;
// ElementAccessExpression
if (tn.skip(Token.OPENBRACKET)) {
next = this.parseExpression(tn); // resets precedence
if (!next)
return null;
if (tn.skip(Token.CLOSEBRACKET))
expr = Node.createElementAccessExpression(<Expression>expr, <Expression>next, tn.range(startPos, tn.pos));
else {
this.error(DiagnosticCode._0_expected, tn.range(), "]");
return null;
}
}
// CallExpression
var typeArguments = this.tryParseTypeArgumentsBeforeArguments(tn); // skips '(' on success
// there might be better ways to distinguish a LESSTHAN from a CALL with type arguments
@ -1593,7 +1606,6 @@ export class Parser extends DiagnosticEmitter {
var token: Token;
var next: Expression | null = null;
var nextPrecedence: Precedence;
while ((nextPrecedence = determinePrecedence(token = tn.peek())) >= precedence) { // precedence climbing
tn.next();
@ -1604,19 +1616,6 @@ export class Parser extends DiagnosticEmitter {
return null;
expr = Node.createAssertionExpression(AssertionKind.AS, expr, toType, tn.range(startPos, tn.pos));
// ElementAccessExpression
} else if (token == Token.OPENBRACKET) {
next = this.parseExpression(tn); // resets precedence
if (!next)
return null;
if (tn.skip(Token.CLOSEBRACKET))
expr = Node.createElementAccessExpression(<Expression>expr, <Expression>next, tn.range(startPos, tn.pos));
else {
this.error(DiagnosticCode._0_expected, tn.range(), "]");
return null;
}
// UnaryPostfixExpression
} else if (token == Token.PLUS_PLUS || token == Token.MINUS_MINUS) {
if (expr.kind != NodeKind.IDENTIFIER && expr.kind != NodeKind.ELEMENTACCESS && expr.kind != NodeKind.PROPERTYACCESS)