aboutsummaryrefslogtreecommitdiff
path: root/src/lexer/ptr.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2017-12-29 20:33:04 +0000
committerAleksey Kladov <[email protected]>2017-12-29 20:33:04 +0000
commit171baf4c4863f035384c6c63a5f0ce531b01cf9d (patch)
tree8dd3885e6d02f64e41275c07bf15491477272182 /src/lexer/ptr.rs
parent15af7ad36c507b17093ba86c393272819ff4b3cd (diff)
Simple identifier lexer
Diffstat (limited to 'src/lexer/ptr.rs')
-rw-r--r--src/lexer/ptr.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/lexer/ptr.rs b/src/lexer/ptr.rs
new file mode 100644
index 000000000..4638dac21
--- /dev/null
+++ b/src/lexer/ptr.rs
@@ -0,0 +1,38 @@
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 { text, len: TextUnit::new(0) }
13 }
14
15 pub fn into_len(self) -> TextUnit {
16 self.len
17 }
18
19 pub fn next(&self) -> Option<char> {
20 self.chars().next()
21 }
22
23 pub fn nnext(&self) -> Option<char> {
24 let mut chars = self.chars();
25 chars.next()?;
26 chars.next()
27 }
28
29 pub fn bump(&mut self) -> Option<char> {
30 let ch = self.chars().next()?;
31 self.len += TextUnit::len_of_char(ch);
32 Some(ch)
33 }
34
35 fn chars(&self) -> Chars {
36 self.text[self.len.0 as usize ..].chars()
37 }
38}