summaryrefslogtreecommitdiff
path: root/src/parse/scanner.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse/scanner.rs')
-rw-r--r--src/parse/scanner.rs55
1 files changed, 22 insertions, 33 deletions
diff --git a/src/parse/scanner.rs b/src/parse/scanner.rs
index 1bffc204..9447222d 100644
--- a/src/parse/scanner.rs
+++ b/src/parse/scanner.rs
@@ -102,9 +102,28 @@ impl<'s> Scanner<'s> {
pub fn check(&self, f: impl FnMut(char) -> bool) -> bool {
self.peek().map(f).unwrap_or(false)
}
+
+ /// Go back to the where the index says.
+ fn reset(&mut self) {
+ self.iter = self.src[self.index ..].chars();
+ }
}
impl<'s> Scanner<'s> {
+ /// The current index in the string.
+ pub fn index(&self) -> usize {
+ self.index
+ }
+
+ /// The previous index in the string.
+ pub fn prev_index(&self) -> usize {
+ self.src[.. self.index]
+ .chars()
+ .next_back()
+ .map(|c| self.index - c.len_utf8())
+ .unwrap_or(0)
+ }
+
/// Slice a part out of the source string.
pub fn get<I>(&self, index: I) -> &'s str
where
@@ -118,39 +137,20 @@ impl<'s> Scanner<'s> {
self.src
}
- /// The full string up to the current index.
+ /// The full source string up to the current index.
pub fn eaten(&self) -> &'s str {
&self.src[.. self.index]
}
- /// The string from `start` to the current index.
+ /// The source string from `start` to the current index.
pub fn eaten_from(&self, start: usize) -> &'s str {
&self.src[start .. self.index]
}
- /// The remaining string after the current index.
+ /// The remaining source string after the current index.
pub fn rest(&self) -> &'s str {
&self.src[self.index ..]
}
-
- /// The current index in the string.
- pub fn index(&self) -> usize {
- self.index
- }
-
- /// The previous index in the string.
- pub fn prev_index(&self) -> usize {
- self.src[.. self.index]
- .chars()
- .next_back()
- .map(|c| self.index - c.len_utf8())
- .unwrap_or(0)
- }
-
- /// Go back to the where the index says.
- fn reset(&mut self) {
- self.iter = self.src[self.index ..].chars();
- }
}
impl Debug for Scanner<'_> {
@@ -158,14 +158,3 @@ impl Debug for Scanner<'_> {
write!(f, "Scanner({}|{})", self.eaten(), self.rest())
}
}
-
-/// Whether this character denotes a newline.
-pub fn is_newline_char(character: char) -> bool {
- match character {
- // Line Feed, Vertical Tab, Form Feed, Carriage Return.
- '\n' | '\x0B' | '\x0C' | '\r' |
- // Next Line, Line Separator, Paragraph Separator.
- '\u{0085}' | '\u{2028}' | '\u{2029}' => true,
- _ => false,
- }
-}