Search in sources :

Example 6 with BraceExprToken

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

the class TokenizerTest method testVarVar.

@Test
public void testVarVar() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("$$foo $ $bar $$$foobar"));
    assertTrue(tokenizer.nextToken() instanceof DollarExprToken);
    assertTrue(tokenizer.nextToken() instanceof VariableExprToken);
    assertTrue(tokenizer.nextToken() instanceof DollarExprToken);
    assertTrue(tokenizer.nextToken() instanceof VariableExprToken);
    assertTrue(tokenizer.nextToken() instanceof DollarExprToken);
    assertTrue(tokenizer.nextToken() instanceof DollarExprToken);
    assertTrue(tokenizer.nextToken() instanceof VariableExprToken);
    tokenizer = new Tokenizer(new Context("${'foo;6bar'}"));
    assertTrue(tokenizer.nextToken() instanceof DollarExprToken);
    assertTrue(tokenizer.nextToken() instanceof BraceExprToken);
    assertTrue(tokenizer.nextToken() instanceof StringExprToken);
    assertTrue(tokenizer.nextToken() instanceof BraceExprToken);
}
Also used : Context(php.runtime.env.Context) DollarExprToken(org.develnext.jphp.core.tokenizer.token.expr.DollarExprToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) VariableExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) StringExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.StringExprToken) Test(org.junit.Test)

Example 7 with BraceExprToken

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

the class TokenizerTest method testHeredoc.

@Test
public void testHeredoc() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("<<<DOC\n <foobar> \nDOC;\n"));
    Token token = tokenizer.nextToken();
    assertTrue(token instanceof StringExprToken);
    assertEquals(StringExprToken.Quote.DOC, ((StringExprToken) token).getQuote());
    assertEquals(" <foobar> ", ((StringExprToken) token).getValue());
    tokenizer = new Tokenizer(new Context("<<<\"DOC\"\n \\n<foobar> \nDOC;\n"));
    token = tokenizer.nextToken();
    assertTrue(token instanceof StringExprToken);
    assertEquals(StringExprToken.Quote.DOC, ((StringExprToken) token).getQuote());
    assertEquals(" \n<foobar> ", ((StringExprToken) token).getValue());
    tokenizer = new Tokenizer(new Context("<<<'DOC'\n \\n<foobar> \nDOC;\n"));
    token = tokenizer.nextToken();
    assertTrue(token instanceof StringExprToken);
    assertEquals(StringExprToken.Quote.DOC, ((StringExprToken) token).getQuote());
    assertEquals(" \\n<foobar> ", ((StringExprToken) token).getValue());
    tokenizer = new Tokenizer(new Context("a(<<<DOC\n<foobar>\nDOC\n)\n"));
    token = tokenizer.nextToken();
    assertTrue(token instanceof NameToken);
    token = tokenizer.nextToken();
    assertTrue(token instanceof BraceExprToken);
    token = tokenizer.nextToken();
    assertTrue(token instanceof StringExprToken);
    assertEquals(StringExprToken.Quote.DOC, ((StringExprToken) token).getQuote());
    assertEquals("<foobar>", ((StringExprToken) token).getValue());
}
Also used : Context(php.runtime.env.Context) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) StaticAccessExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.StaticAccessExprToken) GlobalStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.GlobalStmtToken) DefaultStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.DefaultStmtToken) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) DirMacroToken(org.develnext.jphp.core.tokenizer.token.expr.value.macro.DirMacroToken) NamespaceStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.NamespaceStmtToken) PowExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.PowExprToken) IdenticalExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.IdenticalExprToken) ModExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ModExprToken) MulExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.MulExprToken) DoStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.DoStmtToken) FunctionMacroToken(org.develnext.jphp.core.tokenizer.token.expr.value.macro.FunctionMacroToken) EqualExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.EqualExprToken) EndswitchStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.EndswitchStmtToken) ReturnStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ReturnStmtToken) PlusExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.PlusExprToken) ForStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ForStmtToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) ProtectedStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ProtectedStmtToken) EndwhileStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.EndwhileStmtToken) StaticExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.StaticExprToken) DollarExprToken(org.develnext.jphp.core.tokenizer.token.expr.DollarExprToken) ForeachStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ForeachStmtToken) VariableExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken) TraitMacroToken(org.develnext.jphp.core.tokenizer.token.expr.value.macro.TraitMacroToken) AbstractStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.AbstractStmtToken) FinallyStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FinallyStmtToken) CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) CatchStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.CatchStmtToken) EndifStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.EndifStmtToken) ClassMacroToken(org.develnext.jphp.core.tokenizer.token.expr.value.macro.ClassMacroToken) ConcatExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ConcatExprToken) BooleanExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.BooleanExprToken) TryStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.TryStmtToken) DynamicAccessExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.DynamicAccessExprToken) BooleanAndExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.BooleanAndExprToken) FunctionStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken) BooleanNotExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.BooleanNotExprToken) NotIdenticalExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.NotIdenticalExprToken) FinalStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FinalStmtToken) DoubleExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.DoubleExprToken) ElseIfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ElseIfStmtToken) MinusExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken) BooleanXorExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.BooleanXorExprToken) ImplementsStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ImplementsStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) NamespaceMacroToken(org.develnext.jphp.core.tokenizer.token.expr.value.macro.NamespaceMacroToken) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) PublicStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.PublicStmtToken) BooleanNotEqualExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.BooleanNotEqualExprToken) EndforStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.EndforStmtToken) SmallerOrEqualToken(org.develnext.jphp.core.tokenizer.token.expr.operator.SmallerOrEqualToken) SwitchStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.SwitchStmtToken) BooleanAnd2ExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.BooleanAnd2ExprToken) MethodMacroToken(org.develnext.jphp.core.tokenizer.token.expr.value.macro.MethodMacroToken) ElseStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ElseStmtToken) BooleanOrExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.BooleanOrExprToken) IntegerExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.IntegerExprToken) DeclareStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.DeclareStmtToken) LineMacroToken(org.develnext.jphp.core.tokenizer.token.expr.value.macro.LineMacroToken) ClassStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken) FileMacroToken(org.develnext.jphp.core.tokenizer.token.expr.value.macro.FileMacroToken) BooleanOr2ExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.BooleanOr2ExprToken) WhileStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.WhileStmtToken) ExtendsStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExtendsStmtToken) GreaterOrEqualExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.GreaterOrEqualExprToken) PrivateStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.PrivateStmtToken) EndforeachStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.EndforeachStmtToken) NamespaceUseStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.NamespaceUseStmtToken) StringExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.StringExprToken) DivExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.DivExprToken) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken) NewExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.NewExprToken) CaseStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.CaseStmtToken) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) StringExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.StringExprToken) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken) Test(org.junit.Test)

