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.
Related
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.
I need to extract from c/c++ source code files, function/class/macro names and their locations in their files. I need to do this in java and over a lot of files (~100/150). How can I do this?
So basically I need something similar to ctags but in java.
The easiest thing to do would probably be to write a Java Native Interface wrapper for ctags!
You could also look at finding a C++ parser in Java. Maybe abduct the parser Eclipse uses for syntax highlighting. Writing your own parser will be extremely painful since it's not a LALR grammar (I know this from experience).
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'm looking for implementation of Java source code parser written in JavaScript language. Do you know any?
Have a look at ANTLR which can have Javascript as a target, with the Java 1.5 grammar at http://www.antlr.org/grammar/1152141644268/Java.g
Edit: link stopped working - try https://github.com/antlr/grammars-v4/blob/master/java/Java.g4 :)
Here is Java 1.7 parser http://mazko.github.io/jsjavaparser/ using PEG grammar by Roman R Redziejowski http://www.romanredz.se/Mouse/Java.1.7.peg
I don't know of a Java parser per se, but here are some parser generators for Javascript:
http://jscc.jmksf.com/
http://code.google.com/p/cruiser/wiki/Parse
http://pegjs.majda.cz/
http://zaach.github.com/jison/
and more are listed here including PGS's that are written in other languages and target Javascript ...
If is one of these is ready for prime-time, you should be able to translate the grammar for Java into the requisite form and then use the PGS's to generate a Java parser in Javascript.
Of course, that will only give you a parser. If you want to do type analysis (as your comment seems to be saying), that's not what a parser does.
Try the Rhino engine?
I'm developing a small programming language based mostly of the C99 standard and I've already written a fairly decent lexer in java and now I'm looking to generate a Java Parser from the grammar. I know there's Bison, but that seems to only generate C code. I'm looking for a application that will allow me to input my grammar and create a full parser class in java code. Reading other SO posts on related topics, I've found ANTLR, but I'm wondering if anyone in the SO knows about a better tool?
thanks!
Another couple to look at are JavaCC and SableCC (it has been a long time since I looked at SableCC).
I've been quite impressed by BNFC, which is able to generate parsers in Java as well as in C, C++, C#, F#, Haskell, and OCaml.
The JFlex home page at http://jflex.de indicates where to find Bison-like tools that can target Java:
http://byaccj.sourceforge.net/
http://www2.cs.tum.edu/projects/cup/
http://www.antlr.org/