Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Parser::Source::Buffer #664

Merged
merged 1 commit into from
Sep 17, 2024
Merged
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
3 changes: 3 additions & 0 deletions gems/parser/3.2/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

node = Parser::CurrentRuby.parse("2 + 2") or raise
node.loc

buffer = Parser::Source::Buffer.new(__FILE__)
buffer.name
35 changes: 35 additions & 0 deletions gems/parser/3.2/parser.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,42 @@ module Parser
class Range
end

##
# A buffer with source code. {Buffer} contains the source code itself,
# associated location information (name and first line), and takes care
# of encoding.
#
# A source buffer is immutable once populated.
#
# @!attribute [r] name
# Buffer name. If the buffer was created from a file, the name corresponds
# to relative path to the file.
# @return [String] buffer name
#
# @!attribute [r] first_line
# First line of the buffer, 1 by default.
# @return [Integer] first line
#
# @api public
#
class Buffer
attr_reader name: String
attr_reader first_line: Integer

def self.recognize_encoding: (String) -> Encoding
def self.reencode_string: (String) -> String

def initialize: (untyped name, ?Integer first_line, ?source: untyped) -> void
def read: () -> self
def source: () -> String
def source=: (String) -> String
def raw_source: (String) -> String
def decompose_position: (Integer) -> [Integer, Integer]
def source_lines: () -> Array[String]
def source_line: (Integer) -> String
def line_range: (Integer) -> ::Range[Integer]
def source_range: () -> ::Range[Integer]
def last_line: () -> Integer
end

class TreeRewriter
Expand Down