Skip to content

Instantly share code, notes, and snippets.

@jimsynz

jimsynz/pair.rs

Created Jan 6, 2018
Embed
What would you like to do?
/// Returns the line and column numbers for the beginning and the end of
/// this pair.
///
/// # Example
///
/// ```
/// # use std::rc::Rc;
/// # use pest;
/// # use pest::inputs::StringInput;
/// # #[allow(non_camel_case_types)]
/// # #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
/// enum Rule {
/// ab
/// }
///
/// let input = Rc::new(StringInput::new("ab".to_owned()));
/// let pair = pest::state(input, |state, pos| {
/// // generating a Token pair with Rule::ab
/// # state.rule(Rule::ab, pos, |_, p| p.match_string("ab"))
/// }).unwrap().next().unwrap();
///
/// assert_eq!(unsafe { pair.input_range() }, ((1,1), (1,2)));
/// ```
#[inline]
pub unsafe fn input_range(&self) -> ((usize, usize), (usize, usize)) {
let start_token_pos = self.pos(self.start);
let end_token_pos = self.pos(self.pair());
println!("queue: {:?}", self.queue);
(self.input.line_col(start_token_pos), self.input.line_col(end_token_pos))
}
failures:
---- src/iterators/pair.rs - iterators::pair::Pair<R, I>::input_range (line 208) stdout ----
thread 'rustc' panicked at 'test executable failed:
queue: [Start { pair: 1, pos: 0 }, End { rule: ab, pos: 2 }]
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `((1, 1), (1, 3))`,
right: `((1, 1), (1, 2))`', src/iterators/pair.rs:18:0
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.