Are there any alternatives for Java Makefile Parser library?
I might need a Java library to parse make files in order to extract some information or even simulate execution in given environment. A quick look up suggests that there is only the Java Makefile Parser. But maybe I didn't look in the right places. So is there any other library?
Note that I'm not stating that there is anything wrong with Java Makefile Parser. I haven't even tried it yet. I only want to know my options.
Working on a code generation tool to help creating boiler code for our project.
The generator is written in ruby with erb templates, the project itself is in Java.
Now I am looking for a ruby gem/library for parsing java source files, given a string from a .java files, get the imports, methods, fields, class name etc etc, that would enable me to navigate to a certain method and appending code to it etc (kinda like jQuery selector).
I am wondering if there are already solutions that I can use, kinda like the javaclass-rb library, but that is for parsing bytecodes from .class files.
I know I could use ANTLR and a ruby adapter, but I hope there are existing solutions.
Thanks!
JRuby is a Ruby implementation on top of the JVM that make interaction between Ruby and Java objects trivial. If you decide to use this, you can use any Java library to solve the task, like javaparser.
I wish to create a app that translates input java code into HTML formatted java code,
For example:
public class ReadWithScanner
Would become
<span class="public">public</span> <span class="class">class</span> ReadWithScanner
However it gets quite complicated when it comes to parameters and regular expressions. Now I have a bit of time on my hands, and I wish to write my own code parser.
How would I start this? and is there any tutorials or online content to not only help me write this, but understand it.
Thanks
For help with the complexity of parsing, you'll need to rely on the Java Language Specification.
As I seem to recall, Java is an LL(k) language (see here, for instance). However, the Java language, despite all attempts to keep it "compact", is still quite large and complex. The grammar is spread out over the entire document. This is not a project for the faint at heart. You might consider using a Java parsing tool (like Java-front).
What you need to do is use ANTLR, it already has Java grammars for parsing Java, then you just need to supply your own templates to output whatever you want from the Abstract Syntax Tree you generate with ANTLR.
If you need a resource for learning about parsers, I can recommend Basics of Compiler Design, which is available as a free download.
It covers more than just parsers, but if you read the first few chapters, you should have a good basic understanding of both lexers and parsers.
I think you need a lexical analyzer.
I used early the Flex lexical analyzer. It is not too complicated to use.
If you need to parse the analyzed text you can use the bison c++
bisoncpp.sourceforge.net/
(C++ konwledge need and linux environment)
The project I'm doing is written in Java and parsers source code files. (Java src up to now). Now I'd like to enable parsing Ruby code as well.
Therefore I am looking for a parser in Java that parses Ruby source code.
The only thing I have been able to find up to now are Ruby parsers in Ruby (ParseTree and RubyParser...).
I could maybe parse the source files I want with a Ruby parser in JRuby, and then access my Java stuff from there.
But that would mean that I will not be able to reuse a lot of my previously written Java code.
Is there a decent Ruby parser in Java out there and have I just not be able to find it? Or does someone see a better solution?
See http://kenai.com/projects/jruby-parser/
You could let ANTLR generate a lexer/parser for you. They have a simplified Ruby grammar available: http://www.antlr.org/grammar/1160820213459/rubyParserLexerSPGrammar.g which may be sufficient for your needs.
As you know there is a Syntax highlighter for PHP called GeSHi which supports a great number of Programming Languages or Code formats.
However, I couldn't find such a library for Java which supports programming languages that I need (ADA, ASP, BNF, Bash, Brainfuck, C, C++, C#, CSS, Cobol, ColdFusion, D, Fortran, Haskell, HTML, INI (Config), Java, JavaScript, Lisp, Make, Objective C, PASCAL, Perl, PHP, PLSQL, Prolog, Python, Ruby, Scheme, SQL, VB.NET, Verilog, VHDL, Visual Basic, XML.)
Do you know one or should I prefer inefficient way which is retrieving the highlighted code from a remote PHP server via http transaction? Any ideas?
Thanks.
Two related questions:
What code highlighting libs are there for Java?
Where can I find a syntax highlighting library for Java?
And one library I found: http://colorer.sourceforge.net/
Have a look at JHighlighter or jEdit Syntax Package. All mentioned languages aren't supported out of the box. However, you have the sources, so I guess it should be possible to add language support.
Not a direct answer but, if client-side syntax highlighting is an option, the SyntaxHighlighter library from Alex Gorbatchev is an awesome javascript library, supports lots of languages and is highly extensible.
You could use Pygments through Jython. Won't be as fast as a Java solution, but much faster than interacting with a remote server.
Barring that, you could run Geshi locally and pipe source code through it, that would also beat an HTTP round trip.
It seems that it is possible to run GeSHi from Java: GeSHi4J it seems to be a wrapper that run the PHP library on the JVM.
There is a port of prettify.js for Java: java-prettify.
It can be used to produce HTML (computed in Java), as I discussed here:
Use the java-prettify parser to create HTML
jedit is a text editor with syntax highlighting support for some 170+ languages via "modes". It also allows you to specify your own syntaxes. You can use the StandaloneTextArea component in your own application as follows:
Extract source (eg: jedit4.3source.tar.bz2 to d:\source\jedit)
Use ant to copy all the textarea files to ..\textarea eg:
D:\Source\jedit\jEdit> ant prepare-textArea
However, it misses the file BufferUndoListener.java. Copy this manually by executing
D:\Source\jedit\jEdit> copy org\gjt\sp\jedit\buffer\BufferUndoListener.java ..\textarea\src\org\gjt\sp\jedit\buffer\
In Eclipse create a Java Project from existing source in the directory D:\Source\jedit\textarea
Navigate to org.gjt.sp.jedit.textarea.StandaloneTextArea.java
Change the line
mode.setProperty("file","modes/xml.xml");
to
mode.setProperty("file","src/modes/xml.xml");
Run. Copy and paste an XML into the editor and see the syntax highlighting is working.