1

Is there any Java alternative to PHP Tokenizer?

http://php.net/manual/en/book.tokenizer.php

Edit: I mean Java class that parses Java like PHP Tokenizer parses PHP.

3
  • 3
    Meaning a Java class that parses PHP? Or a Java class that parses Java? Commented Dec 9, 2012 at 13:09
  • Java class that parses Java. Commented Dec 9, 2012 at 13:10
  • Your question could be improved by including a short description of the documentation you are linking to, and perhaps a little detail on what problem you are trying to solve. Commented Dec 9, 2012 at 13:10

1 Answer 1

3

I quickly scanned the documentation you linked to. It looks like functionality for parsing PHP code.

If that is indeed what you are looking for, you might find the JavaParser project useful. It contains functionality for parsing Java source code.

This page contains some usage examples.

Sign up to request clarification or add additional context in comments.

5 Comments

Look at one of the examples on the page.
An explanation of the downvote would be very much appreciated.
Just to add some information to @Henrik answer: JavaParser project gives an API through a Visitor Pattern that allows to move through the AST of a Java Class. In my opinion, the only feature missing (currently), is that the AST parsing leaves comments (non-javadoc) out, either they are single line or multiline. Voting up for valuable information.
@pabrantes: Great addition. I also miss the ability to parse any type of Java code, not just entire classes, e.g. a method or an expression.
@Henrik: In my case I always have a full class to parse, so it's not a real problem, but I do agree with you that being able to parse any java expression would be a great feature!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.