Skip to content

Commit

Permalink
Merge pull request #664 from ksss/parser-buffer
Browse files Browse the repository at this point in the history
Improve Parser::Source::Buffer
  • Loading branch information
pocke authored Sep 17, 2024
2 parents 7c6844d + a5de7f1 commit f5ccba0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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

0 comments on commit f5ccba0

Please sign in to comment.