Translating (or at least parsing) Java interface definitions

9 views
Skip to first unread message

Tim Bunce

unread,
Aug 8, 2005, 5:25:26 AM8/8/05
to perl6-l...@perl.org, Tim Bunce
Anyone done any work on parsing Java interface definitions?

And, ideally, translating them into roughly equivalent Perl 6?

Tim.

Gaal Yahas

unread,
Aug 11, 2005, 3:14:11 AM8/11/05
to Tim Bunce, perl6-l...@perl.org
On Mon, Aug 08, 2005 at 10:25:26AM +0100, Tim Bunce wrote:
> Anyone done any work on parsing Java interface definitions?
>
> And, ideally, translating them into roughly equivalent Perl 6?

I wrote something that did this with Parse::RecDescent. Unfortunately,
I don't own the code.

For my purposes I needed to parse several hundred interface files and
build Perl 5 classes (with hierarchy) on the fly from them. The files
in practice only used a subset of the possible Java syntax available in
an interface, but more than a trivial subset. The grammar (together with
interspersed to buildcode) came out at about 120 lines. It was fast
enough for me after the initial Parse::RecDescent startup hit.

The Java language spec contains a few grammars that helped me.

I found I couldn't use autotree because I can't control the base for
the resulting namespace: I have a patch to Parase::RecDescent somewhere
that fixes that, or you could use Class::Rebless which I wrote initially
because of this problem -- though I ended up doing the blesswork inside
the code sections manually as it made much more algorithmic sense.

Hope this helps.

--
Gaal Yahas <ga...@forum2.org>
http://gaal.livejournal.com/

Reply all
Reply to author
Forward
0 new messages