Script running in Ruby version 1.6.7 but not in 1.8.4

Hi,

I have written a script in Ruby version 1.6.7 running in Windows and it
is
doing fine. But when I start it in Linux with Ruby version 1.8.4 there
are
lot of error messages.

I minimized the script to that part, which will cause the errors.

Here it is:


#======================================================================

class Block

Block

=====================================================================

class Block

UMLAUTE = “”<<0x84<<0x81<<0x94<<0x80<<0x99<<0x9A<<0xE1
REG_VAR_NAME = “[a-z]+[a-z0-9_#$”+"()" + “@.” + UMLAUTE + “]"
REG_PLAIN_NAME = “[a-z]+[a-z0-9_” + “.” + UMLAUTE + "]

REG_PARAM_LIST = “[a-z]+[a-z0-9_#$,” + UMLAUTE + “]"
REG_STRUCT_NAME = “[a-z]+[a-z0-9_” + UMLAUTE + "]

#--------------------------------------------------------------------

Block#adapt_param_list_with_types

Change paramlist for use in c++ prototypes

#--------------------------------------------------------------------
def adapt_param_list_with_types(var_list)
out_list = String.new("")
vars = var_list.split(’,’)

vars.each do |var|
  if var =~ /REF/
    ref  = "&"
  else
    ref = ""
  end
  case var
    when Regexp.new("REF\s(#{REG_PLAIN_NAME)

[@]\sOF\s(#{REG_PLAIN_NAME})$")
out_list += “#{$2} *#{$1},”
when Regexp.new("(#{REG_PLAIN_NAME})#$")
out_list += “int " + ref + $1 + “_int,”
when Regexp.new(”(#{REG_PLAIN_NAME})[$]$")
out_list += “str " + ref + $1 + “_str,”
when Regexp.new(”(#{REG_PLAIN_NAME})$")
out_list += "double " + ref + $1 + “,”
else
out_list += var + “,”
end
end
out_list.chop!
#puts "var_list = " + var_list
#puts "out_list = " + out_list
return adapt_umlaut_in_var_names(out_list)
end

end


Here are the error messages:


ruby test.rb

test.rb:9: parse error, unexpected ‘(’, expecting kEND
REG_VAR_NAME = “[a-z]+[a-z0-9_#$”+"()" + “@.” + UMLAUTE + “]"
^
test.rb:9: parse error, unexpected $undefined., expecting kEND
REG_VAR_NAME = “[a-z]+[a-z0-9_#$”+"()" + “@.” + UMLAUTE + "]

^
test.rb:9: parse error, unexpected ‘]’, expecting kEND
REG_VAR_NAME = “[a-z]+[a-z0-9_#$”+"()" + “@.” + UMLAUTE + “]"
^
test.rb:10: trailing _' in number REG_PLAIN_NAME = "[a-z]+[a-z0-9_" + "." + UMLAUTE + "]*" ^ test.rb:10: parse error, unexpected tSTRING_BEG, expecting ']' REG_PLAIN_NAME = "[a-z]+[a-z0-9_" + "." + UMLAUTE + "]*" ^ test.rb:10: parse error, unexpected tSTRING_BEG REG_PLAIN_NAME = "[a-z]+[a-z0-9_" + "." + UMLAUTE + "]*" ^ test.rb:10: parse error, unexpected ']', expecting kEND REG_PLAIN_NAME = "[a-z]+[a-z0-9_" + "." + UMLAUTE + "]*" ^ test.rb:11: trailing’ in number
REG_PARAM_LIST = "[a-z]+[a-z0-9
#$," + UMLAUTE + "]

^
test.rb:12: parse error, unexpected tCONSTANT, expecting ‘]’
REG_STRUCT_NAME = “[a-z]+[a-z0-9_” + UMLAUTE + “]*”
^
test.rb:33: parse error, unexpected tIDENTIFIER, expecting ‘)’
out_list += “int " + ref + $1 + “_int,”
^
test.rb:33: parse error, unexpected tIDENTIFIER, expecting kEND
out_list += “int " + ref + $1 + “_int,”
^
test.rb:34: parse error, unexpected ‘(’, expecting tCOLON2 or ‘[’ or ‘.’
when Regexp.new(”(#{REG_PLAIN_NAME})[$]$”)
^
test.rb:36: parse error, unexpected kWHEN, expecting kEND
when Regexp.new("(#{REG_PLAIN_NAME})$")
^
test.rb:38: parse error, unexpected kELSE, expecting kEND
else
^
test.rb:48: parse error, unexpected kEND, expecting $


Does anybody have an idea, why these erorr messages occur?

Siegward

“B” == Beratung [email protected] writes:

Write it like this

B> class Block

B> UMLAUTE = “”<<0x84<<0x81<<0x94<<0x80<<0x99<<0x9A<<0xE1
B> REG_VAR_NAME = “[a-z]+[a-z0-9_#$”+“()” + “@.” + UMLAUTE + “]*”

 REG_VAR_NAME = "[a-z]+[a-z0-9_$#"+"()" + "@." + UMLAUTE + "]*"

B> REG_PLAIN_NAME = “[a-z]+[a-z0-9_” + “.” + UMLAUTE + “]"
B> REG_PARAM_LIST = “[a-z]+[a-z0-9_#$,” + UMLAUTE + "]

 REG_PARAM_LIST = "[a-z]+[a-z0-9_$#," + UMLAUTE + "]*"

otherwise it try to interpret

#$" as #{$"}

#$, as #{$,}

B> REG_STRUCT_NAME = “[a-z]+[a-z0-9_” + UMLAUTE + “]*”

Guy Decoux

Hi –

On Tue, 23 May 2006, [email protected] wrote:


#======================================================================

class Block

Block

=====================================================================

class Block

UMLAUTE = “”<<0x84<<0x81<<0x94<<0x80<<0x99<<0x9A<<0xE1
REG_VAR_NAME = “[a-z]+[a-z0-9_#$”+"()" + “@.” + UMLAUTE + “]*”

In 1.8.4, you can use the shorthand of #$x for #{$x} with global
variables. So Ruby thinks you want to interpolate the variable $".
The " therefore doesn’t count as a string delimiter, and you get in
trouble.

If you escape the # (#) it should be OK.

David

Thank you. I changed double quotes into single quotes and now it’s
working
fine.

Siegward