Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
psl: allow to remove position information from ast
- Loading branch information
Showing
19 changed files
with
200 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,9 @@ | ||
/// The stable identifier for a PSL file. | ||
#[derive(Debug, PartialEq, Clone, Copy, Hash, Eq, PartialOrd, Ord)] | ||
pub struct FileId(pub u32); // we can't encapsulate because it would be a circular crate | ||
// dependency between diagnostics and parser-database | ||
|
||
impl FileId { | ||
pub const ZERO: FileId = FileId(0); | ||
pub const MAX: FileId = FileId(u32::MAX); | ||
} | ||
|
||
/// Represents a location in a datamodel's text representation. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct Span { | ||
pub start: usize, | ||
pub end: usize, | ||
pub file_id: FileId, | ||
} | ||
|
||
impl Span { | ||
/// Constructor. | ||
pub fn new(start: usize, end: usize, file_id: FileId) -> Span { | ||
Span { start, end, file_id } | ||
} | ||
|
||
/// Creates a new empty span. | ||
pub fn empty() -> Span { | ||
Span { | ||
start: 0, | ||
end: 0, | ||
file_id: FileId::ZERO, | ||
} | ||
} | ||
|
||
/// Is the given position inside the span? (boundaries included) | ||
pub fn contains(&self, position: usize) -> bool { | ||
position >= self.start && position <= self.end | ||
} | ||
|
||
/// Is the given span overlapping with the current span. | ||
pub fn overlaps(self, other: Span) -> bool { | ||
self.contains(other.start) || self.contains(other.end) | ||
} | ||
} | ||
|
||
impl From<(FileId, pest::Span<'_>)> for Span { | ||
fn from((file_id, s): (FileId, pest::Span<'_>)) -> Self { | ||
Span { | ||
start: s.start(), | ||
end: s.end(), | ||
file_id, | ||
} | ||
} | ||
} | ||
#[cfg(feature = "full-spans")] | ||
mod full; | ||
#[cfg(not(feature = "full-spans"))] | ||
mod noop; | ||
|
||
#[cfg(feature = "full-spans")] | ||
pub use full::{FileId, Span}; | ||
#[cfg(not(feature = "full-spans"))] | ||
pub use noop::{FileId, Span}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/// The stable identifier for a PSL file. | ||
#[derive(Debug, PartialEq, Clone, Copy, Hash, Eq, PartialOrd, Ord)] | ||
pub struct FileId(pub u32); // we can't encapsulate because it would be a circular crate | ||
// dependency between diagnostics and parser-database | ||
|
||
impl FileId { | ||
pub const ZERO: FileId = FileId(0); | ||
pub const MAX: FileId = FileId(u32::MAX); | ||
} | ||
|
||
/// Represents a location in a datamodel's text representation. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct Span { | ||
start: usize, | ||
end: usize, | ||
file_id: FileId, | ||
} | ||
|
||
impl Span { | ||
/// Constructor. | ||
pub fn new(start: usize, end: usize, file_id: FileId) -> Span { | ||
Span { start, end, file_id } | ||
} | ||
|
||
pub fn start(&self) -> usize { | ||
self.start | ||
} | ||
pub fn set_start(&mut self, start: usize) { | ||
self.start = start | ||
} | ||
|
||
pub fn end(&self) -> usize { | ||
self.end | ||
} | ||
pub fn set_end(&mut self, end: usize) { | ||
self.end = end | ||
} | ||
|
||
pub fn file_id(&self) -> FileId { | ||
self.file_id | ||
} | ||
|
||
/// Creates a new empty span. | ||
pub fn empty() -> Span { | ||
Span { | ||
start: 0, | ||
end: 0, | ||
file_id: FileId::ZERO, | ||
} | ||
} | ||
|
||
/// Is the given position inside the span? (boundaries included) | ||
pub fn contains(&self, position: usize) -> bool { | ||
position >= self.start && position <= self.end | ||
} | ||
|
||
/// Is the given span overlapping with the current span. | ||
pub fn overlaps(self, other: Span) -> bool { | ||
self.contains(other.start) || self.contains(other.end) | ||
} | ||
} | ||
|
||
impl From<(FileId, pest::Span<'_>)> for Span { | ||
fn from((file_id, s): (FileId, pest::Span<'_>)) -> Self { | ||
Span { | ||
start: s.start(), | ||
end: s.end(), | ||
file_id, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/// The stable identifier for a PSL file. | ||
#[derive(Debug, PartialEq, Clone, Copy, Hash, Eq, PartialOrd, Ord)] | ||
pub struct FileId(pub u32); // we can't encapsulate because it would be a circular crate | ||
// dependency between diagnostics and parser-database | ||
|
||
impl FileId { | ||
pub const ZERO: FileId = FileId(0); | ||
pub const MAX: FileId = FileId(u32::MAX); | ||
} | ||
|
||
/// Represents a location in a datamodel's text representation. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct Span {} | ||
|
||
impl Span { | ||
/// Constructor. | ||
pub fn new(_start: usize, _end: usize, _file_id: FileId) -> Span { | ||
Span {} | ||
} | ||
|
||
pub fn start(&self) -> usize { | ||
0 | ||
} | ||
|
||
pub fn set_start(&mut self, _start: usize) {} | ||
|
||
pub fn end(&self) -> usize { | ||
0 | ||
} | ||
pub fn set_end(&mut self, _end: usize) {} | ||
|
||
pub fn file_id(&self) -> FileId { | ||
FileId::ZERO | ||
} | ||
|
||
/// Creates a new empty span. | ||
pub fn empty() -> Span { | ||
Span {} | ||
} | ||
|
||
/// Is the given position inside the span? (boundaries included) | ||
pub fn contains(&self, _position: usize) -> bool { | ||
false | ||
} | ||
|
||
/// Is the given span overlapping with the current span. | ||
pub fn overlaps(self, _other: Span) -> bool { | ||
false | ||
} | ||
} | ||
|
||
impl From<(FileId, pest::Span<'_>)> for Span { | ||
fn from((_file_id, _s): (FileId, pest::Span<'_>)) -> Self { | ||
Span {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.