Search in sources :

Example 6 with FulledNameToken

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

the class NamespaceGenerator method getToken.

@Override
public NamespaceStmtToken getToken(Token current, ListIterator<Token> iterator) {
    if (current instanceof NamespaceStmtToken) {
        NamespaceStmtToken result = (NamespaceStmtToken) current;
        FulledNameToken name = analyzer.generator(NameGenerator.class).getToken(nextToken(iterator), iterator);
        result.setName(name);
        if (name == null)
            iterator.previous();
        analyzer.setNamespace(result);
        processBody(result, iterator);
        analyzer.setNamespace(NamespaceStmtToken.getDefault());
        return result;
    }
    return null;
}
Also used : NamespaceStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.NamespaceStmtToken) FulledNameToken(org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken)

Example 7 with FulledNameToken

use of org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken 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 8 with FulledNameToken

use of org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken 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

FulledNameToken (org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken)8 NameToken (org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)5 Token (org.develnext.jphp.core.tokenizer.token.Token)4 Environment (php.runtime.env.Environment)3 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)2 CommaToken (org.develnext.jphp.core.tokenizer.token.expr.CommaToken)2 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)2 SelfExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.SelfExprToken)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 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)1 BackslashExprToken (org.develnext.jphp.core.tokenizer.token.expr.BackslashExprToken)1 ClassExprToken (org.develnext.jphp.core.tokenizer.token.expr.ClassExprToken)1 OperatorExprToken (org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken)1 AssignExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken)1 ImportExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.ImportExprToken)1 StaticAccessExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.StaticAccessExprToken)1