nikgoodley-ibboost / gbench

Automatically exported from code.google.com/p/gbench
Apache License 2.0
0 stars 0 forks source link

Compilation errors "unexpected token" #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For this script, I get "unexpected token: benchmark at line: 4, column: 1":

---
@Grab('com.googlecode.gbench:gbench:0.4.1-groovy-2.1') // v0.4.1 for Groovy 2.1

benchmark(verbose:true) {
    'Each' {
        def i = 0
        (1..100000000).each { i ++ }
    }
    'For' {
        def i = 0
        for (x in 1..100000000) { i ++ }
    }
}.prettyPrint()

---

This gives "unexpected token: { at line: 3, column: 1":

---
@Grab('com.googlecode.gbench:gbench:0.4.1-groovy-2.1') // v0.4.1 for Groovy 2.1

{
    'Each' {
        def i = 0
        (1..100000000).each { i ++ }
    }
    'For' {
        def i = 0
        for (x in 1..100000000) { i ++ }
    }
}.benchmark().prettyPrint()

---

The following works OK:

---
@Grab('com.googlecode.gbench:gbench:0.4.1-groovy-2.1') // v0.4.1 for Groovy 2.1

def r = benchmark(verbose: true) {
    'Each' {
        def i = 0
        (1..100000000).each { i ++ }
    }
    'For' {
        def i = 0
        for (x in 1..100000000) { i ++ }
    }
}
r.prettyPrint()

---

Using:

///
* Groovy: 2.1.2
* JVM: Java HotSpot(TM) 64-Bit Server VM (23.7-b01, Oracle Corporation)
    * JRE: 1.7.0_17
    * Total Memory: 126.0625 MB
    * Maximum Memory: 126.0625 MB
* OS: Windows 8 (6.2, amd64) 
///

Is this something to do with the GBench extension?

Original issue reported on code.google.com by googlegr...@transentia.com.au on 24 Mar 2013 at 11:46

GoogleCodeExporter commented 9 years ago
That is Grape-depended problem. I tested the following examples with 
0.4.2-groovy-2.1 and they are successfully compiled and run with the local jar 
file but not via Grape.
{{{
        benchmark(verbose:true) {
            'Each' {
                def i = 0
                (1..100000000).each { i ++ }
            }
            'For' {
                def i = 0
                for (x in 1..100000000) { i ++ }
            }
        }.prettyPrint()
}}}
{{{
        { -> // this arrow is required
            'Each' {
                def i = 0
                (1..100000000).each { i ++ }
            }
            'For' {
                def i = 0
                for (x in 1..100000000) { i ++ }
            }
        }.benchmark().prettyPrint()
}}}

Original comment by nagaimas...@gmail.com on 26 Mar 2013 at 3:25

GoogleCodeExporter commented 9 years ago
I'll test a bit more and report the problem to Groovy project.

Original comment by nagaimas...@gmail.com on 26 Mar 2013 at 4:03

GoogleCodeExporter commented 9 years ago
http://jira.codehaus.org/browse/GROOVY-6069

Original comment by nagaimas...@gmail.com on 27 Mar 2013 at 8:37

GoogleCodeExporter commented 9 years ago
I got an answer from groovy team. It's not a bug.
[https://jira.codehaus.org/browse/GROOVY-6069?focusedCommentId=322751&page=com.a
tlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-322751]
{quote}
I don't think this is specific to extension module. The problem is that @Grab 
is an annotation, so you can only put @Grab where annotations are valid. This 
means imports or packages definitions here. For example:
{quote}

Original comment by nagaimas...@gmail.com on 28 Mar 2013 at 2:17