[ruby/rdoc] Use a more portable way to check if code is parseable

* The same as used in irb: https://github.com/ruby/irb/pull/134/files
* This works on all Ruby implementations, unlike `return` in BEGIN which
  can be quite difficult to support.

https://github.com/ruby/rdoc/commit/d19f7c66fe
This commit is contained in:
Benoit Daloze 2023-07-26 14:08:23 +02:00 committed by git
parent 628cc7e12d
commit df5330b04e

View File

@ -430,7 +430,9 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
def parseable? text
verbose, $VERBOSE = $VERBOSE, nil
eval("BEGIN {return true}\n#{text}")
catch(:valid) do
eval("BEGIN { throw :valid, true }\n#{text}")
end
rescue SyntaxError
false
ensure