[antlr-interest] A Kinder, Gentler Java

Prashant Deva prashant.deva at gmail.com
Sun Oct 29 13:55:39 PST 2006


Terence Parr, (author of antlr) is already working on his Mantra language
which translates to java and is pretty cool, so you might wish to talk to
him.


-- 
Prashant Deva
Creator, ANTLR Studio
Founder, Placid Systems, www.placidsystems.com

On 10/29/06, Owen Densmore <owen at backspaces.net> wrote:
>
> I'd like to build a preprocessor to create a much cleaner, less
> verbose version of Java. I'm not sure if ANTLR can do this for me ..
> sorta a preprocessor from a "java--" to java. If it can, PLEASE send
> along a few pointers to me, a newbie!
>
> Here's the story:
>
> I've been following the JVM "agile" languages: Groovy, JRuby, Jython.
> Although I've very much enjoyed using them, I've also been impressed
> with the improvements in Java itself, especially with Java 1.5.
>
> Although I like the agile languages, it's my impression that just
> simplifying Java itself would be good enough for me. These three
> sites capture the sort of thing I'd like to achieve:
> 10 Reasons We Need Java 3.0
>    http://www.onjava.com/lpt/a/2524
> Shorter Syntax for Common Operations
>    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6389769\
>    Here's a better formatted version:
>    http://tinyurl.com/hc2ea
> James Gosling: on the Java Road -- Scripting flamewar
> (This also refers to the Shorter Syntax article above)
>    http://blogs.sun.com/jag/entry/scripting_flamewar
> They all address verbosity and warts in Java fairly nicely.
>
> I'm convinced that a preprocessor could handle these, translating
> simplifications of Java into standard Java. I mean, how hard could it
> be to introduce raw strings and multi-line strings, right? Maybe
> something like python/groovy strings would do the trick. So:
>    r"\n\r" -> "\\n\\r" in Java and
> """
> This is a multi line string
> with newlines.
> """
>    ->
> "This is a multi line string\n"+"with newlines.\n"
>
> Reducing the verbosity of declarations should fairly reasonable:
> Java:
>    Foo<T> foo = new Foo<T>(a,b,c);
> Simplified to:
>    Foo<T> foo = new(a,b,c);
> or
>    foo := Foo<T>(a,b,c);
>
> The biggest simplification I'm thinking about would be for one-method
> interfaces generally used an anonymous inner classes. [Google for
> Functor to see great examples. Closures also capture the idea.]
> So in Java, you define a method in a class:
>    ApplyExec(List<T>, Exec<T>);
> .. that uses a simple interface:
>    interface Exec<T> {
>      void exec(T t);
>    }
> It would be called like this in Java:
>    ApplyExec(myTList, new Exec<T>(){
>        void exec(T t) {
>          t.foo = t.bar + 7;
>        }
>    })
> I'd prefer a very simple:
>    ApplyExec(myTList,{t|t.foo = t.bar + 7})
> Note that this captures the feel of a dynamic call, but it really is
> not, its a simple anonymous inner class shorthand. This would need
> either a name convention or a bit more information or both to work
> without building a fairly sophisticated parser. But still, you get
> the idea.
>
> So is this something we could do easily in ANTLR??  If so, how!?
>
> Thanks
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20061029/1b4bcb0d/attachment.html 


More information about the antlr-interest mailing list