aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/string_lexing/string.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/string_lexing/string.rs')
-rw-r--r--crates/ra_syntax/src/string_lexing/string.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/string_lexing/string.rs b/crates/ra_syntax/src/string_lexing/string.rs
index 7476fea13..064f08544 100644
--- a/crates/ra_syntax/src/string_lexing/string.rs
+++ b/crates/ra_syntax/src/string_lexing/string.rs
@@ -1,12 +1,15 @@
1use crate::string_lexing::{ 1use crate::{
2 TextRange,
3 string_lexing::{
2 parser::Parser, 4 parser::Parser,
3 StringComponent, 5 StringComponent,
4}; 6}};
5 7
6pub fn parse_string_literal(src: &str) -> StringComponentIterator { 8pub fn parse_string_literal(src: &str) -> StringComponentIterator {
7 StringComponentIterator { 9 StringComponentIterator {
8 parser: Parser::new(src, b'"'), 10 parser: Parser::new(src, b'"'),
9 has_closing_quote: false, 11 has_closing_quote: false,
12 suffix: None,
10 prefix: None, 13 prefix: None,
11 quote: b'"', 14 quote: b'"',
12 } 15 }
@@ -16,6 +19,7 @@ pub fn parse_byte_string_literal(src: &str) -> StringComponentIterator {
16 StringComponentIterator { 19 StringComponentIterator {
17 parser: Parser::new(src, b'"'), 20 parser: Parser::new(src, b'"'),
18 has_closing_quote: false, 21 has_closing_quote: false,
22 suffix: None,
19 prefix: Some(b'b'), 23 prefix: Some(b'b'),
20 quote: b'"', 24 quote: b'"',
21 } 25 }
@@ -25,6 +29,7 @@ pub fn parse_char_literal(src: &str) -> StringComponentIterator {
25 StringComponentIterator { 29 StringComponentIterator {
26 parser: Parser::new(src, b'\''), 30 parser: Parser::new(src, b'\''),
27 has_closing_quote: false, 31 has_closing_quote: false,
32 suffix: None,
28 prefix: None, 33 prefix: None,
29 quote: b'\'', 34 quote: b'\'',
30 } 35 }
@@ -34,6 +39,7 @@ pub fn parse_byte_literal(src: &str) -> StringComponentIterator {
34 StringComponentIterator { 39 StringComponentIterator {
35 parser: Parser::new(src, b'\''), 40 parser: Parser::new(src, b'\''),
36 has_closing_quote: false, 41 has_closing_quote: false,
42 suffix: None,
37 prefix: Some(b'b'), 43 prefix: Some(b'b'),
38 quote: b'\'', 44 quote: b'\'',
39 } 45 }
@@ -42,6 +48,7 @@ pub fn parse_byte_literal(src: &str) -> StringComponentIterator {
42pub struct StringComponentIterator<'a> { 48pub struct StringComponentIterator<'a> {
43 parser: Parser<'a>, 49 parser: Parser<'a>,
44 pub has_closing_quote: bool, 50 pub has_closing_quote: bool,
51 pub suffix: Option<TextRange>,
45 prefix: Option<u8>, 52 prefix: Option<u8>,
46 quote: u8, 53 quote: u8,
47} 54}
@@ -72,6 +79,9 @@ impl<'a> Iterator for StringComponentIterator<'a> {
72 if self.parser.peek() == Some(self.quote as char) { 79 if self.parser.peek() == Some(self.quote as char) {
73 self.parser.advance(); 80 self.parser.advance();
74 self.has_closing_quote = true; 81 self.has_closing_quote = true;
82 if let Some(range) = self.parser.parse_suffix() {
83 self.suffix = Some(range);
84 }
75 } 85 }
76 86
77 assert!( 87 assert!(