diff options
author | Aleksey Kladov <[email protected]> | 2019-02-20 12:47:32 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-20 12:47:32 +0000 |
commit | 5222b8aba3b1c2c68706aacf6869423a8e4fe6d5 (patch) | |
tree | c8a6e999b8ac5f1f29bde86a2e0b3a53466bb369 /crates/ra_syntax/src/lexer/strings.rs | |
parent | 9d0cda4bc84350961f3884e75a1c20e62c449ede (diff) |
move all parsing related bits to a separate module
Diffstat (limited to 'crates/ra_syntax/src/lexer/strings.rs')
-rw-r--r-- | crates/ra_syntax/src/lexer/strings.rs | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/crates/ra_syntax/src/lexer/strings.rs b/crates/ra_syntax/src/lexer/strings.rs deleted file mode 100644 index 5c1cf3e9c..000000000 --- a/crates/ra_syntax/src/lexer/strings.rs +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | use crate::SyntaxKind::{self, *}; | ||
2 | |||
3 | use crate::lexer::ptr::Ptr; | ||
4 | |||
5 | pub(crate) fn is_string_literal_start(c: char, c1: Option<char>, c2: Option<char>) -> bool { | ||
6 | match (c, c1, c2) { | ||
7 | ('r', Some('"'), _) | ||
8 | | ('r', Some('#'), Some('"')) | ||
9 | | ('r', Some('#'), Some('#')) | ||
10 | | ('b', Some('"'), _) | ||
11 | | ('b', Some('\''), _) | ||
12 | | ('b', Some('r'), Some('"')) | ||
13 | | ('b', Some('r'), Some('#')) => true, | ||
14 | _ => false, | ||
15 | } | ||
16 | } | ||
17 | |||
18 | pub(crate) fn scan_char(ptr: &mut Ptr) { | ||
19 | while let Some(c) = ptr.current() { | ||
20 | match c { | ||
21 | '\\' => { | ||
22 | ptr.bump(); | ||
23 | if ptr.at('\\') || ptr.at('\'') { | ||
24 | ptr.bump(); | ||
25 | } | ||
26 | } | ||
27 | '\'' => { | ||
28 | ptr.bump(); | ||
29 | return; | ||
30 | } | ||
31 | '\n' => return, | ||
32 | _ => { | ||
33 | ptr.bump(); | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | |||
39 | pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind { | ||
40 | // unwrapping and not-exhaustive match are ok | ||
41 | // because of string_literal_start | ||
42 | let c = ptr.bump().unwrap(); | ||
43 | match c { | ||
44 | '\'' => { | ||
45 | scan_byte(ptr); | ||
46 | BYTE | ||
47 | } | ||
48 | '"' => { | ||
49 | scan_byte_string(ptr); | ||
50 | BYTE_STRING | ||
51 | } | ||
52 | 'r' => { | ||
53 | scan_raw_string(ptr); | ||
54 | RAW_BYTE_STRING | ||
55 | } | ||
56 | _ => unreachable!(), | ||
57 | } | ||
58 | } | ||
59 | |||
60 | pub(crate) fn scan_string(ptr: &mut Ptr) { | ||
61 | while let Some(c) = ptr.current() { | ||
62 | match c { | ||
63 | '\\' => { | ||
64 | ptr.bump(); | ||
65 | if ptr.at('\\') || ptr.at('"') { | ||
66 | ptr.bump(); | ||
67 | } | ||
68 | } | ||
69 | '"' => { | ||
70 | ptr.bump(); | ||
71 | return; | ||
72 | } | ||
73 | _ => { | ||
74 | ptr.bump(); | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | |||
80 | pub(crate) fn scan_raw_string(ptr: &mut Ptr) { | ||
81 | let mut hashes = 0; | ||
82 | while ptr.at('#') { | ||
83 | hashes += 1; | ||
84 | ptr.bump(); | ||
85 | } | ||
86 | if !ptr.at('"') { | ||
87 | return; | ||
88 | } | ||
89 | ptr.bump(); | ||
90 | |||
91 | while let Some(c) = ptr.bump() { | ||
92 | if c == '"' { | ||
93 | let mut hashes_left = hashes; | ||
94 | while ptr.at('#') && hashes_left > 0 { | ||
95 | hashes_left -= 1; | ||
96 | ptr.bump(); | ||
97 | } | ||
98 | if hashes_left == 0 { | ||
99 | return; | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | fn scan_byte(ptr: &mut Ptr) { | ||
106 | scan_char(ptr) | ||
107 | } | ||
108 | |||
109 | fn scan_byte_string(ptr: &mut Ptr) { | ||
110 | scan_string(ptr) | ||
111 | } | ||