Search in sources :

Example 11 with Token

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

the class NamespaceSyntaxTest method testLongName.

@Test
public void testLongName() {
    List<Token> tree = getSyntaxTree("namespace A\\B\\C;");
    Assert.assertTrue(tree.size() == 1);
    Assert.assertTrue(tree.get(0) instanceof NamespaceStmtToken);
    NamespaceStmtToken token = (NamespaceStmtToken) tree.get(0);
    Assert.assertNull(token.getTree());
    Assert.assertEquals("A\\B\\C", token.getName().toName());
}
Also used : NamespaceStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.NamespaceStmtToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) NamespaceStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.NamespaceStmtToken) Test(org.junit.Test)

Example 12 with Token

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

the class SimpleExprTest method testSimpleCall.

@Test
public void testSimpleCall() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("myCall(1 * 2, func(3, 2), 4);"));
    SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
    List<Token> tokens = analyzer.getTree();
    Assert.assertTrue(tokens.size() == 1);
    Assert.assertTrue(tokens.get(0) instanceof ExprStmtToken);
    ExprStmtToken expr = (ExprStmtToken) tokens.get(0);
    tokens = expr.getTokens();
    Assert.assertTrue(tokens.size() == 1);
    Assert.assertTrue(tokens.get(0) instanceof CallExprToken);
    CallExprToken call = (CallExprToken) expr.getTokens().get(0);
    Assert.assertTrue(call.getName() instanceof NameToken);
    Assert.assertEquals("myCall", ((NameToken) call.getName()).getName());
    Assert.assertTrue(call.getParameters().size() == 3);
    Assert.assertTrue(call.getParameters().get(0).getTokens().size() == 3);
    Assert.assertTrue(call.getParameters().get(2).getTokens().size() == 1);
    ExprStmtToken param = call.getParameters().get(1);
    Assert.assertTrue(param.getTokens().size() == 1);
    Assert.assertTrue(param.getTokens().get(0) instanceof CallExprToken);
    CallExprToken subCall = (CallExprToken) param.getTokens().get(0);
    Assert.assertTrue(subCall.getParameters().size() == 2);
}
Also used : Context(php.runtime.env.Context) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) ValueIfElseToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) MinusExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 13 with Token

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

the class SimpleExprTest method testIfElse.

@Test
public void testIfElse() {
    List<Token> tokens = getSyntaxTree("call(1, true ? 1 : 2, 'foobar');");
    Assert.assertEquals(1, tokens.size());
    Assert.assertTrue(tokens.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tokens.get(0)).getLast() instanceof CallExprToken);
    CallExprToken call = (CallExprToken) ((ExprStmtToken) tokens.get(0)).getLast();
    Assert.assertEquals(3, call.getParameters().size());
    Assert.assertTrue(call.getParameters().get(0).getSingle() instanceof IntegerExprToken);
    Assert.assertTrue(call.getParameters().get(1).getTokens().get(1) instanceof ValueIfElseToken);
    ValueIfElseToken ifElse = (ValueIfElseToken) call.getParameters().get(1).getTokens().get(1);
    Assert.assertTrue(ifElse.getValue().getSingle() instanceof IntegerExprToken);
    Assert.assertTrue(ifElse.getAlternative().getSingle() instanceof IntegerExprToken);
    Assert.assertTrue(call.getParameters().get(2).getSingle() instanceof StringExprToken);
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ValueIfElseToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken) Token(org.develnext.jphp.core.tokenizer.token.Token) ValueIfElseToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) MinusExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken) Test(org.junit.Test)

Example 14 with Token

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

the class Generator method checkUnexpectedEnd.

protected void checkUnexpectedEnd(ListIterator<Token> iterator) {
    if (!iterator.hasNext()) {
        iterator.previous();
        Token current = iterator.next();
        analyzer.getEnvironment().error(current.toTraceInfo(analyzer.getContext()), ErrorType.E_PARSE, Messages.ERR_PARSE_UNEXPECTED_END_OF_FILE);
    }
}
Also used : CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) BreakToken(org.develnext.jphp.core.tokenizer.token.BreakToken) Token(org.develnext.jphp.core.tokenizer.token.Token) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken)

Example 15 with Token

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

the class Generator method nextToken.

protected Token nextToken(ListIterator<Token> iterator) {
    checkUnexpectedEnd(iterator);
    Token tk = iterator.next();
    if (tk instanceof CommentToken) {
        return nextToken(iterator);
    }
    return tk;
}
Also used : CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) BreakToken(org.develnext.jphp.core.tokenizer.token.BreakToken) Token(org.develnext.jphp.core.tokenizer.token.Token) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken)

Aggregations

Token (org.develnext.jphp.core.tokenizer.token.Token)93 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)47 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)39 CommentToken (org.develnext.jphp.core.tokenizer.token.CommentToken)37 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)27 CommaToken (org.develnext.jphp.core.tokenizer.token.expr.CommaToken)26 BreakToken (org.develnext.jphp.core.tokenizer.token.BreakToken)25 AssignExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken)25 Test (org.junit.Test)24 ColonToken (org.develnext.jphp.core.tokenizer.token.ColonToken)22 NameToken (org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)21 ValueIfElseToken (org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken)19 CastExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.cast.CastExprToken)16 UnsetCastExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.cast.UnsetCastExprToken)16 MacroToken (org.develnext.jphp.core.tokenizer.token.expr.value.macro.MacroToken)16 StringExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.StringExprToken)14 VariableExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken)14 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)13 MinusExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken)12 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)12