diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-27 12:12:14 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-27 12:12:14 +0000 |
commit | 55ab0c602e391537f5e1a84a617fdd817e6a4200 (patch) | |
tree | 3adb0077bd7d7a34376d87cbb0ae7ea5b942d532 /crates/ra_syntax/src/string_lexing/byte_string.rs | |
parent | dbf03b674e7e1a49d9b32ec5ed656df2aedd3ed3 (diff) | |
parent | 49b0fe20ab6aa752df3764908b7c21f4b1827e52 (diff) |
Merge #339
339: Fix assertion error for literals with suffixes r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/string_lexing/byte_string.rs')
-rw-r--r-- | crates/ra_syntax/src/string_lexing/byte_string.rs | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/crates/ra_syntax/src/string_lexing/byte_string.rs b/crates/ra_syntax/src/string_lexing/byte_string.rs deleted file mode 100644 index a6056159b..000000000 --- a/crates/ra_syntax/src/string_lexing/byte_string.rs +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | use super::parser::Parser; | ||
2 | use super::StringComponent; | ||
3 | |||
4 | pub fn parse_byte_string_literal(src: &str) -> ByteStringComponentIterator { | ||
5 | ByteStringComponentIterator { | ||
6 | parser: Parser::new(src), | ||
7 | has_closing_quote: false, | ||
8 | } | ||
9 | } | ||
10 | |||
11 | pub struct ByteStringComponentIterator<'a> { | ||
12 | parser: Parser<'a>, | ||
13 | pub has_closing_quote: bool, | ||
14 | } | ||
15 | |||
16 | impl<'a> Iterator for ByteStringComponentIterator<'a> { | ||
17 | type Item = StringComponent; | ||
18 | fn next(&mut self) -> Option<StringComponent> { | ||
19 | if self.parser.pos == 0 { | ||
20 | assert!( | ||
21 | self.parser.advance() == 'b', | ||
22 | "byte string literal should start with a `b`" | ||
23 | ); | ||
24 | |||
25 | assert!( | ||
26 | self.parser.advance() == '"', | ||
27 | "byte string literal should start with a `b`, followed by double quotes" | ||
28 | ); | ||
29 | } | ||
30 | |||
31 | if let Some(component) = self.parser.parse_string_component() { | ||
32 | return Some(component); | ||
33 | } | ||
34 | |||
35 | // We get here when there are no char components left to parse | ||
36 | if self.parser.peek() == Some('"') { | ||
37 | self.parser.advance(); | ||
38 | self.has_closing_quote = true; | ||
39 | } | ||
40 | |||
41 | assert!( | ||
42 | self.parser.peek() == None, | ||
43 | "byte string literal should leave no unparsed input: src = {:?}, pos = {}, length = {}", | ||
44 | self.parser.src, | ||
45 | self.parser.pos, | ||
46 | self.parser.src.len() | ||
47 | ); | ||
48 | |||
49 | None | ||
50 | } | ||
51 | } | ||