Search in sources :

Example 1 with Separator

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;
}
Also used : MacroToken(org.develnext.jphp.core.tokenizer.token.expr.value.macro.MacroToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) Token(org.develnext.jphp.core.tokenizer.token.Token) CastExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.cast.CastExprToken) BreakToken(org.develnext.jphp.core.tokenizer.token.BreakToken) ColonToken(org.develnext.jphp.core.tokenizer.token.ColonToken) UnsetCastExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.cast.UnsetCastExprToken) Separator(org.develnext.jphp.core.common.Separator)

Aggregations

Separator (org.develnext.jphp.core.common.Separator)1 BreakToken (org.develnext.jphp.core.tokenizer.token.BreakToken)1 ColonToken (org.develnext.jphp.core.tokenizer.token.ColonToken)1 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)1 Token (org.develnext.jphp.core.tokenizer.token.Token)1 CastExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.cast.CastExprToken)1 UnsetCastExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.cast.UnsetCastExprToken)1 MacroToken (org.develnext.jphp.core.tokenizer.token.expr.value.macro.MacroToken)1