Skip to content

Commit ca48251

Browse files
authored
Use prism to check if code is valid (#1695)
A bit nicer than what it currently does
1 parent 71326ff commit ca48251

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

lib/rdoc/markup/to_html.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22
require 'cgi/escape'
33
require 'cgi/util' unless defined?(CGI::EscapeExt)
4+
require 'prism'
45

56
##
67
# Outputs RDoc markup as HTML.
@@ -568,14 +569,7 @@ def list_end_for(list_type)
568569
# Returns true if text is valid ruby syntax
569570

570571
def parseable?(text)
571-
verbose, $VERBOSE = $VERBOSE, nil
572-
catch(:valid) do
573-
eval("BEGIN { throw :valid, true }\n#{text}")
574-
end
575-
rescue SyntaxError
576-
false
577-
ensure
578-
$VERBOSE = verbose
572+
Prism.parse_success?(text)
579573
end
580574

581575
##

0 commit comments

Comments
 (0)