module Ruby::Prism

The Ruby::Prism Ruby parser.

“Parsing Ruby is suddenly manageable!” - You, hopefully

Ruby::Prism is the prism parser built into the interpreter, i.e., the very parser that parsed the running program.

Its API follows the version of prism bundled with this Ruby, and may change incompatibly between Ruby minor versions: not only the node definitions but also the other APIs, as the bundled prism may move to a new major version.

In most cases, use the prism gem instead. Use Ruby::Prism only when you need the very parser of the running interpreter.

Constants

BACKEND

The C extension is the default backend on CRuby.

Public Class Methods

Given a Method, UnboundMethod, Proc, or Thread::Backtrace::Location, returns the Ruby::Prism node representing it. On CRuby, this uses node_id for an exact match. On other implementations, it falls back to best-effort matching by source location line number.

: (Method | UnboundMethod | Proc | Thread::Backtrace::Location callable) -> Node?

# File lib/ruby/prism.rb, line 94
def self.find(callable)
  NodeFind.find(callable)
end

Returns a parse result whose value is an array of tokens that closely resembles the return value of Ripper.lex.

For supported options, see Ruby::Prism.parse.

: (String source, **untyped options) -> LexCompat::Result

# File lib/ruby/prism.rb, line 74
def self.lex_compat(source, **options)
  LexCompat.new(source, **options).result # steep:ignore
end

Load the serialized AST using the source as a reference into a tree.

: (String source, String serialized, ?bool freeze) -> ParseResult

# File lib/ruby/prism.rb, line 84
def self.load(source, serialized, freeze = false)
  Serialize.load_parse(source, serialized, freeze)
end

Create a new scope with the given locals and forwarding options that is suitable for passing into one of the Ruby::Prism.* methods that accepts the scopes option.

: (?locals: Array, ?forwarding: Array) -> Scope

# File lib/ruby/prism/parse_result.rb, line 1231
def self.scope(locals: [], forwarding: [])
  Scope.new(locals, forwarding)
end