jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-460

improper parsing behavior or error message

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.0-JSR-1
  • Component/s: None
  • Labels:
    None
  • Environment:
    mac os x 10.3.3, java 1.4.2

Description

This bug had me scratching my head for a looong time. Here is a sample class that this happens:

Class Bug5 {
static void main(args) { println "hello" }
}

The error I get is:

Caught: Bug5.groovy: 2: could not use 'static' at 2:5

Bug5.groovy: 2: could not use 'static' at 2:5

Bug5.groovy: 5: could not use '}' at 5:1

at org.codehaus.groovy.control.ProcessingUnit.fail(ProcessingUnit.java:466)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:877)
at org.codehaus.groovy.control.CompilationUnit.parse(CompilationUnit.java:508)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:470)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:228)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:154)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:207)
(etc)

For the sharp-eyed people, you will notice that instead of "class" I errantly did "Class". So I guess the parser is trying to declare a variable named Bug5 of type Class, but I don't understand why it allows the chunk of code in the braces. I thought valid variable declarations looked like this:

[<type>] <name> [= <value>]

Anyway, if this is valid syntax, may I request that the error message be a little more descriptive, like "static is not allowed in a field initialization block" or something like that? That would have at least clued me into that the parser thinks he's doing something different than what I was intending to do, and make my debugging a little quicker.

Thanks!

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Chris Poirier added a comment - 11/May/04 3:00 PM

The problem is actually that Class Bug5 is interpreted as:
Class( Bug5() { ... } )

This is why the error message is bad. For now, you can check in groovysh – the "explain" command will show you how the code is being parsed. Unfortunately, it won't (can't) show you the parse tree for code that won't parse, but you could try reducing the text a bit until you get something of the same form that can.

This is probably another reason paren need to be required.

Show
Chris Poirier added a comment - 11/May/04 3:00 PM The problem is actually that Class Bug5 is interpreted as: Class( Bug5() { ... } ) This is why the error message is bad. For now, you can check in groovysh – the "explain" command will show you how the code is being parsed. Unfortunately, it won't (can't) show you the parse tree for code that won't parse, but you could try reducing the text a bit until you get something of the same form that can. This is probably another reason paren need to be required.
Hide
Permalink
John Rose added a comment - 17/Sep/04 6:57 PM

I agree with Chris here. There is a reason C-like languages require '()' in constructions like 'if {y}'. It firms up the syntax and prevents the parser from wandering. With Ruby-like calls in the mix, Groovy needs this convention even more.

(BTW, in other, simpler cases, I hope parentheses can be optional.)

Show
John Rose added a comment - 17/Sep/04 6:57 PM I agree with Chris here. There is a reason C-like languages require '()' in constructions like 'if {y}'. It firms up the syntax and prevents the parser from wandering. With Ruby-like calls in the mix, Groovy needs this convention even more. (BTW, in other, simpler cases, I hope parentheses can be optional.)
Hide
Permalink
blackdrag blackdrag added a comment - 22/Mar/05 7:57 AM

the new parser will now complain about a unexpected token Big5. Could be better, but it should do the job

Show
blackdrag blackdrag added a comment - 22/Mar/05 7:57 AM the new parser will now complain about a unexpected token Big5. Could be better, but it should do the job

People

  • Assignee:
    blackdrag blackdrag
    Reporter:
    John Stump
Vote (0)
Watch (0)

Dates

  • Created:
    11/May/04 10:19 AM
    Updated:
    23/Dec/07 12:25 PM
    Resolved:
    22/Mar/05 7:57 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.