-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
57 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,2 @@ | ||
use std::str::CharIndices; | ||
|
||
pub mod inst; | ||
pub mod lexer; | ||
|
||
pub struct IndexedChars<'a> { | ||
slice: &'a str, | ||
iter: CharIndices<'a>, | ||
peeked: Option<Option<(usize, char)>>, | ||
offset: usize, | ||
} | ||
|
||
impl<'a> Iterator for IndexedChars<'a> { | ||
type Item = (usize, char); | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
match self.peeked.take().unwrap_or_else(|| self.iter.next()) { | ||
Some((offset, c)) => { | ||
self.offset = self.peek_boundary(); | ||
Some((offset, c)) | ||
} | ||
None => { | ||
self.offset = self.slice.len(); | ||
None | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'a> IndexedChars<'a> { | ||
pub fn new(slice: &'a str) -> Self { | ||
Self { | ||
slice, | ||
iter: slice.char_indices(), | ||
peeked: None, | ||
offset: 0, | ||
} | ||
} | ||
|
||
pub fn offset(&self) -> usize { | ||
self.offset | ||
} | ||
|
||
pub fn peek(&mut self) -> Option<&(usize, char)> { | ||
self.peeked.get_or_insert_with(|| self.iter.next()).as_ref() | ||
} | ||
|
||
fn peek_boundary(&mut self) -> usize { | ||
self.peek().map(|(idx, _)| *idx).unwrap_or(self.slice.len()) | ||
} | ||
} |
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,4 +1,4 @@ | ||
use crate::par_buf::ParBuf; | ||
use crate::util::ParBuf; | ||
|
||
#[derive(Debug, Default)] | ||
pub enum OutputTab { | ||
|
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,48 @@ | ||
use std::str::CharIndices; | ||
|
||
pub struct IndexedChars<'a> { | ||
slice: &'a str, | ||
iter: CharIndices<'a>, | ||
peeked: Option<Option<(usize, char)>>, | ||
offset: usize, | ||
} | ||
|
||
impl<'a> Iterator for IndexedChars<'a> { | ||
type Item = (usize, char); | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
match self.peeked.take().unwrap_or_else(|| self.iter.next()) { | ||
Some((offset, c)) => { | ||
self.offset = self.peek_boundary(); | ||
Some((offset, c)) | ||
} | ||
None => { | ||
self.offset = self.slice.len(); | ||
None | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'a> IndexedChars<'a> { | ||
pub fn new(slice: &'a str) -> Self { | ||
Self { | ||
slice, | ||
iter: slice.char_indices(), | ||
peeked: None, | ||
offset: 0, | ||
} | ||
} | ||
|
||
pub fn offset(&self) -> usize { | ||
self.offset | ||
} | ||
|
||
pub fn peek(&mut self) -> Option<&(usize, char)> { | ||
self.peeked.get_or_insert_with(|| self.iter.next()).as_ref() | ||
} | ||
|
||
pub fn peek_boundary(&mut self) -> usize { | ||
self.peek().map(|(idx, _)| *idx).unwrap_or(self.slice.len()) | ||
} | ||
} |
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,5 @@ | ||
mod indexed_chars; | ||
mod par_buf; | ||
|
||
pub use indexed_chars::*; | ||
pub use par_buf::*; |
File renamed without changes.