Regex to transform java code to ecma script

P

pondus

Hi,

I was hoping someone could provide me with a better way to accomplish
(preferrably in one line) the following simple task:

# typical method declaration in a java interface
code = "public void myFunction(String foo);"

# needs to be transformed into the following e.g. Actionscript 2.0
(ECMA)
# public function myFunction(foo:String):Void;

java = code.gsub(/(public) (.*?) (.*).*(;)/) { $1 + ' function ' + $3
+ ':' + $2.capitalize + ";" }
puts code.gsub(/\((String) (foo)\)/,'(\2:\1)')



It works, but it's not very slick..

Thanks!

Peder :)
 
P

pondus

Sorry, my mistake..cut and paste is dangerous. The code should read:

code = "public void myFunction(String foo);"

code = code.gsub(/(public) (.*?) (.*).*(;)/) { $1 + ' function ' + $3
+ ':' + $2.capitalize + ";" }

puts code.gsub(/\((String) (foo)\)/,'(\2:\1)')

Thanks again,

Peder :)
 
G

Giles Bowkett

If you can convert Java to ActionScript with a one-line regex, that's
pretty good.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,216
Messages
2,571,120
Members
47,720
Latest member
mohdkaif002

Latest Threads

Top