Newbie question

ruby 1.8.2 (2004-12-25) [i386-mswin32]

Hi folks,

I'm stumped by a syntax error. The error itself isn't telling me enough, I
think.

I'm attempting to run a unit test and here is the error message that results
:

"
d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__':
../a
ppClasses.rb:153: syntax error (SyntaxError)
        from d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`re
quire'
        from D:/Data/Greg/dev/ruby/hg project/tc_appClasses.rb:1
"

I've looked at custom_require.rb and my newbie eyes can't see anything
amiss.

appClasses and tc_appClasses are my files. The syntax error is on the last
line of this in appClasses.rb :

class CostsToDatabase

  def processCostsData(filepath,databasePath,*definitionFiles)
    definition=Definition.new
    definitionFiles.each do |df|
      definition.setDefinitionFromFile!(df)
    end
  end

end # <syntax error pointing to here

I just can't see the trouble, although I'm pretty certain its related to the
test unit stuff.

Both my files are located here http://www.lorriman.com/deleteme/ if any kind
person needs to look at the whole code.

Thanks for any help,

Greg

A "syntax error" on the last line almost always indicates a missing "end". Get in the habit of checking that first when you see the complaint. In this case, I believe you meant:

   def setFromNativeRef!(nativeRef)
     md=/\D+/.match(nativeRef)
     if (!md)
       raise 'Invalid cell reference :'+nativeRef
     end # <= James added this line!
     colStr=md[0].upcase
     if colStr.length==2
       high=colStr[0]-65
       low=colStr[1]-65
       @col=high*26+low
     else
       @col=colStr[0]-65
     end
     @col=md[0]
     @row=md.post_match
     self
   end

Hope that helps.

James Edward Gray II

···

On Jul 28, 2005, at 10:26 AM, Greg Lorriman wrote:

appClasses and tc_appClasses are my files. The syntax error is on the last
line of this in appClasses.rb :

It looks like you haven't closed one of your if statements:

In appClasses.rb,

def setFromNativeRef!(nativeRef)
    md=/\D+/.match(nativeRef)
    if (!md) <---------------- This if does not have a corresponding end
      raise 'Invalid cell reference :'+nativeRef
    colStr=md[0].upcase
    if colStr.length==2
      high=colStr[0]-65
      low=colStr[1]-65
      @col=high*26+low
    else
      @col=colStr[0]-65
    end
    @col=md[0]
    @row=md.post_match
    self
  end

If you want to use a single line if statement, use this:

raise 'Invalid cell reference :'+nativeRef if (!md)

···

On 7/28/05, Greg Lorriman <bogus@bogus.com> wrote:

ruby 1.8.2 (2004-12-25) [i386-mswin32]

Hi folks,

I'm stumped by a syntax error. The error itself isn't telling me enough, I
think.

The real error line is 22:
21: if (!md)
22: raise 'Invalid cell reference :'+nativeRef
23: end # <-- this was missing

···

On 7/28/05, Greg Lorriman <bogus@bogus.com> wrote:

ruby 1.8.2 (2004-12-25) [i386-mswin32]

Hi folks,

I'm stumped by a syntax error. The error itself isn't telling me enough, I
think.

---

Paolo

Wonderful, thank you very much.

and apologies for sending you an emailed reply by mistake.

Greg

A "syntax error" on the last line almost always indicates a missing
"end". Get in the habit of checking that first when you see the
complaint. In this case, I believe you meant:

I had considered that possibility, but in other languages the missing 'end'
marker tends to result in an error message closer to the mistake, and so I
didn't look back far enough through the code.

Thanks very much for your help.

Greg