Search in sources :

Example 6 with Context

use of php.runtime.env.Context in project jphp by jphp-compiler.

the class TokenizerTest method testComments.

@Test
public void testComments() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("/** FOO BAR \n\r100500 */"));
    Token token = tokenizer.nextToken();
    assertTrue(token instanceof CommentToken);
    assertEquals(CommentToken.Kind.DOCTYPE, ((CommentToken) token).getKind());
    assertEquals("FOO BAR\n\n100500", ((CommentToken) token).getComment());
    // simple
    tokenizer = new Tokenizer(new Context("// foobar \n $x"));
    token = tokenizer.nextToken();
    assertTrue(token instanceof CommentToken);
    assertEquals(CommentToken.Kind.SIMPLE, ((CommentToken) token).getKind());
    assertEquals(" foobar ", ((CommentToken) token).getComment());
    assertTrue(tokenizer.nextToken() instanceof VariableExprToken);
    assertNull(tokenizer.nextToken());
    tokenizer = new Tokenizer(new Context("# // foobar \n $x"));
    token = tokenizer.nextToken();
    assertTrue(token instanceof CommentToken);
    assertEquals(CommentToken.Kind.SIMPLE, ((CommentToken) token).getKind());
    assertEquals(" // foobar ", ((CommentToken) token).getComment());
    assertTrue(tokenizer.nextToken() instanceof VariableExprToken);
    assertNull(tokenizer.nextToken());
    // block
    tokenizer = new Tokenizer(new Context("/* foobar \n */"));
    token = tokenizer.nextToken();
    assertTrue(token instanceof CommentToken);
    assertEquals(CommentToken.Kind.BLOCK, ((CommentToken) token).getKind());
}
Also used : Context(php.runtime.env.Context) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) Token(org.develnext.jphp.core.tokenizer.token.Token) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 7 with Context

use of php.runtime.env.Context in project jphp by jphp-compiler.

the class TokenizerTest method testComplexOperators.

@Test
public void testComplexOperators() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("== >= <= === !== != && ||"));
    assertTrue(tokenizer.nextToken() instanceof EqualExprToken);
    assertTrue(tokenizer.nextToken() instanceof GreaterOrEqualExprToken);
    assertTrue(tokenizer.nextToken() instanceof SmallerOrEqualToken);
    assertTrue(tokenizer.nextToken() instanceof IdenticalExprToken);
    assertTrue(tokenizer.nextToken() instanceof NotIdenticalExprToken);
    assertTrue(tokenizer.nextToken() instanceof BooleanNotEqualExprToken);
    assertTrue(tokenizer.nextToken() instanceof BooleanAndExprToken);
    assertTrue(tokenizer.nextToken() instanceof BooleanOrExprToken);
}
Also used : Context(php.runtime.env.Context) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 8 with Context

use of php.runtime.env.Context in project jphp by jphp-compiler.

the class TokenizerTest method testParseError.

@Test
public void testParseError() throws IOException {
    Throwable ex = null;
    Tokenizer tokenizer = new Tokenizer(new Context("  'foobar \n "));
    try {
        tokenizer.nextToken();
    } catch (Throwable e) {
        ex = e;
    }
    assertTrue(ex instanceof ParseException);
    TraceInfo traceInfo = ((ParseException) ex).getTraceInfo();
    assertNotNull(traceInfo);
    assertNull(traceInfo.getContext().getFileName());
    assertEquals(1, traceInfo.getStartLine());
    assertEquals(1, traceInfo.getEndLine());
    assertEquals(1, traceInfo.getStartPosition());
    assertEquals(1, traceInfo.getEndPosition());
}
Also used : Context(php.runtime.env.Context) ParseException(php.runtime.exceptions.ParseException) TraceInfo(php.runtime.env.TraceInfo) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 9 with Context

use of php.runtime.env.Context in project jphp by jphp-compiler.

the class TokenizerTest method testSplitNot.

@Test
public void testSplitNot() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("!true"));
    assertTrue(tokenizer.nextToken() instanceof BooleanNotExprToken);
    assertTrue(tokenizer.nextToken() instanceof BooleanExprToken);
}
Also used : Context(php.runtime.env.Context) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 10 with Context

use of php.runtime.env.Context in project jphp by jphp-compiler.

the class TokenizerTest method testComplex.

@Test
public void testComplex() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("0==10==='30';"));
    assertTrue(tokenizer.nextToken() instanceof IntegerExprToken);
    assertTrue(tokenizer.nextToken() instanceof EqualExprToken);
    assertTrue(tokenizer.nextToken() instanceof IntegerExprToken);
    assertTrue(tokenizer.nextToken() instanceof IdenticalExprToken);
    assertTrue(tokenizer.nextToken() instanceof StringExprToken);
    assertTrue(tokenizer.nextToken() instanceof SemicolonToken);
    tokenizer = new Tokenizer(new Context("F =; 20;"));
    Token token;
    assertTrue((token = tokenizer.nextToken()) instanceof NameToken);
    assertEquals("F", ((NameToken) token).getName());
    assertTrue(tokenizer.nextToken() instanceof AssignExprToken);
    assertTrue(tokenizer.nextToken() instanceof SemicolonToken);
    assertTrue(tokenizer.nextToken() instanceof IntegerExprToken);
    assertTrue(tokenizer.nextToken() instanceof SemicolonToken);
    tokenizer = new Tokenizer(new Context("123foobar MAX_64Bit"));
    token = tokenizer.nextToken();
    assertTrue(token instanceof IntegerExprToken);
    token = tokenizer.nextToken();
    assertTrue(token instanceof NameToken);
    assertEquals("foobar", token.getWord());
    assertTrue(tokenizer.nextToken() instanceof NameToken);
    assertNull(tokenizer.nextToken());
    assertNull(tokenizer.nextToken());
}
Also used : Context(php.runtime.env.Context) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) Token(org.develnext.jphp.core.tokenizer.token.Token) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Aggregations

Context (php.runtime.env.Context)30 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)27 Test (org.junit.Test)23 Token (org.develnext.jphp.core.tokenizer.token.Token)10 CommentToken (org.develnext.jphp.core.tokenizer.token.CommentToken)8 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)8 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)4 File (java.io.File)3 IOException (java.io.IOException)3 SyntaxAnalyzer (org.develnext.jphp.core.syntax.SyntaxAnalyzer)3 FunctionStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken)3 ModuleEntity (php.runtime.reflection.ModuleEntity)3 Environment (php.runtime.env.Environment)2 ParseException (php.runtime.exceptions.ParseException)2 Launcher (php.runtime.launcher.Launcher)2 DataInputStream (java.io.DataInputStream)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 JvmCompiler (org.develnext.jphp.core.compiler.jvm.JvmCompiler)1 MinusExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken)1