Search in sources :

Example 1 with IfStmtToken

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

the class TokenizerTest method testStmt.

@Test
public void testStmt() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("class function private public protected static final try catch for if foreach switch while " + "default return declare case do else elseif endif endfor endforeach endwhile endswitch " + "abstract use namespace finally extends implements global"));
    assertTrue(tokenizer.nextToken() instanceof ClassStmtToken);
    assertTrue(tokenizer.nextToken() instanceof FunctionStmtToken);
    assertTrue(tokenizer.nextToken() instanceof PrivateStmtToken);
    assertTrue(tokenizer.nextToken() instanceof PublicStmtToken);
    assertTrue(tokenizer.nextToken() instanceof ProtectedStmtToken);
    assertTrue(tokenizer.nextToken() instanceof StaticExprToken);
    assertTrue(tokenizer.nextToken() instanceof FinalStmtToken);
    assertTrue(tokenizer.nextToken() instanceof TryStmtToken);
    assertTrue(tokenizer.nextToken() instanceof CatchStmtToken);
    assertTrue(tokenizer.nextToken() instanceof ForStmtToken);
    assertTrue(tokenizer.nextToken() instanceof IfStmtToken);
    assertTrue(tokenizer.nextToken() instanceof ForeachStmtToken);
    assertTrue(tokenizer.nextToken() instanceof SwitchStmtToken);
    assertTrue(tokenizer.nextToken() instanceof WhileStmtToken);
    assertTrue(tokenizer.nextToken() instanceof DefaultStmtToken);
    assertTrue(tokenizer.nextToken() instanceof ReturnStmtToken);
    assertTrue(tokenizer.nextToken() instanceof DeclareStmtToken);
    assertTrue(tokenizer.nextToken() instanceof CaseStmtToken);
    assertTrue(tokenizer.nextToken() instanceof DoStmtToken);
    assertTrue(tokenizer.nextToken() instanceof ElseStmtToken);
    assertTrue(tokenizer.nextToken() instanceof ElseIfStmtToken);
    assertTrue(tokenizer.nextToken() instanceof EndifStmtToken);
    assertTrue(tokenizer.nextToken() instanceof EndforStmtToken);
    assertTrue(tokenizer.nextToken() instanceof EndforeachStmtToken);
    assertTrue(tokenizer.nextToken() instanceof EndwhileStmtToken);
    assertTrue(tokenizer.nextToken() instanceof EndswitchStmtToken);
    assertTrue(tokenizer.nextToken() instanceof AbstractStmtToken);
    assertTrue(tokenizer.nextToken() instanceof NamespaceUseStmtToken);
    assertTrue(tokenizer.nextToken() instanceof NamespaceStmtToken);
    assertTrue(tokenizer.nextToken() instanceof FinallyStmtToken);
    assertTrue(tokenizer.nextToken() instanceof ExtendsStmtToken);
    assertTrue(tokenizer.nextToken() instanceof ImplementsStmtToken);
    assertTrue(tokenizer.nextToken() instanceof GlobalStmtToken);
}
Also used : AbstractStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.AbstractStmtToken) ElseStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ElseStmtToken) StaticExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.StaticExprToken) EndforStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.EndforStmtToken) PublicStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.PublicStmtToken) CatchStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.CatchStmtToken) EndwhileStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.EndwhileStmtToken) ForeachStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ForeachStmtToken) ExtendsStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExtendsStmtToken) NamespaceUseStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.NamespaceUseStmtToken) FinallyStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FinallyStmtToken) EndifStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.EndifStmtToken) SwitchStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.SwitchStmtToken) ImplementsStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ImplementsStmtToken) FunctionStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) ForStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ForStmtToken) EndswitchStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.EndswitchStmtToken) Context(php.runtime.env.Context) ProtectedStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ProtectedStmtToken) ReturnStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ReturnStmtToken) DeclareStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.DeclareStmtToken) NamespaceStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.NamespaceStmtToken) TryStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.TryStmtToken) ElseIfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ElseIfStmtToken) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) EndforeachStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.EndforeachStmtToken) GlobalStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.GlobalStmtToken) WhileStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.WhileStmtToken) CaseStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.CaseStmtToken) ClassStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken) PrivateStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.PrivateStmtToken) FinalStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FinalStmtToken) DoStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.DoStmtToken) DefaultStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.DefaultStmtToken) ElseIfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ElseIfStmtToken) Test(org.junit.Test)

Example 2 with IfStmtToken

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

the class IfSyntaxTest method testShortly.

@Test
public void testShortly() {
    List<Token> tree = getSyntaxTree("if (true) 'string'; 123;");
    Assert.assertTrue(tree.size() == 2);
    Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
    IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
    Assert.assertNotNull(token.getBody());
    Assert.assertNotNull(token.getCondition());
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) Test(org.junit.Test)

Example 3 with IfStmtToken

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

the class IfSyntaxTest method testAlternative.

@Test
public void testAlternative() {
    List<Token> tree = getSyntaxTree("if (true): 123; endif");
    Assert.assertTrue(tree.size() == 1);
    Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
    IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
    Assert.assertNotNull(token.getBody());
    Assert.assertNotNull(token.getCondition());
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) Test(org.junit.Test)

Example 4 with IfStmtToken

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

the class IfSyntaxTest method testNested.

@Test
public void testNested() {
    List<Token> tree = getSyntaxTree("if (true){ " + "'string'; " + "if(false){ " + "1234; " + "} " + "}");
    Assert.assertTrue(tree.size() == 1);
    Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
    IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
    Assert.assertNotNull(token.getBody());
    Assert.assertTrue(token.getBody().getInstructions().size() == 2);
    Assert.assertTrue(token.getBody().getInstructions().get(1).getTokens().size() == 1);
    Assert.assertTrue(token.getBody().getInstructions().get(1).getTokens().get(0) instanceof IfStmtToken);
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) Test(org.junit.Test)

Example 5 with IfStmtToken

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

the class IfSyntaxTest method testSimple.

@Test
public void testSimple() {
    List<Token> tree = getSyntaxTree("if (true) { } ");
    Assert.assertTrue(tree.size() == 1);
    Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
    IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
    Assert.assertNotNull(token.getBody());
    Assert.assertNotNull(token.getCondition());
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) Test(org.junit.Test)

Aggregations

IfStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken)5 Test (org.junit.Test)5 Token (org.develnext.jphp.core.tokenizer.token.Token)4 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)4 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)1 StaticExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.StaticExprToken)1 AbstractStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.AbstractStmtToken)1 CaseStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.CaseStmtToken)1 CatchStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.CatchStmtToken)1 ClassStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken)1 DeclareStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.DeclareStmtToken)1 DefaultStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.DefaultStmtToken)1 DoStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.DoStmtToken)1 ElseIfStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ElseIfStmtToken)1 ElseStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ElseStmtToken)1 EndforStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.EndforStmtToken)1 EndforeachStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.EndforeachStmtToken)1 EndifStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.EndifStmtToken)1 EndswitchStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.EndswitchStmtToken)1 EndwhileStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.EndwhileStmtToken)1