Search in sources :

Example 21 with Tokenizer

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

the class TokenizerTest method testStringSlashes.

@Test
public void testStringSlashes() throws IOException {
    Token token;
    Tokenizer tokenizer = new Tokenizer(new Context(" 'foo\\'bar' \"foo\\\"bar\""));
    token = tokenizer.nextToken();
    assertTrue(token instanceof StringExprToken);
    assertEquals("foo'bar", ((StringExprToken) token).getValue());
    token = tokenizer.nextToken();
    assertTrue(token instanceof StringExprToken);
    assertEquals("foo\"bar", ((StringExprToken) token).getValue());
}
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 22 with Tokenizer

use of org.develnext.jphp.core.tokenizer.Tokenizer 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 23 with Tokenizer

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

the class JvmCompilerCase method getSyntaxTree.

protected List<Token> getSyntaxTree(Context context) {
    Tokenizer tokenizer = null;
    try {
        tokenizer = new Tokenizer(context);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
    return analyzer.getTree();
}
Also used : SyntaxAnalyzer(org.develnext.jphp.core.syntax.SyntaxAnalyzer) IOException(java.io.IOException) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer)

Example 24 with Tokenizer

use of org.develnext.jphp.core.tokenizer.Tokenizer 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 25 with Tokenizer

use of org.develnext.jphp.core.tokenizer.Tokenizer 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)

Aggregations

Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)30 Context (php.runtime.env.Context)27 Test (org.junit.Test)23 Token (org.develnext.jphp.core.tokenizer.token.Token)11 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)9 CommentToken (org.develnext.jphp.core.tokenizer.token.CommentToken)8 SyntaxAnalyzer (org.develnext.jphp.core.syntax.SyntaxAnalyzer)6 IOException (java.io.IOException)4 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)4 FunctionStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken)3 ParseException (php.runtime.exceptions.ParseException)3 TraceInfo (php.runtime.env.TraceInfo)2 File (java.io.File)1 BigInteger (java.math.BigInteger)1 JvmCompiler (org.develnext.jphp.core.compiler.jvm.JvmCompiler)1 TokenMeta (org.develnext.jphp.core.tokenizer.TokenMeta)1 BreakToken (org.develnext.jphp.core.tokenizer.token.BreakToken)1 ColonToken (org.develnext.jphp.core.tokenizer.token.ColonToken)1 MinusExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken)1 ValueIfElseToken (org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken)1