Example 8 with BraceExprToken

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

the class DeclareGenerator method getToken.

@Override
public DeclareStmtToken getToken(Token current, ListIterator<Token> iterator) {
    if (current instanceof DeclareStmtToken) {
        BraceExprToken token = nextAndExpected(iterator, BraceExprToken.class);
        if (!isOpenedBrace(token, BraceExprToken.Kind.SIMPLE)) {
            unexpectedToken(token, "(");
        }
        NameToken nameToken = nextAndExpected(iterator, NameToken.class);
        nextAndExpected(iterator, AssignExprToken.class);
        ExprStmtToken value = analyzer.generator(ExprGenerator.class).getInBraces(BraceExprToken.Kind.SIMPLE, iterator, true);
        if (!value.isConstantly()) {
            unexpectedToken(value, "constant value");
        }
        DeclareStmtToken result = (DeclareStmtToken) current;
        result.setName(nameToken);
        result.setValue(value);
        return result;
    }
    return null;
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) DeclareStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.DeclareStmtToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)

Example 9 with BraceExprToken

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

the class ASMExpression method processOperator.

protected void processOperator(Stack<Token> stack, List<Token> result, OperatorExprToken current) {
    List<Token> list = new ArrayList<Token>();
    boolean isRightOperator = current != null && current.isRightSide();
    int prior = current == null ? -1 : current.getPriority();
    while (!stack.empty()) {
        Token el = stack.peek();
        int elPrior = getPriority(el);
        if (el instanceof BraceExprToken)
            break;
        if (current != null && current.getAssociation() == Association.RIGHT && !current.isBinary() && prev instanceof OperatorExprToken)
            break;
        boolean flush = current == null || elPrior == 1 || (isRightOperator ? elPrior > prior : elPrior <= prior);
        if (flush) {
            stack.pop();
            list.add(el);
        } else {
            break;
        }
    }
    result.addAll(list);
}
Also used : BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) ArrayList(java.util.ArrayList) OperatorExprToken(org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken) Token(org.develnext.jphp.core.tokenizer.token.Token) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ExprToken(org.develnext.jphp.core.tokenizer.token.expr.ExprToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) OperatorExprToken(org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken) CallExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.CallExprToken)

Aggregations

BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)9 Token (org.develnext.jphp.core.tokenizer.token.Token)6 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)5 CommaToken (org.develnext.jphp.core.tokenizer.token.expr.CommaToken)5 CommentToken (org.develnext.jphp.core.tokenizer.token.CommentToken)4 AssignExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken)4 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)3 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)3 ValueIfElseToken (org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken)3 NameToken (org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)3 StringExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.StringExprToken)3 Test (org.junit.Test)3 Context (php.runtime.env.Context)3 ColonToken (org.develnext.jphp.core.tokenizer.token.ColonToken)2 DollarExprToken (org.develnext.jphp.core.tokenizer.token.expr.DollarExprToken)2 ExprToken (org.develnext.jphp.core.tokenizer.token.expr.ExprToken)2 OperatorExprToken (org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken)2 AmpersandRefToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AmpersandRefToken)2 ArgumentUnpackExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.ArgumentUnpackExprToken)2 DynamicAccessExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.DynamicAccessExprToken)2