aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/lexer/strings.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/lexer/strings.rs')
-rw-r--r--crates/libsyntax2/src/lexer/strings.rs123
1 files changed, 0 insertions, 123 deletions
diff --git a/crates/libsyntax2/src/lexer/strings.rs b/crates/libsyntax2/src/lexer/strings.rs
deleted file mode 100644
index 5ff483d14..000000000
--- a/crates/libsyntax2/src/lexer/strings.rs
+++ /dev/null
@@ -1,123 +0,0 @@
1use SyntaxKind::{self, *};
2
3use lexer::ptr::Ptr;
4
5pub(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('#'), _)
9 | ('b', Some('"'), _)
10 | ('b', Some('\''), _)
11 | ('b', Some('r'), Some('"'))
12 | ('b', Some('r'), Some('#')) => true,
13 _ => false,
14 }
15}
16
17pub(crate) fn scan_char(ptr: &mut Ptr) {
18 while let Some(c) = ptr.current() {
19 match c {
20 '\\' => {
21 ptr.bump();
22 if ptr.at('\\') || ptr.at('\'') {
23 ptr.bump();
24 }
25 }
26 '\'' => {
27 ptr.bump();
28 return;
29 }
30 '\n' => return,
31 _ => {
32 ptr.bump();
33 }
34 }
35 }
36}
37
38pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind {
39 // unwrapping and not-exhaustive match are ok
40 // because of string_literal_start
41 let c = ptr.bump().unwrap();
42 match c {
43 '\'' => {
44 scan_byte(ptr);
45 BYTE
46 }
47 '"' => {
48 scan_byte_string(ptr);
49 BYTE_STRING
50 }
51 'r' => {
52 scan_raw_byte_string(ptr);
53 RAW_BYTE_STRING
54 }
55 _ => unreachable!(),
56 }
57}
58
59pub(crate) fn scan_string(ptr: &mut Ptr) {
60 while let Some(c) = ptr.current() {
61 match c {
62 '\\' => {
63 ptr.bump();
64 if ptr.at('\\') || ptr.at('"') {
65 ptr.bump();
66 }
67 }
68 '"' => {
69 ptr.bump();
70 return;
71 }
72 _ => {
73 ptr.bump();
74 },
75 }
76 }
77}
78
79pub(crate) fn scan_raw_string(ptr: &mut Ptr) {
80 let mut hashes = 0;
81 while ptr.at('#') {
82 hashes += 1;
83 ptr.bump();
84 }
85 if !ptr.at('"') {
86 return;
87 }
88 ptr.bump();
89
90 while let Some(c) = ptr.bump() {
91 if c == '"' {
92 let mut hashes_left = hashes;
93 while ptr.at('#') && hashes_left > 0{
94 hashes_left -= 1;
95 ptr.bump();
96 }
97 if hashes_left == 0 {
98 return;
99 }
100 }
101 }
102}
103
104fn scan_byte(ptr: &mut Ptr) {
105 scan_char(ptr)
106}
107
108fn scan_byte_string(ptr: &mut Ptr) {
109 scan_string(ptr)
110}
111
112fn scan_raw_byte_string(ptr: &mut Ptr) {
113 if !ptr.at('"') {
114 return;
115 }
116 ptr.bump();
117
118 while let Some(c) = ptr.bump() {
119 if c == '"' {
120 return;
121 }
122 }
123}