Class: Parser::Source::Buffer
Overview
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.
source://parser//lib/parser/source/buffer.rb#25
Constant Summary collapse
- ENCODING_RE =
          
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
source://parser//lib/parser/source/buffer.rb#31
 T.let(T.unsafe(nil), Regexp)
Class Method Summary collapse
- 
  
    
      .recognize_encoding(string)  ⇒ String? 
    
    
  
  
  
  
  
  
  
  
  
    
Try to recognize encoding of
stringas Ruby would, i.e. - 
  
    
      .reencode_string(input)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Recognize encoding of
inputand process it so it could be lexed. 
Instance Method Summary collapse
- 
  
    
      #column_for_position(position)  ⇒ Integer 
    
    
  
  
  
  
  
  
  
  private
  
    
Convert a character index into the source to a column number.
 - 
  
    
      #decompose_position(position)  ⇒ [Integer, Integer] 
    
    
  
  
  
  
  
  
  
  
  
    
Convert a character index into the source to a
[line, column]tuple. - 
  
    
      #first_line  ⇒ Integer 
    
    
  
  
  
  
  
  
  
  
  
    
First line of the buffer, 1 by default.
 - 
  
    
      #freeze  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
source://parser//lib/parser/source/buffer.rb#317.
 - 
  
    
      #initialize(name, first_line = T.unsafe(nil), source: T.unsafe(nil))  ⇒ Buffer 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
source://parser//lib/parser/source/buffer.rb#110.
 - 
  
    
      #last_line  ⇒ Integer 
    
    
  
  
  
  
  
  
  
  
  
    
Number of last line in the buffer.
 - 
  
    
      #line_for_position(position)  ⇒ Integer 
    
    
  
  
  
  
  
  
  
  private
  
    
Convert a character index into the source to a line number.
 - 
  
    
      #line_range(lineno)  ⇒ Range 
    
    
  
  
  
  
  
  
  
  
  
    
Extract line
linenoas a newRange, takingfirst_lineinto account. - 
  
    
      #name  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Buffer name.
 - 
  
    
      #raw_source=(input)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Populate this buffer from a string without encoding autodetection.
 - 
  
    
      #read  ⇒ Buffer 
    
    
  
  
  
  
  
  
  
  
  
    
Populate this buffer from correspondingly named file.
 - 
  
    
      #slice(start, length = T.unsafe(nil))  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
source://parser//lib/parser/source/buffer.rb#199.
 - 
  
    
      #source  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Source code contained in this buffer.
 - 
  
    
      #source=(input)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Populate this buffer from a string with encoding autodetection.
 - 
  
    
      #source_line(lineno)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Extract line
linenofrom source, takingfirst_lineinto account. - 
  
    
      #source_lines  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    
Return an
Arrayof source code lines. - 
  
    
      #source_range  ⇒ Range 
    
    
  
  
  
  
  
  
  
  
  
    
source://parser//lib/parser/source/buffer.rb#303.
 
Constructor Details
#initialize(name, first_line = T.unsafe(nil), source: T.unsafe(nil)) ⇒ Buffer
source://parser//lib/parser/source/buffer.rb#110
      5155  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5155 def initialize(name, first_line = T.unsafe(nil), source: T.unsafe(nil)); end  | 
  
Class Method Details
.recognize_encoding(string) ⇒ String?
Try to recognize encoding of string as Ruby would, i.e. by looking for
magic encoding comment or UTF-8 BOM. string can be in any encoding.
source://parser//lib/parser/source/buffer.rb#52
      5327  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5327 def recognize_encoding(string); end  | 
  
.reencode_string(input) ⇒ String
Recognize encoding of input and process it so it could be lexed.
- If 
inputdoes not contain BOM or magic encoding comment, it is kept in the original encoding. - If the detected encoding is binary, 
inputis kept in binary. - Otherwise, 
inputis re-encoded into UTF-8 and returned as a new string. 
This method mutates the encoding of input, but not its content.
source://parser//lib/parser/source/buffer.rb#95
      5345  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5345 def reencode_string(input); end  | 
  
Instance Method Details
#column_for_position(position) ⇒ Integer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Convert a character index into the source to a column number.
source://parser//lib/parser/source/buffer.rb#247
      5164  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5164 def column_for_position(position); end  | 
  
#decompose_position(position) ⇒ [Integer, Integer]
Convert a character index into the source to a [line, column] tuple.
source://parser//lib/parser/source/buffer.rb#222
      5173  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5173 def decompose_position(position); end  | 
  
#first_line ⇒ Integer
First line of the buffer, 1 by default.
source://parser//lib/parser/source/buffer.rb#26
      5181  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5181 def first_line; end  | 
  
#freeze ⇒ Object
source://parser//lib/parser/source/buffer.rb#317
      5186  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5186 def freeze; end  | 
  
#last_line ⇒ Integer
Number of last line in the buffer
source://parser//lib/parser/source/buffer.rb#312
      5199  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5199 def last_line; end  | 
  
#line_for_position(position) ⇒ Integer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Convert a character index into the source to a line number.
source://parser//lib/parser/source/buffer.rb#236
      5208  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5208 def line_for_position(position); end  | 
  
#line_range(lineno) ⇒ Range
Extract line lineno as a new Range, taking first_line into account.
source://parser//lib/parser/source/buffer.rb#289
      5218  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5218 def line_range(lineno); end  | 
  
#name ⇒ String
Buffer name. If the buffer was created from a file, the name corresponds to relative path to the file.
source://parser//lib/parser/source/buffer.rb#26
      5227  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5227 def name; end  | 
  
#raw_source=(input) ⇒ String
Populate this buffer from a string without encoding autodetection.
source://parser//lib/parser/source/buffer.rb#185
      5237  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5237 def raw_source=(input); end  | 
  
#read ⇒ Buffer
Populate this buffer from correspondingly named file.
source://parser//lib/parser/source/buffer.rb#136
      5248  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5248 def read; end  | 
  
#slice(start, length = T.unsafe(nil)) ⇒ Object
source://parser//lib/parser/source/buffer.rb#199
      5253  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5253 def slice(start, length = T.unsafe(nil)); end  | 
  
#source ⇒ String
Source code contained in this buffer.
source://parser//lib/parser/source/buffer.rb#150
      5262  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5262 def source; end  | 
  
#source=(input) ⇒ String
Populate this buffer from a string with encoding autodetection.
input is mutated if not frozen.
source://parser//lib/parser/source/buffer.rb#167
      5274  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5274 def source=(input); end  | 
  
#source_line(lineno) ⇒ String
Extract line lineno from source, taking first_line into account.
source://parser//lib/parser/source/buffer.rb#278
      5284  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5284 def source_line(lineno); end  | 
  
#source_lines ⇒ Array<String>
Return an Array of source code lines.
source://parser//lib/parser/source/buffer.rb#257
      5292  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5292 def source_lines; end  | 
  
#source_range ⇒ Range
source://parser//lib/parser/source/buffer.rb#303
      5298  | 
    
      # File 'sorbet/rbi/parser@3.3.8.0.rbi', line 5298 def source_range; end  |