Class: Parser::Source::Buffer

Inherits:
Object
  • Object
show all
Defined in:
sorbet/rbi/parser@3.3.7.4.rbi

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

Instance Method Summary collapse

Constructor Details

#initialize(name, first_line = T.unsafe(nil), source: T.unsafe(nil)) ⇒ Buffer

source://parser//lib/parser/source/buffer.rb#110



5149
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5149

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

Parameters:

Returns:

  • (String, nil)

    encoding name, if recognized

Raises:



5321
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5321

def recognize_encoding(string); end

.reencode_string(input) ⇒ String

Recognize encoding of input and process it so it could be lexed.

  • If input does not contain BOM or magic encoding comment, it is kept in the original encoding.
  • If the detected encoding is binary, input is kept in binary.
  • Otherwise, input is 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

Parameters:

Returns:

Raises:

  • (EncodingError)


5339
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5339

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

Parameters:

  • position (Integer)

Returns:

  • (Integer)

    column



5158
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5158

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

Parameters:

  • position (Integer)

Returns:

  • ([Integer, Integer])

    [line, column]



5167
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5167

def decompose_position(position); end

#first_lineInteger

First line of the buffer, 1 by default.

source://parser//lib/parser/source/buffer.rb#26

Returns:

  • (Integer)

    first line



5175
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5175

def first_line; end

#freezeObject

source://parser//lib/parser/source/buffer.rb#317



5180
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5180

def freeze; end

#last_lineInteger

Number of last line in the buffer

source://parser//lib/parser/source/buffer.rb#312

Returns:

  • (Integer)


5193
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5193

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

Parameters:

  • position (Integer)

Returns:

  • (Integer)

    line



5202
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5202

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

Parameters:

  • lineno (Integer)

Returns:

Raises:

  • (IndexError)

    if lineno is out of bounds



5212
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5212

def line_range(lineno); end

#nameString

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

Returns:



5221
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5221

def name; end

#raw_source=(input) ⇒ String

Populate this buffer from a string without encoding autodetection.

source://parser//lib/parser/source/buffer.rb#185

Parameters:

Returns:

Raises:

  • (ArgumentError)

    if already populated



5231
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5231

def raw_source=(input); end

#readBuffer

Populate this buffer from correspondingly named file.

source://parser//lib/parser/source/buffer.rb#136

Examples:

Parser::Source::Buffer.new('foo/bar.rb').read

Returns:

Raises:

  • (ArgumentError)

    if already populated



5242
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5242

def read; end

#slice(start, length = T.unsafe(nil)) ⇒ Object

source://parser//lib/parser/source/buffer.rb#199



5247
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5247

def slice(start, length = T.unsafe(nil)); end

#sourceString

Source code contained in this buffer.

source://parser//lib/parser/source/buffer.rb#150

Returns:

Raises:

  • (RuntimeError)

    if buffer is not populated yet



5256
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5256

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

Parameters:

Returns:

Raises:

  • (ArgumentError)

    if already populated

  • (EncodingError)

    if input includes invalid byte sequence for the encoding



5268
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5268

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

Parameters:

  • lineno (Integer)

Returns:

Raises:

  • (IndexError)

    if lineno is out of bounds



5278
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5278

def source_line(lineno); end

#source_linesArray<String>

Return an Array of source code lines.

source://parser//lib/parser/source/buffer.rb#257

Returns:



5286
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5286

def source_lines; end

#source_rangeRange

source://parser//lib/parser/source/buffer.rb#303

Returns:

  • (Range)

    A range covering the whole source



5292
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5292

def source_range; end