Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String with a semicolon results in "unterminated string meets end of file" in RubyMine

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.

like image 960
Marc Clifton Avatar asked Aug 05 '13 16:08

Marc Clifton


1 Answers

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.

like image 79
Richard Cook Avatar answered Nov 07 '22 15:11

Richard Cook