Syntax error, unexpected tSTRING_BEG

Hello, I hope this isn’t a dumb question but I have inherited some jruby
code that is throwing a syntax error and I have virtually no experience
with ruby. The goal is to compile and deploy compass/sass CSS
stylesheet from our Java app using BSFManager and jruby. It works from
the command line.

The exception is as follows:
Caused by: org.jruby.exceptions.RaiseException: (SyntaxError)

:12: syntax error, unexpected tSTRING_BEG ARGV.push('--css-dir').push('D:\S-Source\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\css\') (the exception points to the second apostrophe in the first push parameter '-css-dir' [after dir]) The command is executed as follows: result = manager.eval("jruby", "", 0, 0, compass); the 'compass' script is as follows: require 'rubygems' version = ">= 0" if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then version = $1 ARGV.shift end ARGV.push('compile') ARGV.push('D:\S-Source\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\sass\') ARGV.push('--css-dir').push('D:\S-S\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\css\') ARGV.push('--sass-dir').push('D:\S-B~1\S-P~1\SW\assets\theme\theme000000000001224\shell\sass') ARGV.push('--output-style').push('expanded') ARGV.push('--force') ARGV.push('--trace') puts ARGV.inspect() gem 'compass', version load Gem.bin_path('compass', 'compass', version) I'm really struggling to sort this out so if anyone has any pointers I would really appreciate it. Thanks in advance, Sean

Sean,

On Mar 20, 2012, at 12:00 PM, Sean B. wrote:

ARGV.push(‘compile’)

ARGV.push(‘D:\S-Source\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\sass’)

The last single quote is escaped by the backslash, so the String
continues on to the next line, until

ARGV.push(’–css-dir’).push(‘D:\S-S\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\css’)

the first single quote. JRuby then sees “–css-dir”, and another
single-quote, which should mark the beginning of a new String. But
that’s not allowed. You have the same problem on this line.

Thanks in advance,
Sean

Please study how strings are defined in Ruby. (Here, you can escape the
last backslash, or drop it altogether.)

On 20.03.2012 16:00, Sean B. wrote:

Hello, I hope this isn’t a dumb question but I have inherited some
jruby code that is throwing a syntax error and I have virtually no
experience with ruby. The goal is to compile and deploy compass/sass
CSS stylesheet from our Java app using BSFManager and jruby. It works
from the command line.

The exception is as follows:

Caused by: org.jruby.exceptions.RaiseException: (SyntaxError) :12:
syntax error, unexpected tSTRING_BEG

The final ‘’ on this line escapes the closing ':

ARGV.push(‘D:\S-Source\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\sass’)

Use a double \ at the end (or remove the trailing slash) to fix:

ARGV.push(‘D:\S-Source\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\sass\’)

And you’ll need to do the same on the next line.


Alex G.

See below…

On Tue, Mar 20, 2012 at 11:00 AM, Sean B. [email protected]
wrote:

syntax error, unexpected tSTRING_BEG

ARGV.push(‘–css-dir’).push('D:\S-Source\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\css')

backslash of \ in front of ’ will make it from a string delimeter to
an actual ’ char:

a = ‘'’ #=> ’

So your first ARGV.push added:

"')

ARGV.push('" to the string then thought it so two unary minuses --,
fcall (css), minus, fcall (dir), then an unexpected '.

You should not use \ for path delim in Ruby source if you can avoid it
since it ends up being confused with literal escaping of chars. When
possible use File.join too (I can understand why you didn’t here)
since it will make it more cross-platform.

-Tom

result = manager.eval(“jruby”, “”, 0, 0, compass);


blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]

Thanks for the prompt replies; that was it.

I’ll spend some time checking out how ruby hanles strings and file path
joins.

cheers.