aboutsummaryrefslogtreecommitdiff
path: root/src/lexer
diff options
context:
space:
mode:
Diffstat (limited to 'src/lexer')
-rw-r--r--src/lexer/mod.rs45
-rw-r--r--src/lexer/ptr.rs4
2 files changed, 48 insertions, 1 deletions
diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs
index 24c14add0..3f277bd2b 100644
--- a/src/lexer/mod.rs
+++ b/src/lexer/mod.rs
@@ -34,7 +34,9 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
34 } 34 }
35 35
36 if is_dec_digit(c) { 36 if is_dec_digit(c) {
37 return scan_number(c, ptr); 37 let kind = scan_number(c, ptr);
38 scan_literal_suffix(ptr);
39 return kind;
38 } 40 }
39 41
40 // One-byte tokens. 42 // One-byte tokens.
@@ -98,6 +100,8 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
98 } 100 }
99 _ => NOT, 101 _ => NOT,
100 }, 102 },
103
104 // '\'' => scan_char_or_lifetime(ptr),
101 _ => (), 105 _ => (),
102 } 106 }
103 ERROR 107 ERROR
@@ -116,6 +120,45 @@ fn scan_ident(c: char, ptr: &mut Ptr) -> SyntaxKind {
116 IDENT 120 IDENT
117} 121}
118 122
123fn scan_char_or_lifetime(ptr: &mut Ptr) -> SyntaxKind {
124 // Either a character constant 'a' OR a lifetime name 'abc
125 let c = match ptr.bump() {
126 Some(c) => c,
127 None => return CHAR, // TODO: error reporting is upper in the stack
128 };
129
130 // If the character is an ident start not followed by another single
131 // quote, then this is a lifetime name:
132 if is_ident_start(c) && !ptr.next_is('\'') {
133 while ptr.next_is_p(is_ident_continue) {
134 ptr.bump();
135 }
136
137 // lifetimes shouldn't end with a single quote
138 // if we find one, then this is an invalid character literal
139 if ptr.next_is('\'') {
140 ptr.bump();
141 return CHAR;
142 }
143 return LIFETIME;
144 }
145 scan_char_or_byte(ptr);
146 if !ptr.next_is('\'') {
147 return CHAR; // TODO: error reporting
148 }
149 ptr.bump();
150 scan_literal_suffix(ptr);
151 CHAR
152}
153
154fn scan_literal_suffix(ptr: &mut Ptr) {
155
156}
157
158fn scan_char_or_byte(ptr: &mut Ptr) {
159 ptr.bump();
160}
161
119fn string_literal_start(c: char, c1: Option<char>, c2: Option<char>) -> bool { 162fn string_literal_start(c: char, c1: Option<char>, c2: Option<char>) -> bool {
120 match (c, c1, c2) { 163 match (c, c1, c2) {
121 ('r', Some('"'), _) | 164 ('r', Some('"'), _) |
diff --git a/src/lexer/ptr.rs b/src/lexer/ptr.rs
index b380117e6..2f759119a 100644
--- a/src/lexer/ptr.rs
+++ b/src/lexer/ptr.rs
@@ -34,6 +34,10 @@ impl<'s> Ptr<'s> {
34 self.nnext() == Some(c) 34 self.nnext() == Some(c)
35 } 35 }
36 36
37 pub fn next_is_p<P: Fn(char) -> bool>(&self, p: P) -> bool {
38 self.next().map(p) == Some(true)
39 }
40
37 pub fn nnext_is_p<P: Fn(char) -> bool>(&self, p: P) -> bool { 41 pub fn nnext_is_p<P: Fn(char) -> bool>(&self, p: P) -> bool {
38 self.nnext().map(p) == Some(true) 42 self.nnext().map(p) == Some(true)
39 } 43 }