diff options
| author | Adolfo OchagavĂa <aochagavia92@gmail.com> | 2018-11-11 21:00:31 +0100 |
|---|---|---|
| committer | Adolfo OchagavĂa <aochagavia92@gmail.com> | 2018-11-11 21:00:31 +0100 |
| commit | c96bfe7e2d4465653fe6b0eff053f0dfb48313fa (patch) | |
| tree | 93c56d8301131a01de13b73010f615291eb1d6d4 /crates/ra_syntax/src/string_lexing/string.rs | |
| parent | 30cd4d5acb7dfd40cea264a926d1c89f0c3522c3 (diff) | |
| download | rust-c96bfe7e2d4465653fe6b0eff053f0dfb48313fa.tar.gz rust-c96bfe7e2d4465653fe6b0eff053f0dfb48313fa.zip | |
Split string lexing and run rustfmt
Diffstat (limited to 'crates/ra_syntax/src/string_lexing/string.rs')
| -rw-r--r-- | crates/ra_syntax/src/string_lexing/string.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/string_lexing/string.rs b/crates/ra_syntax/src/string_lexing/string.rs new file mode 100644 index 00000000000..1b23029c64e --- /dev/null +++ b/crates/ra_syntax/src/string_lexing/string.rs @@ -0,0 +1,46 @@ +use super::parser::Parser; +use super::StringComponent; + +pub fn parse_string_literal(src: &str) -> StringComponentIterator { + StringComponentIterator { + parser: Parser::new(src), + has_closing_quote: false, + } +} + +pub struct StringComponentIterator<'a> { + parser: Parser<'a>, + pub has_closing_quote: bool, +} + +impl<'a> Iterator for StringComponentIterator<'a> { + type Item = StringComponent; + fn next(&mut self) -> Option<StringComponent> { + if self.parser.pos == 0 { + assert!( + self.parser.advance() == '"', + "string literal should start with 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, + "string literal should leave no unparsed input: src = {}, pos = {}, length = {}", + self.parser.src, + self.parser.pos, + self.parser.src.len() + ); + + None + } +} |
