aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing/lexer/numbers.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-07-22 15:56:19 +0100
committerAleksey Kladov <[email protected]>2019-07-22 15:56:19 +0100
commit700669bbd0ab3ae0c5a56985ce13ca896d342a3a (patch)
tree20ee49ed4ee94e463cd81f3f8142d64cde0ca134 /crates/ra_syntax/src/parsing/lexer/numbers.rs
parent75761c0e47d8c20a490a3d61ea64d2413d3c3570 (diff)
kill old lexer
Diffstat (limited to 'crates/ra_syntax/src/parsing/lexer/numbers.rs')
-rw-r--r--crates/ra_syntax/src/parsing/lexer/numbers.rs66
1 files changed, 0 insertions, 66 deletions
diff --git a/crates/ra_syntax/src/parsing/lexer/numbers.rs b/crates/ra_syntax/src/parsing/lexer/numbers.rs
deleted file mode 100644
index e53ae231b..000000000
--- a/crates/ra_syntax/src/parsing/lexer/numbers.rs
+++ /dev/null
@@ -1,66 +0,0 @@
1use crate::parsing::lexer::{classes::*, ptr::Ptr};
2
3use crate::SyntaxKind::{self, *};
4
5pub(crate) fn scan_number(c: char, ptr: &mut Ptr) -> SyntaxKind {
6 if c == '0' {
7 match ptr.current().unwrap_or('\0') {
8 'b' | 'o' => {
9 ptr.bump();
10 scan_digits(ptr, false);
11 }
12 'x' => {
13 ptr.bump();
14 scan_digits(ptr, true);
15 }
16 '0'..='9' | '_' | '.' | 'e' | 'E' => {
17 scan_digits(ptr, true);
18 }
19 _ => return INT_NUMBER,
20 }
21 } else {
22 scan_digits(ptr, false);
23 }
24
25 // might be a float, but don't be greedy if this is actually an
26 // integer literal followed by field/method access or a range pattern
27 // (`0..2` and `12.foo()`)
28 if ptr.at('.') && !(ptr.at_str("..") || ptr.nth_is_p(1, is_ident_start)) {
29 // might have stuff after the ., and if it does, it needs to start
30 // with a number
31 ptr.bump();
32 scan_digits(ptr, false);
33 scan_float_exponent(ptr);
34 return FLOAT_NUMBER;
35 }
36 // it might be a float if it has an exponent
37 if ptr.at('e') || ptr.at('E') {
38 scan_float_exponent(ptr);
39 return FLOAT_NUMBER;
40 }
41 INT_NUMBER
42}
43
44fn scan_digits(ptr: &mut Ptr, allow_hex: bool) {
45 while let Some(c) = ptr.current() {
46 match c {
47 '_' | '0'..='9' => {
48 ptr.bump();
49 }
50 'a'..='f' | 'A'..='F' if allow_hex => {
51 ptr.bump();
52 }
53 _ => return,
54 }
55 }
56}
57
58fn scan_float_exponent(ptr: &mut Ptr) {
59 if ptr.at('e') || ptr.at('E') {
60 ptr.bump();
61 if ptr.at('-') || ptr.at('+') {
62 ptr.bump();
63 }
64 scan_digits(ptr, false);
65 }
66}