aboutsummaryrefslogtreecommitdiff
path: root/src/lexer/ptr.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-10 20:33:29 +0100
committerAleksey Kladov <[email protected]>2018-08-10 20:33:29 +0100
commit7c67612b8a894187fa3b64725531a5459f9211bf (patch)
tree9e2a536efa0c880d921fd8d4d74423afc9451fd4 /src/lexer/ptr.rs
parent26262aaf05983c5b7f41cc438e287523268fe1eb (diff)
organizize
Diffstat (limited to 'src/lexer/ptr.rs')
-rw-r--r--src/lexer/ptr.rs74
1 files changed, 0 insertions, 74 deletions
diff --git a/src/lexer/ptr.rs b/src/lexer/ptr.rs
deleted file mode 100644
index d1391fd5f..000000000
--- a/src/lexer/ptr.rs
+++ /dev/null
@@ -1,74 +0,0 @@
1use TextUnit;
2
3use std::str::Chars;
4
5pub(crate) struct Ptr<'s> {
6 text: &'s str,
7 len: TextUnit,
8}
9
10impl<'s> Ptr<'s> {
11 pub fn new(text: &'s str) -> Ptr<'s> {
12 Ptr {
13 text,
14 len: 0.into(),
15 }
16 }
17
18 pub fn into_len(self) -> TextUnit {
19 self.len
20 }
21
22 pub fn next(&self) -> Option<char> {
23 self.chars().next()
24 }
25
26 pub fn nnext(&self) -> Option<char> {
27 let mut chars = self.chars();
28 chars.next()?;
29 chars.next()
30 }
31
32 pub fn next_is(&self, c: char) -> bool {
33 self.next() == Some(c)
34 }
35
36 pub fn nnext_is(&self, c: char) -> bool {
37 self.nnext() == Some(c)
38 }
39
40 pub fn next_is_p<P: Fn(char) -> bool>(&self, p: P) -> bool {
41 self.next().map(p) == Some(true)
42 }
43
44 pub fn nnext_is_p<P: Fn(char) -> bool>(&self, p: P) -> bool {
45 self.nnext().map(p) == Some(true)
46 }
47
48 pub fn bump(&mut self) -> Option<char> {
49 let ch = self.chars().next()?;
50 self.len += TextUnit::of_char(ch);
51 Some(ch)
52 }
53
54 pub fn bump_while<F: Fn(char) -> bool>(&mut self, pred: F) {
55 loop {
56 match self.next() {
57 Some(c) if pred(c) => {
58 self.bump();
59 }
60 _ => return,
61 }
62 }
63 }
64
65 pub fn current_token_text(&self) -> &str {
66 let len: u32 = self.len.into();
67 &self.text[..len as usize]
68 }
69
70 fn chars(&self) -> Chars {
71 let len: u32 = self.len.into();
72 self.text[len as usize..].chars()
73 }
74}