Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Commit

Permalink
Implement InputTake for Span
Browse files Browse the repository at this point in the history
  • Loading branch information
subhojit777 committed Sep 20, 2018
1 parent 077aa7a commit 8e84f42
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions source/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use nom::{
FindSubstring,
InputIter,
InputLength,
InputTake,
Offset,
Slice
};
Expand Down Expand Up @@ -824,6 +825,36 @@ pub struct Span<'a> {
slice: Input<'a>
}

impl<'a> InputTake for Span<'a> {
fn take(&self, count: usize) -> Self {
Span {
offset: self.offset,
line: self.line,
column: self.column,
slice: self.slice.take(count),
}
}

fn take_split(&self, count: usize) -> (Self, Self) {
let (left, right) = self.slice.take_split(count);

(
Span {
offset: self.offset,
line: self.line,
column: self.column,
slice: left,
},
Span {
offset: self.offset,
line: self.line,
column: self.column,
slice: right,
},
)
}
}

impl<'a> Span<'a> {
/// Create a span for a particular input with default `offset`,
/// `line`, and `column` values.
Expand Down Expand Up @@ -1622,7 +1653,7 @@ mod tests {
fn case_span_slice_with_range() {
let range = 2..5;
let input = b"foobar";
let output = Span {
let output = Span {
offset: 2,
line : 1,
column: 3,
Expand All @@ -1636,7 +1667,7 @@ mod tests {
fn case_span_slice_with_range_to() {
let range = 2..;
let input = b"foobar";
let output = Span {
let output = Span {
offset: 2,
line : 1,
column: 3,
Expand All @@ -1650,7 +1681,7 @@ mod tests {
fn case_span_slice_with_range_from() {
let range = ..3;
let input = b"foobar";
let output = Span {
let output = Span {
offset: 0,
line : 1,
column: 1,
Expand All @@ -1664,7 +1695,7 @@ mod tests {
fn case_span_slice_with_range_full() {
let range = ..;
let input = b"foobar";
let output = Span {
let output = Span {
offset: 0,
line : 1,
column: 1,
Expand Down

0 comments on commit 8e84f42

Please sign in to comment.