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
string
as Ruby would, i.e. -
.reencode_string(input) ⇒ String
Recognize encoding of
input
and 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
lineno
as a newRange
, takingfirst_line
into 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
lineno
from source, takingfirst_line
into account. -
#source_lines ⇒ Array<String>
Return an
Array
of 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
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
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
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
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
5167 |
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5167 def decompose_position(position); end |
#first_line ⇒ Integer
First line of the buffer, 1 by default.
source://parser//lib/parser/source/buffer.rb#26
5175 |
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5175 def first_line; end |
#freeze ⇒ Object
source://parser//lib/parser/source/buffer.rb#317
5180 |
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5180 def freeze; end |
#last_line ⇒ Integer
Number of last line in the buffer
source://parser//lib/parser/source/buffer.rb#312
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
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
5212 |
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5212 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
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
5231 |
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5231 def raw_source=(input); end |
#read ⇒ Buffer
Populate this buffer from correspondingly named file.
source://parser//lib/parser/source/buffer.rb#136
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 |
#source ⇒ String
Source code contained in this buffer.
source://parser//lib/parser/source/buffer.rb#150
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
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
5278 |
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5278 def source_line(lineno); end |
#source_lines ⇒ Array<String>
Return an Array
of source code lines.
source://parser//lib/parser/source/buffer.rb#257
5286 |
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5286 def source_lines; end |
#source_range ⇒ Range
source://parser//lib/parser/source/buffer.rb#303
5292 |
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 5292 def source_range; end |