Path: | lib/parslet/slice.rb |
Last Update: | Thu Apr 26 16:22:26 -0400 2012 |
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.