From: "Rob ." Date: 2005-11-10T01:11:05+09:00 Subject: Re: RUBY GRAMMAR On 11/9/05, puellula@gmail.com wrote: > Can you help me? I have to write a Ruby Editor + Parser > with Java I'm curious why do you *have* to write a Ruby Editor + Parser with Java? If you wish to parse Ruby code in Java, I recommend using the JRuby parser (http://jruby.sourceforge.net/). If you want to write a Ruby Editor in Java, there are existing editor efforts underway that would welcome enthusiastic developers helping out. I'm writing the jEdit Ruby Editor Plugin (http://jedit.org/ruby/). There are also Eclipse based plugins underway, like Ruby Development Tools and RadRails. If you want to use JRuby, here is some example parsing code: DefaultRubyParser parser = new DefaultRubyParser(); parser.init(new RubyParserConfiguration()); LexerSource source = LexerSource.getSource(file, content); RubyParserResult result = parser.parse(source); Node node = result.getAST(); NodeVisitor visitor = new RubyNodeVisitor(); if (node != null) { node.accept(visitor); } List members = visitor.getMembers(); You implement your own version of the JRuby NodeVisitor interface, which looks something like this: class RubyNodeVisitor extends AbstractVisitor { ... protected void visitNode(Node node) { ... public void visitBlockNode(BlockNode node) { ... public void visitNewlineNode(NewlineNode node) { ... public void visitModuleNode(ModuleNode node) { ... public void visitClassNode(ClassNode node) { ... public void visitDefnNode(DefnNode node) { ... public void visitDefsNode(DefsNode node) { ... public void visitScopeNode(ScopeNode node) { ... // etc } cheers, Rob