Search in sources :

Example 11 with NameToken

use of org.develnext.jphp.core.tokenizer.token.expr.value.NameToken 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, "(");
    next = nextToken(iterator);
    if (!(next instanceof NameToken))
        unexpectedToken(next, TokenType.T_STRING);
    FulledNameToken exception = analyzer.getRealName((NameToken) next);
    result.setException(exception);
    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) Token(org.develnext.jphp.core.tokenizer.token.Token) 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) 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)

Example 12 with NameToken

use of org.develnext.jphp.core.tokenizer.token.expr.value.NameToken in project jphp by jphp-compiler.

the class ConstGenerator method getToken.

/*@SuppressWarnings("unchecked")
    protected void processBody(ConstStmtToken result, ListIterator<Token> iterator){
        Token current = nextToken(iterator);
        if (!(current instanceof AssignExprToken))
            unexpectedToken(current, "=");

        ExprStmtToken value = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator);
        if (value == null)
            unexpectedToken(nextToken(iterator));

        result.setValue(value);
    }*/
@Override
@SuppressWarnings("unchecked")
public ConstStmtToken getToken(Token current, ListIterator<Token> iterator) {
    if (current instanceof ConstStmtToken) {
        ConstStmtToken result = (ConstStmtToken) current;
        Token prev = null;
        if (analyzer.getClazz() == null)
            result.setNamespace(analyzer.getNamespace());
        while (true) {
            Token next = analyzer.getClazz() == null ? nextToken(iterator) : nextTokenSensitive(iterator, ClassStmtToken.class);
            if (next instanceof NameToken) {
                if (next instanceof FulledNameToken && !((FulledNameToken) next).isProcessed(NamespaceUseStmtToken.UseType.CONSTANT))
                    unexpectedToken(next, TokenType.T_STRING);
                Token token = nextToken(iterator);
                if (!(token instanceof AssignExprToken))
                    unexpectedToken(token, "=");
                ExprStmtToken value = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator, Separator.COMMA_OR_SEMICOLON, null);
                if (!isBreak(iterator.previous())) {
                    iterator.next();
                }
                if (value == null)
                    unexpectedToken(iterator.previous());
                result.add((NameToken) next, value);
            } else if (next instanceof CommaToken) {
                if (prev instanceof CommaToken)
                    unexpectedToken(next);
                prev = next;
            } else if (isBreak(next)) {
                break;
            } else
                unexpectedToken(next, TokenType.T_STRING);
        }
        return result;
    }
    return null;
}
Also used : CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) SimpleExprGenerator(org.develnext.jphp.core.syntax.generators.manually.SimpleExprGenerator) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken) Token(org.develnext.jphp.core.tokenizer.token.Token) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) ClassExprToken(org.develnext.jphp.core.tokenizer.token.expr.ClassExprToken) ImportExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.ImportExprToken) OperatorExprToken(org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken) FulledNameToken(org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken) CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) 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)

Aggregations

NameToken (org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)12 FulledNameToken (org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken)6 Token (org.develnext.jphp.core.tokenizer.token.Token)4 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)2 CommaToken (org.develnext.jphp.core.tokenizer.token.expr.CommaToken)2 OperatorExprToken (org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken)2 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)2 StaticAccessExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.StaticAccessExprToken)2 ClassStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken)2 MethodStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken)2 Memory (php.runtime.Memory)2 Environment (php.runtime.env.Environment)2 ArrayList (java.util.ArrayList)1 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)1 MethodNodeImpl (org.develnext.jphp.core.compiler.jvm.node.MethodNodeImpl)1 BodyGenerator (org.develnext.jphp.core.syntax.generators.manually.BodyGenerator)1 SimpleExprGenerator (org.develnext.jphp.core.syntax.generators.manually.SimpleExprGenerator)1 TokenMeta (org.develnext.jphp.core.tokenizer.TokenMeta)1 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)1 BackslashExprToken (org.develnext.jphp.core.tokenizer.token.expr.BackslashExprToken)1