6

In the RubyMine debugger, just type this into the watches:

';'

or

";"

and I am getting the error:

"unterminated string meets end of file"

Why is this? It doesn't happen in the Rails console, and it doesn't have anything to do with RubyMine, as far as an I can tell.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Marc Clifton
  • 756
  • 1
  • 11
  • 19

2 Answers2

12

This is the result of the Ruby debugger having different parsing rules from the Ruby interpreter. In fact, the regular Ruby debugger, invoked from irb or the ruby command exhibits this same behaviour. The workaround, however, is straightforward: to create a string literal consisting of a single semicolon, just escape it with a backslash:

$ irb
> require 'debugger'
 => true
> debugger
(rdb:1) ';'
*** SyntaxError Exception: /usr/local/rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/irb/context.rb:166: unterminated string meets end of file
(rdb:1) '\;'
";"

It's important to note that the Ruby debugger command-line parser is not the same as the parser used by the irb or ruby interpreter: it is designed around parsing debugger commands such as backtrace, break etc. and not for parsing the Ruby language (with shell-like extensions in the case of irb). It has limited support for evaluating Ruby (or Ruby-style) expressions. This is, of course, crucial to effective debugging of Ruby programs. However, you should not expect it to be able to parse everything that irb or the ruby command itself would be able to parse or to parse things in exactly the same way. In some cases, like this, it can handle certain expressions but they need to be escaped subject to the parsing rules of the debugger as opposed to the Ruby language itself.

The Rails console is built on top of irb and is, thus, a Ruby shell and respects the parsing rules of the Ruby language just like irb and ruby.

Richard Cook
  • 32,523
  • 5
  • 46
  • 71
  • I had the same problem using gsub('\;',',') - interpreter did one thing, debug prompt did another – Mitch Aug 09 '13 at 16:03
0

I had the same problem with the Ruby CSV library parsing a CSV with a Semicolon as delimiter. I added the col_sep ';' but it always resulted in the following error: unterminated string meets end of file

Correct way of doing it:

CSV.open(file.path, col_sep: '\;', &:readline)

Added this as documentation for anybody else.

fydelio
  • 932
  • 1
  • 8
  • 22