Search in sources :

Example 1 with OrExprToken

use of org.develnext.jphp.core.tokenizer.token.expr.operator.OrExprToken in project jphp by jphp-compiler.

the class TryCatchGenerator method processCatch.

public void processCatch(CatchStmtToken result, ListIterator<Token> iterator) {
    Token next = nextToken(iterator);
    if (!isOpenedBrace(next, BraceExprToken.Kind.SIMPLE))
        unexpectedToken(next, "(");
    List<FulledNameToken> exceptions = new ArrayList<>();
    do {
        next = nextToken(iterator);
        if (!(next instanceof NameToken)) {
            if (exceptions.isEmpty()) {
                unexpectedToken(next, TokenType.T_STRING);
            } else {
                iterator.previous();
                break;
            }
        }
        FulledNameToken exception = analyzer.getRealName((NameToken) next);
        exceptions.add(exception);
        next = nextToken(iterator);
        if (!(next instanceof OrExprToken)) {
            iterator.previous();
            break;
        }
    } while (true);
    result.setExceptions(exceptions);
    next = nextToken(iterator);
    if (!(next instanceof VariableExprToken))
        unexpectedToken(next, TokenType.T_VARIABLE);
    VariableExprToken variable = (VariableExprToken) next;
    result.setVariable(variable);
    if (analyzer.getFunction() != null) {
        analyzer.getFunction().variable(variable).setUnstable(true);
    }
    analyzer.getScope().addVariable(variable);
    next = nextToken(iterator);
    if (!isClosedBrace(next, BraceExprToken.Kind.SIMPLE))
        unexpectedToken(next, ")");
    BodyStmtToken body = analyzer.generator(BodyGenerator.class).getToken(nextToken(iterator), iterator);
    result.setBody(body);
}
Also used : BodyGenerator(org.develnext.jphp.core.syntax.generators.manually.BodyGenerator) ArrayList(java.util.ArrayList) Token(org.develnext.jphp.core.tokenizer.token.Token) OrExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.OrExprToken) BodyStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.BodyStmtToken) VariableExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken) FinallyStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FinallyStmtToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken) FulledNameToken(org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken) TryStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.TryStmtToken) CatchStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.CatchStmtToken) VariableExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken) OrExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.OrExprToken) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken) FulledNameToken(org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken) FulledNameToken(org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken) BodyStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.BodyStmtToken)

Aggregations

ArrayList (java.util.ArrayList)1 BodyGenerator (org.develnext.jphp.core.syntax.generators.manually.BodyGenerator)1 Token (org.develnext.jphp.core.tokenizer.token.Token)1 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)1 OrExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.OrExprToken)1 FulledNameToken (org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken)1 NameToken (org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)1 VariableExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken)1 BodyStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.BodyStmtToken)1 CatchStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.CatchStmtToken)1 FinallyStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.FinallyStmtToken)1 TryStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.TryStmtToken)1