Search in sources :

Example 6 with CommentToken

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

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

the class ClassGenerator method processDefine.

@SuppressWarnings("unchecked")
protected ClassStmtToken processDefine(Token current, ListIterator<Token> iterator) {
    ClassStmtToken result = null;
    if (isTokenClass(current, FinalStmtToken.class, AbstractStmtToken.class)) {
        Token next = nextToken(iterator);
        if (next instanceof ClassStmtToken) {
            result = (ClassStmtToken) next;
            result.setInterface(false);
            result.setAbstract(current instanceof AbstractStmtToken);
            result.setFinal(current instanceof FinalStmtToken);
        //return result;
        } else if (next instanceof InterfaceStmtToken || next instanceof TraitStmtToken) {
            unexpectedToken(current);
        } else if (next instanceof AbstractStmtToken || next instanceof FinalStmtToken) {
            unexpectedToken(next);
        } else {
            iterator.previous();
        }
    }
    if (current instanceof ClassStmtToken)
        result = (ClassStmtToken) current;
    else if (current instanceof InterfaceStmtToken) {
        result = new ClassStmtToken(current.getMeta());
        result.setInterface(true);
    } else if (current instanceof TraitStmtToken) {
        result = new ClassStmtToken(current.getMeta());
        result.setClassType(ClassEntity.Type.TRAIT);
    }
    if (result != null) {
        iterator.previous();
        if (result.isFinal() || result.isAbstract())
            iterator.previous();
        if (iterator.hasPrevious()) {
            Token tk = iterator.previous();
            if (tk instanceof CommentToken) {
                result.setDocComment((CommentToken) tk);
            }
            iterator.next();
        }
        if (result.isFinal() || result.isAbstract())
            iterator.next();
        iterator.next();
    }
    return result;
}
Also used : CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) Token(org.develnext.jphp.core.tokenizer.token.Token) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken)

Example 8 with CommentToken

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

Aggregations

CommentToken (org.develnext.jphp.core.tokenizer.token.CommentToken)8 Token (org.develnext.jphp.core.tokenizer.token.Token)8 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)6 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)5 CommaToken (org.develnext.jphp.core.tokenizer.token.expr.CommaToken)3 AssignExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken)3 NameToken (org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)3 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)2 BreakToken (org.develnext.jphp.core.tokenizer.token.BreakToken)2 Test (org.junit.Test)2 Context (php.runtime.env.Context)2 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)1 AmpersandRefToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AmpersandRefToken)1 ArgumentUnpackExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.ArgumentUnpackExprToken)1 ClosureStmtToken (org.develnext.jphp.core.tokenizer.token.expr.value.ClosureStmtToken)1 FulledNameToken (org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken)1