use of org.develnext.jphp.core.common.Separator in project jphp by jphp-compiler.
the class SimpleExprGenerator method processArrayToken.
protected Token processArrayToken(Token previous, Token current, ListIterator<Token> iterator) {
BraceExprToken.Kind braceKind = ARRAY;
Separator separator = Separator.ARRAY;
if (isOpenedBrace(current, BLOCK)) {
braceKind = BLOCK;
separator = Separator.ARRAY_BLOCK;
}
VariableExprToken var = null;
if (previous instanceof VariableExprToken) {
if (analyzer.getFunction() != null) {
analyzer.getFunction().variable(var = (VariableExprToken) previous).setArrayAccess(true);
}
}
Token next = nextToken(iterator);
if (isClosedBrace(next, braceKind)) {
// !!! allow [] anywhere
return new ArrayPushExprToken(TokenMeta.of(current, next));
/*} else
unexpectedToken(tk);*/
} else
iterator.previous();
ExprStmtToken param;
List<ExprStmtToken> parameters = new ArrayList<>();
boolean lastPush = false;
do {
Token token = nextToken(iterator);
if (isClosedBrace(token, ARRAY)) {
iterator.previous();
if (iterator.hasPrevious()) {
iterator.previous();
}
lastPush = true;
break;
} else {
param = analyzer.generator(SimpleExprGenerator.class).getNextExpression(token, iterator, separator, braceKind);
}
if (param != null) {
parameters.add(param);
if (iterator.hasNext()) {
iterator.next();
if (iterator.hasNext()) {
Token tmp = nextToken(iterator);
if (isOpenedBrace(tmp, ARRAY)) {
braceKind = ARRAY;
separator = Separator.ARRAY;
continue;
} else if (isOpenedBrace(tmp, BLOCK)) {
braceKind = BLOCK;
separator = Separator.ARRAY_BLOCK;
continue;
}
iterator.previous();
}
break;
}
}
} while (param != null);
//nextToken(iterator); // skip ]
ArrayGetExprToken result;
result = new ArrayGetExprToken(current.getMeta());
result.setParameters(parameters);
if (isRef) {
result = new ArrayGetRefExprToken(result);
((ArrayGetRefExprToken) result).setShortcut(true);
if (var != null && analyzer.getFunction() != null) {
analyzer.getFunction().variable(var).setMutable(true);
}
} else if (iterator.hasNext()) {
next = iterator.next();
if (next instanceof AssignableOperatorToken || lastPush) {
result = new ArrayGetRefExprToken(result);
if (var != null && analyzer.getFunction() != null) {
analyzer.getFunction().variable(var).setMutable(true);
}
}
iterator.previous();
}
return result;
}
Aggregations