Hi,

Inline::Java::PerlInterpreter allows you to call Perl code from Java
using an embedded Perl interpreter. You should be able to do what you
want to do with that. However keep in mind that it's not been
extensively tested and is still somewhat experimental.

Here's an example (I'm no PPI expert...):

import org.perl.inline.java.* ;

class test {

public static void main(String args[])
        throws InlineJavaPerlException, InlineJavaException {

        InlineJavaPerlInterpreter pi = InlineJavaPerlInterpreter.create() ;

        pi.require("PPI::Document") ;
        pi.require("PPI::Dumper") ;
        pi.eval("sub main::do_ppi_stuff {
PPI::Dumper->new(PPI::Document->new(\\$_[0]))->string() }") ;

        String perl_code = "#!/usr/bin/perl\nprint( \"Hello World!\"
);\nexit();" ;

        String output = (String)pi.CallPerlSub("main::do_ppi_stuff",
new Object [] {perl_code}, String.class) ;
        System.out.println(output);

        pi.destroy() ;
}

}


which prints:


PPI::Document
  PPI::Token::Comment   '#!/usr/bin/perl\n'
  PPI::Statement
    PPI::Token::Word    'print'
    PPI::Structure::List        ( ... )
      PPI::Token::Whitespace    ' '
      PPI::Statement::Expression
        PPI::Token::Quote::Double       '"Hello World!"'
      PPI::Token::Whitespace    ' '
    PPI::Token::Structure       ';'
  PPI::Token::Whitespace        '\n'
  PPI::Statement
    PPI::Token::Word    'exit'
    PPI::Structure::List        ( ... )
    PPI::Token::Structure       ';'


A piece of advice is to keep the inter-language stuff as minimal as
possible. For example, pass the perl source to analyze over to the
Perl side, do all of the PPI stuff there, and then return a string to
Java that can then be parsed and displayed in your editor.

Patrick



On Wed, Feb 18, 2009 at 6:49 AM, Zaid Sheikh <sheikh.z...@gmail.com> wrote:
> I am trying to use the PPI module from inside Java (so as to implement
> syntax highlighting and parsing in a Perl editor). How do I do that?
>
> I have looked at Inline::Java, Inline::Java::PerlInterpreter and
> Inline::Java::Callback, Inline::Java::PerlNatives. None of them seem to
> serve my purpose,
> I have also tried the PLJava project. But it seems PLJava has not been
> developed since 2004. I am hoping there are better alternatives now.
>
> Any help will be greatly appreciated.
> --
> Zaid Md. Abdul Wahab Sheikh
> B.Tech Computer Science and Engineering
> NIT Allahabad (MNNIT)
>



-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada

Reply via email to