diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2023-10-30 13:49:32 -0400 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2023-11-01 13:10:29 -0400 |
| commit | f12617ec9832ff8979cd86eb717fa9ee5820123e (patch) | |
| tree | 6a02dd2214629bdff0a6804d536a84efdec078d2 /lib/prism | |
| parent | 73b6934cf27315ac52e7565f4ff7b889447f5593 (diff) | |
[ruby/prism] Fix up Prism and Debug docs
https://github.com/ruby/prism/commit/c2b7724d91
Diffstat (limited to 'lib/prism')
| -rw-r--r-- | lib/prism/debug.rb | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/prism/debug.rb b/lib/prism/debug.rb index bd2eb0842b..f573d0958d 100644 --- a/lib/prism/debug.rb +++ b/lib/prism/debug.rb @@ -4,7 +4,9 @@ module Prism # This module is used for testing and debugging and is not meant to be used by # consumers of this library. module Debug - class ISeq + # A wrapper around a RubyVM::InstructionSequence that provides a more + # convenient interface for accessing parts of the iseq. + class ISeq # :nodoc: attr_reader :parts def initialize(parts) @@ -42,6 +44,11 @@ module Prism end end + private_constant :ISeq + + # :call-seq: + # Debug::cruby_locals(source) -> Array + # # For the given source, compiles with CRuby and returns a list of all of the # sets of local variables that were encountered. def self.cruby_locals(source) @@ -76,8 +83,16 @@ module Prism end end + # Used to hold the place of a local that will be in the local table but + # cannot be accessed directly from the source code. For example, the + # iteration variable in a for loop or the positional parameter on a method + # definition that is destructured. AnonymousLocal = Object.new + private_constant :AnonymousLocal + # :call-seq: + # Debug::prism_locals(source) -> Array + # # For the given source, parses with prism and returns a list of all of the # sets of local variables that were encountered. def self.prism_locals(source) @@ -164,10 +179,19 @@ module Prism locals end + # :call-seq: + # Debug::newlines(source) -> Array + # + # For the given source string, return the byte offsets of every newline in + # the source. def self.newlines(source) Prism.parse(source).source.offsets end + # :call-seq: + # Debug::parse_serialize_file(filepath) -> dumped + # + # For the given file, parse the AST and dump it to a string. def self.parse_serialize_file(filepath) parse_serialize_file_metadata(filepath, [filepath.bytesize, filepath.b, 0].pack("LA*L")) end |
