Class Parslet::Slice
In: lib/parslet/slice.rb
Parent: Object

A slice is a small part from the parse input. A slice mainly behaves like any other string, except that it remembers where it came from (offset in original input).

Extracting line and column

Using the line_and_column method, you can extract the line and column in the original input where this slice starts.

Example:

  slice.line_and_column # => [1, 13]
  slice.offset          # => 12

Likeness to strings

Parslet::Slice behaves in many ways like a Ruby String. This likeness however is not complete - many of the myriad of operations String supports are not yet in Slice. You can always extract the internal string instance by calling to_s.

These omissions are somewhat intentional. Rather than maintaining a full delegation, we opt for a partial emulation that gets the job done.

Methods

+   ==   inspect   line_and_column   match   new   size   to_f   to_i   to_int   to_s   to_slice   to_str   to_sym  

Attributes

line_cache  [R] 
offset  [R] 
str  [R] 

Public Class methods

Construct a slice using a string, an offset and an optional line cache. The line cache should be able to answer to the line_and_column message.

Public Instance methods

Concatenate two slices; it is assumed that the second slice begins where the first one ends. The offset of the resulting slice is the same as the one of this slice.

Compares slices to other slices or strings.

Prints the slice as "string"@offset.

Returns a <line, column> tuple referring to the original input.

Match regular expressions.

Returns the slices size in characters.

to_s()

Alias for to_str

Conversion operators ——————————————————

[Validate]