From 73ded3c63ca2522b7bb6ca8eb7834c5adc1a3511 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 27 Dec 2018 14:42:46 +0300 Subject: dedupe literal parsers --- crates/ra_syntax/src/string_lexing/byte_string.rs | 51 ----------------------- 1 file changed, 51 deletions(-) delete mode 100644 crates/ra_syntax/src/string_lexing/byte_string.rs (limited to 'crates/ra_syntax/src/string_lexing/byte_string.rs') 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 @@ -use super::parser::Parser; -use super::StringComponent; - -pub fn parse_byte_string_literal(src: &str) -> ByteStringComponentIterator { - ByteStringComponentIterator { - parser: Parser::new(src), - has_closing_quote: false, - } -} - -pub struct ByteStringComponentIterator<'a> { - parser: Parser<'a>, - pub has_closing_quote: bool, -} - -impl<'a> Iterator for ByteStringComponentIterator<'a> { - type Item = StringComponent; - fn next(&mut self) -> Option { - if self.parser.pos == 0 { - assert!( - self.parser.advance() == 'b', - "byte string literal should start with a `b`" - ); - - assert!( - self.parser.advance() == '"', - "byte string literal should start with a `b`, followed by double quotes" - ); - } - - if let Some(component) = self.parser.parse_string_component() { - return Some(component); - } - - // We get here when there are no char components left to parse - if self.parser.peek() == Some('"') { - self.parser.advance(); - self.has_closing_quote = true; - } - - assert!( - self.parser.peek() == None, - "byte string literal should leave no unparsed input: src = {:?}, pos = {}, length = {}", - self.parser.src, - self.parser.pos, - self.parser.src.len() - ); - - None - } -} -- cgit v1.2.3