Search in sources :

Example 21 with Context

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

the class TokenizerTest method testSimple.

@Test
public void testSimple() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context(""));
    assertNull(tokenizer.nextToken());
    assertEquals("", tokenizer.getCode());
    tokenizer = new Tokenizer(new Context(" "));
    assertNull(tokenizer.nextToken());
    tokenizer = new Tokenizer(new Context("  "));
    assertNull(tokenizer.nextToken());
    tokenizer = new Tokenizer(new Context("\t"));
    assertNull(tokenizer.nextToken());
    tokenizer = new Tokenizer(new Context("\n"));
    assertNull(tokenizer.nextToken());
    tokenizer = new Tokenizer(new Context("\r"));
    assertNull(tokenizer.nextToken());
}
Also used : Context(php.runtime.env.Context) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 22 with Context

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

the class CommentsTest method testBug154.

@Test
public void testBug154() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("/*// */"));
    Token token = tokenizer.nextToken();
    assertTrue(token instanceof CommentToken);
    assertEquals(CommentToken.Kind.BLOCK, ((CommentToken) token).getKind());
    assertEquals("// ", ((CommentToken) token).getComment());
}
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) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 23 with Context

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

the class TokenizerTest method testMagicString.

@Test
public void testMagicString() throws IOException {
    Token token;
    Tokenizer tokenizer = new Tokenizer(new Context("\"\\.{$foo}\""));
    token = tokenizer.nextToken();
    assertTrue(token instanceof StringExprToken);
    assertEquals(".{$foo}", ((StringExprToken) token).getValue());
    assertEquals(1, ((StringExprToken) token).getSegments().size());
    StringExprToken.Segment segment = ((StringExprToken) token).getSegments().get(0);
    assertEquals(1, segment.from);
    assertEquals(7, segment.to);
}
Also used : Context(php.runtime.env.Context) 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 24 with Context

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

the class SyntaxAnalyzerTest method testUnexpectedEnd.

@Test(expected = ErrorException.class)
public void testUnexpectedEnd() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("foobar"));
    environment.scope.setLangMode(LangMode.DEFAULT);
    new SyntaxAnalyzer(environment, tokenizer);
}
Also used : Context(php.runtime.env.Context) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 25 with Context

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

the class AbstractSyntaxTestCase method getSyntaxTree.

protected List<Token> getSyntaxTree(String code) {
    Tokenizer tokenizer = null;
    try {
        tokenizer = new Tokenizer(new Context(code));
        environment.scope.setLangMode(LangMode.DEFAULT);
        SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
        return analyzer.getTree();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Context(php.runtime.env.Context) IOException(java.io.IOException) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer)

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