pub mod printf {
use super::strcursor::StrCursor as Cur;
+ use syntax_pos::InnerSpan;
/// Represents a single `printf`-style substitution.
#[derive(Clone, PartialEq, Debug)]
}
}
- pub fn position(&self) -> Option<(usize, usize)> {
+ pub fn position(&self) -> Option<InnerSpan> {
match *self {
Substitution::Format(ref fmt) => Some(fmt.position),
_ => None,
pub fn set_position(&mut self, start: usize, end: usize) {
match self {
Substitution::Format(ref mut fmt) => {
- fmt.position = (start, end);
+ fmt.position = InnerSpan::new(start, end);
}
_ => {}
}
/// Type of parameter being converted.
pub type_: &'a str,
/// Byte offset for the start and end of this formatting directive.
- pub position: (usize, usize),
+ pub position: InnerSpan,
}
impl Format<'_> {
let (mut sub, tail) = parse_next_substitution(self.s)?;
self.s = tail;
match sub {
- Substitution::Format(_) => if let Some((start, end)) = sub.position() {
- sub.set_position(start + self.pos, end + self.pos);
- self.pos += end;
+ Substitution::Format(_) => if let Some(inner_span) = sub.position() {
+ sub.set_position(inner_span.start + self.pos, inner_span.end + self.pos);
+ self.pos += inner_span.end;
}
Substitution::Escape => self.pos += 2,
}
precision: None,
length: None,
type_: at.slice_between(next).unwrap(),
- position: (start.at, next.at),
+ position: InnerSpan::new(start.at, next.at),
}),
next.slice_after()
));
drop(next);
end = at;
- let position = (start.at, end.at);
+ let position = InnerSpan::new(start.at, end.at);
let f = Format {
span: start.slice_between(end).unwrap(),
precision: $prec,
length: $len,
type_: $type_,
- position: $pos,
+ position: syntax_pos::InnerSpan::new($pos.0, $pos.1),
}),
"!"
))
pub mod shell {
use super::strcursor::StrCursor as Cur;
+ use syntax_pos::InnerSpan;
#[derive(Clone, PartialEq, Debug)]
pub enum Substitution<'a> {
}
}
- pub fn position(&self) -> Option<(usize, usize)> {
+ pub fn position(&self) -> Option<InnerSpan> {
match self {
Substitution::Ordinal(_, pos) |
Substitution::Name(_, pos) |
- Substitution::Escape(pos) => Some(*pos),
+ Substitution::Escape(pos) => Some(InnerSpan::new(pos.0, pos.1)),
}
}
match parse_next_substitution(self.s) {
Some((mut sub, tail)) => {
self.s = tail;
- if let Some((start, end)) = sub.position() {
+ if let Some(InnerSpan { start, end }) = sub.position() {
sub.set_position(start + self.pos, end + self.pos);
self.pos += end;
}