Position
Remove file_id from Position and Span
@@ -2,7 +2,6 @@ use codespan::{ByteIndex, Span as ByteSpan};
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, Clone)]
pub struct Position {
- file_id: usize,
line: usize,
column: usize,
idx: usize,
@@ -11,7 +10,6 @@ pub struct Position {
impl Default for Position {
fn default() -> Self {
Position {
- file_id: 0,
line: 0,
column: 0,
idx: 0,
@@ -20,14 +18,6 @@ impl Default for Position {
}
impl Position {
- pub fn default_from(file_id: usize) -> Self {
- Position {
- file_id,
- line: 0,
- column: 0,
- idx: 0,
- }
- }
pub fn new_line(&mut self) {
self.line += 1;
self.column = 0;
@@ -50,7 +40,6 @@ impl Position {
pub fn into_span(self) -> Span {
Span {
- file_id: self.file_id,
start: self,
end: self,
}
@@ -58,7 +47,6 @@ impl Position {
pub fn backward_by(self, amount: usize) -> Position {
Position {
- file_id: self.file_id,
line: self.line,
column: self.column - amount,
idx: self.idx - amount,
@@ -66,7 +54,6 @@ impl Position {
}
pub fn forward_by(self, amount: usize) -> Position {
Position {
- file_id: self.file_id,
line: self.line,
column: self.column + amount,
idx: self.idx + amount,
@@ -100,11 +87,7 @@ impl<T: std::cmp::PartialEq> PartialEq<Spanned<T>> for Spanned<T> {
impl<T> Spanned<T> {
pub fn from_position(start: Position, end: Position, contents: T) -> Spanned<T> {
Spanned {
- span: Span {
- file_id: start.file_id,
- start,
- end,
- },
+ span: Span { start, end },
contents,
}
}
@@ -128,7 +111,6 @@ impl<T> std::borrow::Borrow<T> for Spanned<T> {
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, Clone)]
pub struct Span {
- file_id: usize,
pub start: Position,
pub end: Position,
}
@@ -136,7 +118,6 @@ pub struct Span {
impl Default for Span {
fn default() -> Self {
Span {
- file_id: 0,
start: Position::default(),
end: Position::default(),
}
@@ -145,18 +126,11 @@ impl Default for Span {
impl Span {
pub fn merge(self, other: Span) -> Span {
- assert_eq!(self.file_id, other.file_id);
- let file_id = self.file_id;
-
use std::cmp::{max, min};
let start = min(self.start, other.start);
let end = max(self.end, other.end);
- Span {
- file_id,
- start,
- end,
- }
+ Span { start, end }
}
pub fn to_byte_span(self) -> ByteSpan {
ByteSpan::from(self.start.to_byte_index()..self.end.to_byte_index())
