Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Ripper.sexp
sexp(src, filename = '-', lineno = 1, raise_errors: false)
ext/ripper/lib/ripper/sexp.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/ext/ripper/lib/ripper/sexp.rb, line 35
def Ripper.sexp(src, filename = '-', lineno = 1, raise_errors: false)
builder = SexpBuilderPP.new(src, filename, lineno)
sexp = builder.parse
if builder.error?
if raise_errors
raise SyntaxError, builder.error
end
else
sexp
end
end
- EXPERIMENTAL
-
Parses
srcand create S-exp tree. Returns more readable tree rather thanRipper.sexp_raw. This method is mainly for developer use. Thefilenameargument is mostly ignored. By default, this method does not handle syntax errors insrc, returningnilin such cases. Use theraise_errorskeyword to raise aSyntaxErrorfor an error insrc.require 'ripper' require 'pp' pp Ripper.sexp("def m(a) nil end") #=> [:program, [[:def, [:@ident, "m", [1, 4]], [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil, nil, nil, nil]], [:bodystmt, [[:var_ref, [:@kw, "nil", [1, 9]]]], nil, nil, nil]]]]