Forum: Ruby Script running in Ruby version 1.6.7 but not in 1.8.4

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-05-23 13:58
(Received via mailing list)
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
ts (Guest)
on 2006-05-23 14:07
(Received via mailing list)
>>>>> "B" == Beratung  <removed_email_address@domain.invalid> 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
unknown (Guest)
on 2006-05-23 14:13
(Received via mailing list)
Hi --

On Tue, 23 May 2006, removed_email_address@domain.invalid 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
unknown (Guest)
on 2006-05-23 14:41
(Received via mailing list)
Thank  you. I changed double quotes into single quotes and now it's
working
fine.

Siegward
This topic is locked and can not be replied to.