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).
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
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.
line_cache | [R] | |
offset | [R] | |
str | [R] |
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.