Search in sources :

Example 1 with DoubleExprToken

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

the class TokenizerTest method testScalarTokens.

@Test
public void testScalarTokens() throws IOException {
    Token token;
    Tokenizer tokenizer = new Tokenizer(new Context("10 3.3 'foo' '' \"xyz\" 0xCC 0b0011 true false"));
    token = tokenizer.nextToken();
    assertTrue(token instanceof IntegerExprToken);
    assertEquals(10L, ((IntegerExprToken) token).getValue());
    token = tokenizer.nextToken();
    assertTrue(token instanceof DoubleExprToken);
    assertEquals(3.3, ((DoubleExprToken) token).getValue(), 0.01);
    token = tokenizer.nextToken();
    assertTrue(token instanceof StringExprToken);
    assertEquals(StringExprToken.Quote.SINGLE, ((StringExprToken) token).getQuote());
    assertEquals("foo", ((StringExprToken) token).getValue());
    token = tokenizer.nextToken();
    assertTrue(token instanceof StringExprToken);
    assertEquals(StringExprToken.Quote.SINGLE, ((StringExprToken) token).getQuote());
    assertEquals("", ((StringExprToken) token).getValue());
    token = tokenizer.nextToken();
    assertTrue(token instanceof StringExprToken);
    assertEquals(DOUBLE, ((StringExprToken) token).getQuote());
    assertEquals("xyz", ((StringExprToken) token).getValue());
    token = tokenizer.nextToken();
    assertTrue(token instanceof IntegerExprToken);
    assertEquals(new BigInteger("CC", 16).longValue(), ((IntegerExprToken) token).getValue());
    token = tokenizer.nextToken();
    assertTrue(token instanceof IntegerExprToken);
    assertEquals(new BigInteger("0011", 2).longValue(), ((IntegerExprToken) token).getValue());
    token = tokenizer.nextToken();
    assertTrue(token instanceof BooleanExprToken);
    assertEquals(true, ((BooleanExprToken) token).getValue());
    token = tokenizer.nextToken();
    assertTrue(token instanceof BooleanExprToken);
    assertEquals(false, ((BooleanExprToken) token).getValue());
    token = tokenizer.nextToken();
    assertNull(token);
}
Also used : Context(php.runtime.env.Context) DoubleExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.DoubleExprToken) IntegerExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.IntegerExprToken) BigInteger(java.math.BigInteger) 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) BooleanExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.BooleanExprToken) Test(org.junit.Test)

Example 2 with DoubleExprToken

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

the class TokenizerTest method testBraces.

@Test
public void testBraces() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context(" :: ->foobar('a', 1, 3.0);"));
    assertTrue(tokenizer.nextToken() instanceof StaticAccessExprToken);
    assertTrue(tokenizer.nextToken() instanceof DynamicAccessExprToken);
    assertTrue(tokenizer.nextToken() instanceof NameToken);
    assertTrue(tokenizer.nextToken() instanceof BraceExprToken);
    assertTrue(tokenizer.nextToken() instanceof StringExprToken);
    assertTrue(tokenizer.nextToken() instanceof CommaToken);
    assertTrue(tokenizer.nextToken() instanceof IntegerExprToken);
    assertTrue(tokenizer.nextToken() instanceof CommaToken);
    assertTrue(tokenizer.nextToken() instanceof DoubleExprToken);
    assertTrue(tokenizer.nextToken() instanceof BraceExprToken);
    assertTrue(tokenizer.nextToken() instanceof SemicolonToken);
}
Also used : Context(php.runtime.env.Context) CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) DoubleExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.DoubleExprToken) StaticAccessExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.StaticAccessExprToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) IntegerExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.IntegerExprToken) DynamicAccessExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.DynamicAccessExprToken) 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)

Aggregations

Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)2 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)2 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)2 CommaToken (org.develnext.jphp.core.tokenizer.token.expr.CommaToken)2 DynamicAccessExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.DynamicAccessExprToken)2 DoubleExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.DoubleExprToken)2 IntegerExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.IntegerExprToken)2 NameToken (org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)2 StaticAccessExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.StaticAccessExprToken)2 StringExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.StringExprToken)2 Test (org.junit.Test)2 Context (php.runtime.env.Context)2 BigInteger (java.math.BigInteger)1 CommentToken (org.develnext.jphp.core.tokenizer.token.CommentToken)1 Token (org.develnext.jphp.core.tokenizer.token.Token)1 DollarExprToken (org.develnext.jphp.core.tokenizer.token.expr.DollarExprToken)1 AssignExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken)1 BooleanAnd2ExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.BooleanAnd2ExprToken)1 BooleanAndExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.BooleanAndExprToken)1 BooleanNotEqualExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.BooleanNotEqualExprToken)1