Groovy 1.0 JSR 1 Released O’Reilly CodeZoo: Trying to pen in the wilds of opensource
Apr 06

Groovy JSR Hyperlinked Grammar

Groovy, Tech Add comments

I am going through a slew of Groovy code and making sure it works in Groovy JSR.

From time to time it is nice to look at the grammar to see what is happening, and there is a hyperlinked version at: http://groovy.codehaus.org/jsr/spec/grammar.

My observations on the migration so far are:

  • Get ready to do a s/// for: |\s*(\w+)\s*| to the -> version
  • I am a fan of ‘#’ for comments, so I had to s|#|//|
  • Get ready to do some ‘def’ additions although…
  • I was surprised when a lot of scripts ‘just worked’ after the || conversion. I was surprised because I knew I wasn’t ‘def’ing all of my variables. It turns out that the current parser is fairly lax (apart from with member variables and methods), so I all of the following just works:
    aVar = "aVar"
    
    println aVar
    
    def m() {
    println aVar
    
    anotherVar = "anotherVar"
    println anotherVar
    }
    
    m()
    
    class Foo {
    def f = "letter f"
    
    def printF() {
    println this.f
    }
    
    def printG() {
    g = "letter g"
    println g
    }
    
    }
    
    fc = new Foo()
    fc.printF()
    fc.printG()
    

    The parser will get stricter though, so I will have to do def additions (I understand why, but I prefer not having the noise)

  • I spent some time breaking things to see what errors came out. For the first time ever, I actually was pointed to where the problem was (with the correct line in script). Now I just wish they could surpress the huge stacktrace that occurs and just tell me the problem. Let me give a -option to see all of the evil crap.
  • I know that I haven’t hit the hard snags yet though…. so we will see!

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What are the first four letters in the word British?