slice.rb

Path: lib/parslet/slice.rb
Last Update: Fri Jul 15 14:35:39 -0400 2016

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.

[Validate]