Skip to content

Instantly share code, notes, and snippets.

@jimsynz
Created January 6, 2018 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimsynz/28926294c507a1fc1b90b2a55eb7dc8b to your computer and use it in GitHub Desktop.
Save jimsynz/28926294c507a1fc1b90b2a55eb7dc8b to your computer and use it in GitHub Desktop.
/// 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