Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/power_assert/parser.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
require 'ripper'

module PowerAssert
class Parser
Ident = Struct.new(:type, :name, :column)

# Prism is the default parser since Ruby 3.4. It contains a compatibility layer
# with ripper that returns data in the same format that ripper would.
RipperImplementation = begin
gem "prism", ">= 1.0.0"
require "prism"
Prism::Translation::Ripper
rescue LoadError
require "ripper"
Ripper
end

attr_reader :line, :path, :lineno, :binding

def initialize(line, path, lineno, binding, assertion_method_name = nil, assertion_proc = nil)
Expand All @@ -18,7 +27,7 @@ def initialize(line, path, lineno, binding, assertion_method_name = nil, asserti
end

def idents
@idents ||= extract_idents(Ripper.sexp(@line_for_parsing))
@idents ||= extract_idents(RipperImplementation.sexp(@line_for_parsing))
end

def call_paths
Expand Down
1 change: 0 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

require 'test/unit'
require 'power_assert'
require 'ripper'

module PowerAssertTestHelper
class << self
Expand Down